feat(jd): 京东数据库与建单页类目面板换京麦授权类目真树(2026-11-16 客户拍板「京麦类目是这些 我们后台的现在的不对」+「你直接爬」)
真机取证京麦首屏接口 getVenderLicenseCategory(62KB:一级就 3 个=该店铺授权经营类目 服饰内衣1315/母婴1319/运动户外1318,250 个末级,最深 4 级;落库末级名样本「艺考形体服/啦啦队服/拉丁舞服」都在树内 level 3=category_path 等值过滤契约成立;4 组末级同名跨支如实登记,取证件 D:/tmp/jd_cat_probe/)。两份 jd-category-tree.ts 正本同轮重写;JdCategoryCascader 重做京麦同款逐级下钻+末级选中(admin 单选过滤/建单页多选 categoryPaths),搜索搜树内末级(行 title 带路径)+树外兜底段(京麦树已无的历史名仍可选);建单页 hint 文案随真树口径更新。判据:vue-tsc×2 rc=0;node --test 树测试 6/6×2+jd-collect-tab 9/9;vitest admin mount 28/28、用户端 mount 78/78(「勾选类目」用例改真树下钻 运动户外>舞蹈体操鞋服/装备>艺考形体服);fast 闸门 overall=pass 四面绿
This commit is contained in:
@@ -1,19 +1,97 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { jdCategoryNavChildren, jdCategoryNavRoots } from '../src/pages/jd/jd-category-tree.ts'
|
||||
import {
|
||||
JD_CATEGORY_TREE,
|
||||
jdCategoryChildren,
|
||||
jdCategoryLeaves,
|
||||
jdCategoryRoots,
|
||||
jdCategorySearchLeaves,
|
||||
} from '../src/pages/jd/jd-category-tree.ts'
|
||||
|
||||
/** 建单页类目级联的静态导航树(与后管 admin-frontend-vue/tests/jd-product-group.test.ts
|
||||
* 同判据同数据——两份正本必须同形,改树两边同轮同步)。 */
|
||||
test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源', () => {
|
||||
assert.deepEqual(jdCategoryNavChildren('服饰内衣'),
|
||||
['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
|
||||
assert.deepEqual(jdCategoryNavChildren('不存在的一级'), [],
|
||||
'未知一级回落空子级(面板该栏缺省)')
|
||||
/** 京麦授权类目真树(2026-11-16 真机取证 getVenderLicenseCategory 快照;与后管
|
||||
* admin-frontend-vue 侧同数据两份正本,改树两边同轮同步)。判据钉的是取证读数:
|
||||
* 3 个一级 / 250 个末级 / 最深 4 级 / 5 个同名跨支——改树先对取证数据(京麦面板
|
||||
* 或 getVenderLicenseCategory 重抓),不得手改数字凑测试。 */
|
||||
test('树形状=京麦授权类目真机读数:3 个一级、250 个末级、最深 4 级', () => {
|
||||
const roots = jdCategoryRoots()
|
||||
assert.deepEqual(
|
||||
roots.map((node) => node.name),
|
||||
['服饰内衣', '母婴', '运动户外'],
|
||||
'一级就 3 个(京麦面板 2026-11-16 真机:该店铺授权经营类目,不得加回京东公开全量)',
|
||||
)
|
||||
assert.deepEqual(
|
||||
roots.map((node) => node.value),
|
||||
['1315', '1319', '1318'],
|
||||
'一级类目 id 与取证响应逐字同',
|
||||
)
|
||||
const leaves = jdCategoryLeaves()
|
||||
assert.equal(leaves.length, 250, '末级节点 250 个(取证读数)')
|
||||
const maxDepth = Math.max(...leaves.map((leaf) => leaf.path.length))
|
||||
assert.equal(maxDepth, 4, '树最深 4 级')
|
||||
})
|
||||
|
||||
test('一级导航顺序——服饰内衣置首、不得重复、常用集在册', () => {
|
||||
const roots = jdCategoryNavRoots()
|
||||
assert.ok(roots.length >= 20, '一级类目常用集至少 20 个')
|
||||
assert.equal(new Set(roots).size, roots.length, '一级类目不得重复')
|
||||
assert.equal(roots[0], '服饰内衣', '服饰内衣置首(客户主采类目)')
|
||||
test('服饰内衣二级与京麦面板逐字同源;逐级下钻到真机样本叶', () => {
|
||||
assert.deepEqual(
|
||||
jdCategoryChildren(['服饰内衣']).map((node) => node.name),
|
||||
['服饰配件', '内衣', '女装', '男装', '定制服装/工装'],
|
||||
'服饰内衣二级 5 个(京麦面板逐字)',
|
||||
)
|
||||
assert.deepEqual(
|
||||
jdCategoryChildren(['服饰内衣', '服饰配件']).map((node) => node.name),
|
||||
['腰带/腰链', '耳罩/耳包', '领带/领结/领带夹', '男士丝巾/围巾', '女士丝巾/围巾/披肩', '鸭舌帽',
|
||||
'礼帽', '手套', '围巾/手套/帽子套装', '毛线帽', '遮阳帽', '棒球帽', '渔夫帽'],
|
||||
'服饰配件三级 13 个(京麦面板 2026-11-16 截图逐字前 6 +取证快照全量)',
|
||||
)
|
||||
assert.deepEqual(
|
||||
jdCategoryChildren(['服饰内衣', '服饰配件', '腰带/腰链']),
|
||||
[],
|
||||
'三级叶子 children 空(末级,可选中)',
|
||||
)
|
||||
assert.deepEqual(
|
||||
jdCategoryChildren(['不存在的一级']),
|
||||
[],
|
||||
'未知路径回落空子级(面板该栏缺省)',
|
||||
)
|
||||
})
|
||||
|
||||
test('落库末级名真机样本都在树内(category_path 等值过滤成立的前提)', () => {
|
||||
const names = new Set(jdCategoryLeaves().map((leaf) => leaf.name))
|
||||
for (const sample of ['艺考形体服', '啦啦队服', '拉丁舞服']) {
|
||||
assert.ok(names.has(sample), `真机样本「${sample}」必须是树内末级(契约 E3 口径)`)
|
||||
}
|
||||
const yikao = jdCategoryLeaves().find((leaf) => leaf.name === '艺考形体服')
|
||||
assert.ok(yikao, '艺考形体服在树内')
|
||||
assert.equal(yikao!.path.length, 3, '艺考形体服是 level 3 节点(取证读数)')
|
||||
})
|
||||
|
||||
test('同名跨支叶子如实登记:4 组重名(同名行等值过滤一起命中,B112-05 口径)', () => {
|
||||
const counts = new Map<string, number>()
|
||||
for (const leaf of jdCategoryLeaves()) {
|
||||
counts.set(leaf.name, (counts.get(leaf.name) ?? 0) + 1)
|
||||
}
|
||||
const dups = [...counts.entries()].filter(([, count]) => count > 1)
|
||||
assert.deepEqual(
|
||||
dups.map(([name]) => name).sort(),
|
||||
['唐装', '吊带/背心', '短裤', '赠品'].sort(),
|
||||
'重名集与取证读数逐字同(改树后这里红=重名集变了,须复核登记)。注:「汉服」两处节点中'
|
||||
+ '一处带四级子级是非叶(点它会下钻),不构成末级重名。',
|
||||
)
|
||||
})
|
||||
|
||||
test('搜索:按名称或路径段命中末级;空词返回全量', () => {
|
||||
assert.equal(jdCategorySearchLeaves('').length, 250, '空词=全量末级')
|
||||
const byName = jdCategorySearchLeaves('艺考')
|
||||
assert.equal(byName.length, 1)
|
||||
assert.equal(byName[0]!.name, '艺考形体服')
|
||||
const byPath = jdCategorySearchLeaves('服饰配件')
|
||||
assert.ok(byPath.length >= 12, '按路径段命中服饰配件全部末级')
|
||||
assert.ok(byPath.every((leaf) => leaf.path.includes('服饰配件')))
|
||||
assert.deepEqual(jdCategorySearchLeaves('不存在词xyz'), [])
|
||||
})
|
||||
|
||||
test('树数据快照不可空、value 全非空(取证 id 留档完整)', () => {
|
||||
assert.ok(JD_CATEGORY_TREE.length > 0)
|
||||
for (const leaf of jdCategoryLeaves()) {
|
||||
assert.ok(leaf.value, `叶子 ${leaf.name} 必须带京麦类目 id`)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -284,32 +284,41 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
})
|
||||
|
||||
it('勾选类目后建单:categoryPaths 随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 用户口径「客户端前端也要同步加上京东类目」:多选面板勾「女装」后
|
||||
// 建单请求体与推送载荷都要带 ['女装']——客户端按行 categoryPath 等值过滤的源头。
|
||||
// 2026-11-16 用户口径「客户端前端也要同步加上京东类目」+「你直接爬」:面板换京麦
|
||||
// 授权类目真树(逐级下钻、末级勾选)——下钻 运动户外 → 舞蹈体操鞋服/装备(客户
|
||||
// 舞蹈服类目在京麦归运动户外支)→ 勾末级「艺考形体服」后建单请求体与推送载荷都要
|
||||
// 带 ['艺考形体服'](客户端按行 categoryPath 等值过滤的源头;mock 类目用树内真实
|
||||
// 末级名,贴合落库形状)。
|
||||
api.fetchJdCollectCategories.mockResolvedValue([
|
||||
{ name: '女装', productCount: 5 },
|
||||
{ name: '男装', productCount: 3 },
|
||||
{ name: '艺考形体服', productCount: 5 },
|
||||
{ name: '啦啦队服', productCount: 3 },
|
||||
])
|
||||
const w = await mountPage()
|
||||
|
||||
await w.find('.cat-trigger').trigger('click')
|
||||
const leafRow = w.findAll('.cat-row').find((row) => row.text().includes('女装'))
|
||||
expect(leafRow, '面板第三栏必须渲染出已落库类目选项').toBeTruthy()
|
||||
await w.findAll('.cat-col')[0].findAll('.cat-row').find((row) => row.text().includes('运动户外'))!.trigger('click')
|
||||
let cols = w.findAll('.cat-col')
|
||||
expect(cols).toHaveLength(2, '点亮一级后第二栏出现(真树下钻)')
|
||||
await cols[1].findAll('.cat-row').find((row) => row.text().includes('舞蹈体操鞋服/装备'))!.trigger('click')
|
||||
cols = w.findAll('.cat-col')
|
||||
expect(cols).toHaveLength(3, '二级非末级:第三栏出末级子级')
|
||||
const leafRow = cols[2].findAll('.cat-row').find((row) => row.text().includes('艺考形体服'))
|
||||
expect(leafRow, '第三栏必须渲染出该支的末级(艺考形体服)').toBeTruthy()
|
||||
await leafRow!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(w.find('.cat-trigger-text').text()).toBe('女装', '单选勾选后触发框显示类目名')
|
||||
expect(w.find('.cat-trigger-text').text()).toBe('艺考形体服', '单选勾选后触发框显示类目名')
|
||||
await w.find('.cat-mask').trigger('click')
|
||||
await startCollect(w)
|
||||
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, ['女装'])
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, ['艺考形体服'])
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
expect(payload.data).toEqual({
|
||||
taskId: 88,
|
||||
shopName: '京麦后台',
|
||||
listTabs: ['ONSALE', 'OFFSALE'],
|
||||
maxProducts: 0,
|
||||
categoryPaths: ['女装'],
|
||||
categoryPaths: ['艺考形体服'],
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user