revert(gating): 后管 Gating 页与入口回滚

删除品牌Gating库页面、API/导入/模型与测试,摘掉静态路由、操作指引条目与
ops-cell 列宽登记;菜单行由 V166 移除,后端模块保留但无授权入口。
This commit is contained in:
2026-10-24 09:20:36 +08:00
parent 68ec48b573
commit 052f2bd4a5
10 changed files with 0 additions and 1385 deletions
@@ -1,58 +0,0 @@
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 条')
})
@@ -1,99 +0,0 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
createGatingFilterState,
gatingStatusLabel,
parseGatingNameCountList,
parseGatingPage,
parseGatingStats,
toGatingItem,
toGatingListParams,
} from '../src/pages/gating/gating-model.ts'
test('gating_filter_normal_primary_path', () => {
// 完整筛选映射到契约查询参数(page/size/keyword/country/gatingType/status/source)。
const state = { ...createGatingFilterState(), keyword: 'jellycat', country: '英国', gatingType: '品牌gating', status: '1', source: 'MANUAL' }
const params = toGatingListParams(state, 3, 20)
assert.equal(params.page, 3)
assert.equal(params.size, 20)
assert.equal(params.keyword, 'jellycat')
assert.equal(params.country, '英国')
assert.equal(params.gatingType, '品牌gating')
assert.equal(params.status, '1')
assert.equal(params.source, 'MANUAL')
})
test('gating_filter_boundary_blank_dropped', () => {
// 空筛选只带分页;非法 status(非 '0'/'1')不下发。
const params = toGatingListParams({ ...createGatingFilterState(), status: 'all', keyword: ' ' }, 0, -5)
assert.deepEqual(params, { page: 1, size: 10 })
})
test('gating_item_parse_normal_and_snake_fallback', () => {
const camel = toGatingItem({
id: 7, brand: 'jellycat', asin: 'B0ABC123', country: '英国', gatingType: '品牌gating',
status: 1, source: 'AUTO', shopName: '店A', remark: 'r',
createdAt: '2026-01-02 03:04:05', updatedAt: '2026-01-03 03:04:05', disabledAt: null,
})
assert.ok(camel)
assert.equal(camel.gatingType, '品牌gating')
assert.equal(camel.shopName, '店A')
assert.equal(camel.createdAt, '2026-01-02 03:04:05')
assert.equal(camel.disabledAt, undefined)
const snake = toGatingItem({
id: 9, gating_type: '类目gating', shop_name: '店B',
created_at: '2026-02-01 00:00:00', updated_at: '2026-02-02 00:00:00', disabled_at: '2026-02-03 00:00:00',
})
assert.ok(snake)
assert.equal(snake.gatingType, '类目gating')
assert.equal(snake.shopName, '店B')
assert.equal(snake.disabledAt, '2026-02-03 00:00:00')
})
test('gating_item_parse_invalid_rows_dropped', () => {
assert.equal(toGatingItem(null), null)
assert.equal(toGatingItem({ brand: 'no-id' }), null)
const page = parseGatingPage({ total: 3, rows: [{ id: 1, brand: 'a' }, { brand: 'bad' }, 'junk', null] })
assert.equal(page.rows.length, 1)
assert.equal(page.rows[0]?.brand, 'a')
assert.equal(page.total, 3)
})
test('gating_page_parse_empty_and_items_alias', () => {
assert.deepEqual(parseGatingPage(null), { rows: [], total: 0 })
const page = parseGatingPage({ total: 1, items: [{ id: 2, brand: 'b' }] })
assert.equal(page.rows.length, 1)
assert.equal(page.rows[0]?.id, 2)
})
test('gating_stats_parse_array_and_dict_forms', () => {
// 契约数组形态。
const stats = parseGatingStats({
total: 10, active: 8, disabled: 2, brands: 5,
byType: [{ name: '品牌gating', count: 6 }, { name: '类目gating', count: 2 }],
byCountry: [{ name: '英国', count: 4 }],
bySource: [{ name: 'AUTO', count: 7 }],
})
assert.equal(stats.total, 10)
assert.equal(stats.brands, 5)
assert.equal(stats.byType[0]?.name, '品牌gating')
assert.equal(stats.bySource[0]?.count, 7)
// 桌面版遗留 dict 形态也要能收。
const legacy = parseGatingStats({ total: 1, by_type: { '品牌gating': 3 }, by_country: { '全部': 1 }, by_source: { MANUAL: 1 } })
assert.equal(legacy.byType[0]?.name, '品牌gating')
assert.equal(legacy.byType[0]?.count, 3)
assert.equal(legacy.byCountry[0]?.name, '全部')
})
test('gating_name_count_list_garbage_in_empty_out', () => {
assert.deepEqual(parseGatingNameCountList(null), [])
assert.deepEqual(parseGatingNameCountList('x'), [])
assert.deepEqual(parseGatingNameCountList([{ name: '', count: 1 }, { count: 2 }, 'junk']), [])
})
test('gating_status_label', () => {
assert.equal(gatingStatusLabel(1), '生效')
assert.equal(gatingStatusLabel(0), '停用')
assert.equal(gatingStatusLabel(undefined), '停用')
})
@@ -1,138 +0,0 @@
/**
* 品牌Gating库页面挂载测试:渲染(统计卡 + 行)与两次操作载荷断言(新增、恢复生效)。
* 跑法:`npm run test:mount`(vitest + jsdom,配置见 vitest.config.ts)。
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import GatingPage from '@/pages/gating/GatingPage.vue'
const gatingApi = vi.hoisted(() => ({
fetchGatingPage: vi.fn(),
fetchGatingStats: vi.fn(),
createGating: vi.fn(),
deleteGating: vi.fn(),
updateGatingStatus: vi.fn(),
importGatingText: vi.fn(),
}))
vi.mock('@/pages/gating/gating-api', () => gatingApi)
const listPayload = {
total: 2,
rows: [
{
id: 1,
brand: 'jellycat',
asin: 'B0ABC123',
country: '英国',
gatingType: '品牌gating',
status: 1,
source: 'AUTO',
shopName: '',
remark: '',
createdAt: '2026-01-02 03:04:05',
updatedAt: '2026-01-03 03:04:05',
},
{
id: 2,
brand: 'crocs',
asin: '',
country: '全部',
gatingType: '类目gating',
status: 0,
source: 'MANUAL',
shopName: '店A',
remark: '人为录入',
createdAt: '2026-02-01 00:00:00',
updatedAt: '2026-02-02 00:00:00',
disabledAt: '2026-02-03 00:00:00',
},
],
}
const statsPayload = {
total: 2,
active: 1,
disabled: 1,
brands: 2,
byType: [{ name: '品牌gating', count: 1 }],
byCountry: [{ name: '英国', count: 1 }],
bySource: [{ name: 'MANUAL', count: 1 }],
}
const findButton = (wrapper: VueWrapper, label: string) =>
wrapper.findAll('button').find((button) => button.text().trim() === label)
describe('GatingPage', () => {
beforeEach(() => {
vi.clearAllMocks()
gatingApi.fetchGatingPage.mockResolvedValue(listPayload)
gatingApi.fetchGatingStats.mockResolvedValue(statsPayload)
})
it('渲染统计卡、筛选区与表格行', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
const text = wrapper.text()
expect(text).toContain('Gating总记录')
expect(text).toContain('去重品牌数')
expect(text).toContain('jellycat')
expect(text).toContain('crocs')
expect(text).toContain('生效')
expect(text).toContain('停用')
expect(text).toContain('按Gating类型')
expect(wrapper.findAll('tbody tr').length).toBeGreaterThanOrEqual(2)
expect(gatingApi.fetchGatingPage).toHaveBeenCalledTimes(1)
expect(gatingApi.fetchGatingStats).toHaveBeenCalledTimes(1)
})
it('新增弹窗提交后按驼峰字段发载荷', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
gatingApi.createGating.mockResolvedValue(1)
await findButton(wrapper, '新增')!.trigger('click')
const modal = wrapper.get('.modal')
const inputs = modal.findAll('input[type="text"]')
await inputs[0]!.setValue('jellycat') // 品牌
await inputs[1]!.setValue('B0Z9X') // ASIN
await inputs[2]!.setValue('店A') // 店铺
await inputs[3]!.setValue('测试备注') // 备注
await findButton(modal, '保存')!.trigger('click')
await flushPromises()
expect(gatingApi.createGating).toHaveBeenCalledTimes(1)
expect(gatingApi.createGating).toHaveBeenCalledWith({
brand: 'jellycat',
asin: 'B0Z9X',
country: '全部',
gatingType: '品牌gating',
source: 'MANUAL',
shopName: '店A',
remark: '测试备注',
})
})
it('停用行点恢复 → POST status 载荷 status=1;品牌为空时新增被拦截', async () => {
const wrapper = mount(GatingPage)
await flushPromises()
const crocsRow = wrapper
.findAll('tbody tr')
.find((row) => row.text().includes('crocs'))!
await findButton(crocsRow, '恢复')!.trigger('click')
await flushPromises()
expect(gatingApi.updateGatingStatus).toHaveBeenCalledTimes(1)
expect(gatingApi.updateGatingStatus).toHaveBeenCalledWith(2, 1)
// 品牌必填:空品牌提交不发请求
await findButton(wrapper, '新增')!.trigger('click')
await findButton(wrapper.get('.modal'), '保存')!.trigger('click')
await flushPromises()
expect(gatingApi.createGating).not.toHaveBeenCalled()
})
})
@@ -36,7 +36,6 @@ const OPS_MIN_COL_PX: Record<string, number> = {
'src/pages/asin/ProductCategoryPage.vue': 138,
'src/pages/asin/QueryAsinPage.vue': 138,
'src/pages/asin/SkipPricePage.vue': 138,
'src/pages/gating/GatingPage.vue': 138,
'src/pages/records/DeviceLogsPage.vue': 138,
'src/pages/records/RecordsDigitalHumanVersionPage.vue': 287,
'src/pages/records/RecordsSoftwareVersionPage.vue': 77,