gongxiangp2/lib/__tests__/sku-barcode-detector.test.ts

41 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { detectSkuOrBarcodeName } from '@/lib/sku-barcode-detector'
describe('detectSkuOrBarcodeName(SKU 图文件名判别)', () => {
it.each([
// 条码:SKU 编码 + N数字V数字 段(生产数据真实形态)
['DNZ038521N1280V01', 'barcode'],
['CY001306N35V01', 'barcode'],
['BJ017603N1241V01', 'barcode'],
['cy001301N35', 'barcode'], // 小写品类码也能识别
['GBSFY-DNZ038415N1261V01', 'barcode'], // 带店铺前缀
])('%s → %s', (input, expected) => {
expect(detectSkuOrBarcodeName(input)?.type).toBe(expected)
// value 保留原始大小写
expect(detectSkuOrBarcodeName(input)?.value).toBe(input)
})
it.each([
// SKU 编号:品类码 + 纯数字
['DNZ038521', 'skuCode'],
['AD033601', 'skuCode'],
['GBSFY-AD0360', 'skuCode'], // 带店铺前缀
['MKHDNZ0409260600987', 'skuCode'], // MKH=模块化前缀,无连字符直接拼品类码(测试人员真实用例)
['GBSFYAD0360', 'skuCode'], // 店铺前缀无连字符形态
])('%s → %s', (input, expected) => {
expect(detectSkuOrBarcodeName(input)?.type).toBe(expected)
})
it.each([
// 命名不规范:一律不自动填
['1'],
['10'],
['02-1'],
['MKH-DNZ038528N1280V01-1-GBGJ-DNZ038415N1261V01-5'], // 复合串
['GBPM-BJ019201N1280V01场景'], // 含中文
['随便起的名字'],
[''],
])('%s → 不填(null)', (input) => {
expect(detectSkuOrBarcodeName(input)).toBeNull()
})
})