import { createBatchFileItems } from '@/components/upload/file-handlers' describe('批量视频 SPU 自动识别', () => { test('无法确认 SPU 时保持空值并展开对应文件', () => { const [item] = createBatchFileItems( [new File(['video'], '抖音素材-624-456.mp4', { type: 'video/mp4' })], '抖音-千川素材', '', '', '', '', '', ) expect(item).toMatchObject({ expanded: true, productModel: '', productModelSource: undefined, }) }) test('只把文件名中可确认的型号作为 SPU', () => { const items = createBatchFileItems( [ new File(['video'], 'GBPM-SN0204K12.mp4', { type: 'video/mp4' }), new File(['video'], 'DF-A3DZ0008.mp4', { type: 'video/mp4' }), ], '抖音-千川素材', '', '', '', '', '', ) expect(items.map(item => ({ productModel: item.productModel, productModelSource: item.productModelSource, }))).toEqual([ { productModel: 'GBPM-SN0204K12', productModelSource: 'filename' }, { productModel: 'DF-A3DZ0008', productModelSource: 'filename' }, ]) }) test('带说明文字的文件名不截取其中一段冒充 SPU', () => { const [item] = createBatchFileItems( [new File(['video'], '产品-GBPM-SN0204-展示.mp4', { type: 'video/mp4' })], '抖音-千川素材', '', '', '', '', '', ) expect(item.productModel).toBe('') expect(item.productModelSource).toBeUndefined() expect(item.expanded).toBe(true) }) })