Files
crawler-plugin/admin-frontend-vue/tests/gating-import.test.ts
T
huangzd1997 eb6dd9bf44 feat(gating): 后管新增品牌Gating库管理页
菜单权限键 admin_brand_gating(admin_group_data 组),路由 asin-center/gating;
统计卡+五字段筛选+13 列表格+新增/删除/启停用/批量导入(粘文本 { text }
整段交后端,前端同款 parse_batch 规则只做行数预览);companyScoped=false
(biz_brand_gating 全平台共享表口径)。补 ops-cell 操作列宽登记与操作提示条。
2026-10-23 21:57:05 +08:00

59 lines
2.7 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 test from 'node:test'
import assert from 'node:assert/strict'
import { gatingImportOutcomeText, parseGatingImportText } from '../src/pages/gating/gating-import.ts'
test('gating_import_single_field_defaults', () => {
// 桌面版口径:只给品牌 → 国家=全部、类型=品牌gating、ASIN/备注空。
const result = parseGatingImportText('jellycat')
assert.equal(result.items.length, 1)
assert.deepEqual(result.items[0], { brand: 'jellycat', country: '全部', gatingType: '品牌gating', asin: '', remark: '' })
assert.equal(result.skippedLines, 0)
})
test('gating_import_full_five_fields', () => {
const result = parseGatingImportText('tory burch,英国,品牌gating,B0ABC123,人为录入')
assert.deepEqual(result.items[0], { brand: 'tory burch', country: '英国', gatingType: '品牌gating', asin: 'B0ABC123', remark: '人为录入' })
})
test('gating_import_mixed_separators_and_extra_fields_dropped', () => {
// 桌面版分隔符集合 [,\t;,;];第 5 列之后的段丢弃。
const result = parseGatingImportText('crocs,德国;类目gating\tB0X\t备注\t多余段')
assert.deepEqual(result.items[0], { brand: 'crocs', country: '德国', gatingType: '类目gating', asin: 'B0X', remark: '备注' })
})
test('gating_import_skip_blank_comment_and_separator_only_lines', () => {
const text = [
'',
' ',
'# 这是注释行',
';;,', // 纯分隔符行 → 空段全被丢,整行跳过
'jellycat',
].join('\n')
const result = parseGatingImportText(text)
assert.equal(result.items.length, 1)
assert.equal(result.items[0]?.brand, 'jellycat')
assert.equal(result.skippedLines, 2) // 注释行 + 纯分隔符行;纯空白行不计数
})
test('gating_import_bom_and_crlf_and_empty_parts', () => {
const result = parseGatingImportText('\uFEFFcrocs,德国,,B0X\r\n,头部空段被丢')
assert.equal(result.items.length, 2)
assert.equal(result.items[0]?.brand, 'crocs')
assert.equal(result.items[0]?.country, '德国')
// 桌面版口径:空段在切分后就被丢弃,后续字段整体左移(B0X 落到类型位)——照抄不修正。
assert.equal(result.items[0]?.gatingType, 'B0X')
assert.equal(result.items[0]?.asin, '')
assert.equal(result.items[1]?.brand, '头部空段被丢')
assert.equal(result.items[1]?.country, '全部')
})
test('gating_import_empty_input_never_throws', () => {
assert.deepEqual(parseGatingImportText(''), { items: [], skippedLines: 0 })
// @ts-expect-error 纯函数要扛住脏输入(运行时防呆)。
assert.deepEqual(parseGatingImportText(null), { items: [], skippedLines: 0 })
})
test('gating_import_outcome_text', () => {
assert.equal(gatingImportOutcomeText(3, 2), '批量导入完成:新增 3 条,跳过重复 2 条')
})