feat(京东数据库): 撤销按公司隔离回归全平台共享采集池+后管商品目录改京东平台类目平铺
客户口径(2026-11-26):「采集的数据可以重复被操作分类,大家一起采集,但分类后的 数据就自己看,所以会有数据副本」「被分类后按组 id 绑定拷贝数据副本,原来的数据 也要留着」。 - 可见口径:商品行全平台共享(2026-11-23 的按公司隔离整批撤销),读侧撤 companyId 谓词(列表/类目下拉/候选店铺/详情/导出),写侧撤 assertRowsInCompany 行级公司闸——越权由端点级 requireJdProductWrite(仅平台超管+公司超管)兜住。 「副本」落在 V203 归属行上:同一商品可多组各一条 owner_group_id,分类列/分类 筛选各看各的;原商品行一条不删不藏,别组分过类的在本组仍显示未分类、可再分。 - 用户端选品 pageInScope 不再按 companyId 收窄(只认可见分组下的归属行)。 - 后管左栏「商品目录」:授权类目树/内置花屿巷快照退役,改为 /categories 的 category_path 平铺(末级类目名+商品数),点行=末级名等值过滤;删 jd-category-tree.ts / jd-shop-category-api.ts 及其测试,JdDatabasePage 不再取树。 - 判据:AdminJdProductControllerTest 34、JdProductMapperSqlTest 5、 JdGroupShopServiceTest 10、JdProductQueryServiceUserPageTest 7 全绿; 后管 node --test 1963/vitest 250/vue-tsc rc=0。
This commit is contained in:
@@ -1,374 +0,0 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import {
|
||||
JD_CATEGORY_TREE,
|
||||
jdCategoryAllNodes,
|
||||
jdCategoryChildren,
|
||||
jdCategoryCountTree,
|
||||
jdCategoryLeaves,
|
||||
jdCategoryNamesUnder,
|
||||
jdCategoryPruneZero,
|
||||
jdCategoryRoots,
|
||||
jdCategorySearchLeaves,
|
||||
jdCategorySearchNodes,
|
||||
parseJdCategoryNodeTree,
|
||||
type JdCategoryCountedNode,
|
||||
type JdCategoryNode,
|
||||
} from '../src/pages/jd/jd-category-tree.ts'
|
||||
|
||||
/** 京麦授权类目真树(2026-11-16 真机取证 getVenderLicenseCategory 快照;与用户端
|
||||
* frontend-vue 侧同数据两份正本,改树两边同轮同步)。判据钉的是取证读数:
|
||||
* 3 个一级 / 250 个末级 / 最深 4 级 / 4 组同名跨支——改树先对取证数据(京麦面板
|
||||
* 或 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('服饰内衣二级与京麦面板逐字同源;逐级下钻到真机样本叶', () => {
|
||||
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 >= 13, '按路径段命中服饰配件全部末级')
|
||||
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`)
|
||||
}
|
||||
})
|
||||
|
||||
/** 2026-11-18 客户口径「一级/二级类目也要能选来搜索」:全层级节点+子树展开集合。 */
|
||||
test('全节点搜索:一级/二级/末级都在结果里,leaf 标记如实', () => {
|
||||
assert.equal(jdCategorySearchNodes('').length, jdCategoryAllNodes().length, '空词=全量节点')
|
||||
assert.ok(jdCategoryAllNodes().length > 250, '全节点数必须大于末级 250(含非末级)')
|
||||
const byName = jdCategorySearchNodes('女装')
|
||||
const women = byName.find((node) => node.name === '女装')
|
||||
assert.ok(women, '「女装」这个二级节点必须可搜到(旧版只铺末级,选不了它)')
|
||||
assert.equal(women!.leaf, false, '女装有子级=非末级')
|
||||
assert.deepEqual(women!.path, ['服饰内衣', '女装'], '路径从一级起(同名跨支靠它区分)')
|
||||
assert.ok(byName.some((node) => node.leaf), '末级命中照旧在')
|
||||
})
|
||||
|
||||
test('子树展开集合:含自身+全部后代名、去重、不越支;路径失效回 null', () => {
|
||||
const dress = jdCategoryNamesUnder(['服饰内衣', '女装', '连衣裙'])
|
||||
assert.ok(dress, '连衣裙路径有效')
|
||||
assert.ok(dress!.includes('连衣裙'), '含节点自身名(实际末级可能就在这一级)')
|
||||
assert.ok(dress!.includes('短袖连衣裙') && dress!.includes('长袖连衣裙') && dress!.includes('无袖连衣裙'))
|
||||
assert.ok(!dress!.includes('女装'), '只展开本节点子树,不带上父级')
|
||||
|
||||
const top = jdCategoryNamesUnder(['运动户外'])
|
||||
assert.ok(top!.includes('艺考形体服') && top!.includes('啦啦队服'), '一级展开覆盖全支')
|
||||
assert.ok(!top!.includes('女装'), '不越支')
|
||||
|
||||
const hanfu = jdCategoryNamesUnder(['服饰内衣', '女装', '汉服'])
|
||||
assert.ok(hanfu!.includes('汉服') && hanfu!.includes('汉服套装'), '非叶「汉服」展开含四级')
|
||||
|
||||
assert.equal(jdCategoryNamesUnder(['不存在', '的路径']), null, '路径失效回 null(调用方按单名兜底)')
|
||||
assert.equal(jdCategoryNamesUnder([]), null, '空路径回 null')
|
||||
|
||||
// 去重:同名跨支在**同一子树内**出现两次时集合不重复(唐装/短裤等在女装支内只有一个)。
|
||||
const women = jdCategoryNamesUnder(['服饰内衣', '女装'])!
|
||||
assert.equal(new Set(women).size, women.length, '展开集合内部去重')
|
||||
})
|
||||
|
||||
/** v1.6 蓝图 Phase 1 备料:/categories 计数行 → 树形计数聚合(侧栏徽标的数据源)。 */
|
||||
/** 按名称路径取计数节点(与 jdCategoryChildren 同构的测试侧寻路)。 */
|
||||
const nodeAt = (roots: JdCategoryCountedNode[], path: string[]): JdCategoryCountedNode | null => {
|
||||
let level = roots
|
||||
let hit: JdCategoryCountedNode | null = null
|
||||
for (const name of path) {
|
||||
hit = level.find((node) => node.name === name) ?? null
|
||||
if (!hit) return null
|
||||
level = hit.children
|
||||
}
|
||||
return hit
|
||||
}
|
||||
|
||||
test('计数聚合——节点徽标=自身名+子树叶和,与 jdCategoryNamesUnder 展开集合同源', () => {
|
||||
const tree = jdCategoryCountTree([
|
||||
{ name: '艺考形体服', productCount: 5 },
|
||||
{ name: '啦啦队服', productCount: 3 },
|
||||
{ name: '拉丁舞服', productCount: 2 },
|
||||
{ name: '连衣裙', productCount: 7 },
|
||||
{ name: '短袖连衣裙', productCount: 4 },
|
||||
])
|
||||
assert.equal(tree.extra.length, 0, '树内名字不进兜底组')
|
||||
assert.equal(tree.extraTotal, 0)
|
||||
|
||||
const roots = tree.roots
|
||||
assert.equal(roots.length, 3, '一级节点全量保留(无词条的一级也在)')
|
||||
assert.deepEqual(
|
||||
roots.map((node) => node.name),
|
||||
['服饰内衣', '母婴', '运动户外'],
|
||||
)
|
||||
assert.equal(roots.find((node) => node.name === '母婴')!.count, 0, '无词条的一级归 0 不缺节点')
|
||||
|
||||
const sport = nodeAt(roots, ['运动户外'])!
|
||||
assert.equal(sport.count, 10, '运动户外=艺考5+啦啦3+拉丁2')
|
||||
assert.equal(sport.leaf, false)
|
||||
const dance = nodeAt(roots, ['运动户外', '舞蹈体操鞋服/装备'])!
|
||||
assert.equal(dance.count, 10, '二级下钻同和')
|
||||
const yikao = nodeAt(roots, ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'])!
|
||||
assert.equal(yikao.count, 5, '末级叶子=该名计数')
|
||||
assert.equal(yikao.leaf, true, 'children 空=末级')
|
||||
assert.deepEqual(yikao.children, [], '叶子 children 是空数组(UI 直接遍历不炸)')
|
||||
|
||||
const dress = nodeAt(roots, ['服饰内衣', '女装', '连衣裙'])!
|
||||
assert.equal(dress.count, 11, '连衣裙=自身名7+短袖4(长袖/无袖无词条归 0)')
|
||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 11, '女装只有连衣裙支有词条')
|
||||
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 11, '一级汇总到根')
|
||||
|
||||
const dressLeaves = nodeAt(roots, ['服饰内衣', '女装', '连衣裙'])!.children.map((node) => node.name)
|
||||
assert.deepEqual(dressLeaves, ['短袖连衣裙', '长袖连衣裙', '无袖连衣裙'], '子节点形状与静态树逐字同')
|
||||
})
|
||||
|
||||
test('计数聚合——父级名本身是落库末级名:计入自身节点(快照层级可能比实际浅)', () => {
|
||||
const tree = jdCategoryCountTree([
|
||||
{ name: '女装', productCount: 6 },
|
||||
{ name: '短袖连衣裙', productCount: 1 },
|
||||
])
|
||||
const roots = tree.roots
|
||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 7, '女装徽标=自身6+子树1')
|
||||
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 7)
|
||||
assert.equal(tree.extra.length, 0, '非叶名也是合法落库名,不进兜底组')
|
||||
})
|
||||
|
||||
test('计数聚合——同名跨支叶:两个分支都计入(点哪支都等值命中同一批行),父层去重不翻倍', () => {
|
||||
const tree = jdCategoryCountTree([{ name: '短裤', productCount: 9 }])
|
||||
const roots = tree.roots
|
||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 9, '女装支的短裤叶如实计入')
|
||||
assert.equal(nodeAt(roots, ['服饰内衣', '男装'])!.count, 9, '男装支的同名叶同计数(过滤语义非双计)')
|
||||
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 9,
|
||||
'父层子树按名字去重求和:展开集合里短裤只出现一次,徽标不得翻倍成 18')
|
||||
assert.equal(tree.extra.length, 0)
|
||||
})
|
||||
|
||||
test('计数聚合——树外兜底组:树上任何节点名都对不上的历史行单独归组', () => {
|
||||
const tree = jdCategoryCountTree([
|
||||
{ name: '已下架历史类目', productCount: 12 },
|
||||
{ name: '另一个树外名', productCount: 8 },
|
||||
{ name: '艺考形体服', productCount: 5 },
|
||||
])
|
||||
assert.deepEqual(
|
||||
tree.extra.map((row) => row.name),
|
||||
['已下架历史类目', '另一个树外名'],
|
||||
'兜底组按入参顺序保留',
|
||||
)
|
||||
assert.deepEqual(
|
||||
tree.extra.map((row) => row.productCount),
|
||||
[12, 8],
|
||||
)
|
||||
assert.equal(tree.extraTotal, 20, '兜底组和=徽标直接用')
|
||||
const sport = nodeAt(tree.roots, ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'])!
|
||||
assert.equal(sport.count, 5, '树内行照常聚合,兜底不影响树形')
|
||||
})
|
||||
|
||||
test('计数聚合——脏值归一:空名跳过、非有限/负数归 0、前后空白截掉、同名多行求和', () => {
|
||||
const tree = jdCategoryCountTree([
|
||||
{ name: '', productCount: 5 },
|
||||
{ name: ' ', productCount: 7 },
|
||||
{ name: '短裤', productCount: Number.NaN },
|
||||
{ name: '唐装', productCount: -3 },
|
||||
{ name: ' 女装 ', productCount: 2 },
|
||||
{ name: '女装', productCount: 3 },
|
||||
{ name: '艺考形体服', productCount: '4' as unknown as number },
|
||||
] as { name: string; productCount: number }[])
|
||||
const roots = tree.roots
|
||||
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 5, 'trim 后同名求和 2+3')
|
||||
assert.equal(nodeAt(roots, ['服饰内衣', '男装'])!.count, 0, 'NaN/负数/空名都归 0 不记账')
|
||||
assert.equal(tree.extra.length, 0, '空名词条不进兜底组')
|
||||
assert.equal(tree.extraTotal, 0)
|
||||
})
|
||||
|
||||
test('计数聚合——treeMatched 三态:树内有命中/整树零命中(别店快照树)/数据没到', () => {
|
||||
// 树内任一节点有行 ⇒ true(正常店:库内类目名挂得上内置授权树)。
|
||||
const matched = jdCategoryCountTree([{ name: '连衣裙', productCount: 3 }])
|
||||
assert.equal(matched.treeMatched, true)
|
||||
|
||||
// 2026-11-23 活样本:家居日用店打开「花屿巷旗舰店」那份服饰授权快照树——库内
|
||||
// 类目名一个都不在树上(收纳盒/收纳架全落兜底),树内节点全 0。
|
||||
const foreign = jdCategoryCountTree([
|
||||
{ name: '化妆品收纳盒', productCount: 260 },
|
||||
{ name: '其他收纳架', productCount: 4 },
|
||||
])
|
||||
assert.equal(foreign.treeMatched, false, '整树零命中 ⇒ 侧栏收树、不拿别店的树冒充本店')
|
||||
assert.equal(foreign.extra.length, 2)
|
||||
assert.equal(foreign.extraTotal, 264)
|
||||
assert.equal(foreign.roots.every((root) => root.count === 0), true)
|
||||
|
||||
// 数据没到(空输入)同样是 false,但兜底为空——侧栏靠剪枝后树为空 + extra 非空决定
|
||||
// 怎么渲染(树空则本店类目平铺成一级列表),不靠 treeMatched 判「加载中」。
|
||||
const empty = jdCategoryCountTree([])
|
||||
assert.equal(empty.treeMatched, false)
|
||||
assert.equal(empty.extra.length, 0)
|
||||
|
||||
// 树内名但计数 0(脏值/归一后)不算命中:徽标与命中集合必须同源。
|
||||
const zero = jdCategoryCountTree([{ name: '连衣裙', productCount: 0 }])
|
||||
assert.equal(zero.treeMatched, false)
|
||||
})
|
||||
|
||||
test('计数聚合——空输入:全树 0、兜底组空(结构仍完整可渲染)', () => {
|
||||
const tree = jdCategoryCountTree([])
|
||||
assert.equal(tree.roots.length, 3)
|
||||
assert.equal(tree.extra.length, 0)
|
||||
assert.equal(tree.extraTotal, 0)
|
||||
const total = tree.roots.reduce((sum, node) => sum + node.count, 0)
|
||||
assert.equal(total, 0)
|
||||
// 结构与静态树同形:一级孩子数与 jdCategoryChildren 逐一对齐。
|
||||
for (const root of tree.roots) {
|
||||
assert.deepEqual(
|
||||
root.children.map((node) => node.name),
|
||||
jdCategoryChildren([root.name]).map((node) => node.name),
|
||||
)
|
||||
}
|
||||
// 非数组入参按空处理(运行期 resilience,JS 调用方传 null 不炸)。
|
||||
const junk = jdCategoryCountTree(null as unknown as [])
|
||||
assert.equal(junk.roots.length, 3)
|
||||
assert.equal(junk.extraTotal, 0)
|
||||
})
|
||||
|
||||
test('服务端授权树解析:与内置快照同形、空名节点丢自身保子级、非数组/超深归空', () => {
|
||||
const parsed = parseJdCategoryNodeTree([
|
||||
{ name: ' 收纳用品 ', value: '7001', children: [
|
||||
{ name: '化妆品收纳盒', value: '7002' },
|
||||
{ name: '', value: 'x', children: [{ name: '孤儿但保留', value: '7003' }] },
|
||||
{ notAnObject: true },
|
||||
] },
|
||||
{ name: '厨房用品', value: 7004 },
|
||||
])
|
||||
assert.deepEqual(parsed, [
|
||||
{ name: '收纳用品', value: '7001', children: [
|
||||
{ name: '化妆品收纳盒', value: '7002' },
|
||||
{ name: '孤儿但保留', value: '7003' },
|
||||
] },
|
||||
{ name: '厨房用品', value: '7004' },
|
||||
], 'name trim、value 数字转串、空名节点自身丢弃但子级上提')
|
||||
|
||||
assert.deepEqual(parseJdCategoryNodeTree(null), [], '非数组按空处理(接口抖动不炸渲染)')
|
||||
|
||||
// 10 层脏数据:只留前 9 层(depth 0..8),第 10 层被护栏截断。
|
||||
let deep: unknown = [{ name: 'L10', value: '10' }]
|
||||
for (let i = 9; i >= 1; i--) {
|
||||
deep = [{ name: 'L' + i, value: String(i), children: deep }]
|
||||
}
|
||||
assert.equal(JSON.stringify(parseJdCategoryNodeTree(deep)).includes('L10'), false,
|
||||
'超过 8 层的脏数据不递归下去(护栏在解析层,不留给渲染层)')
|
||||
})
|
||||
|
||||
test('计数聚合——传入服务端真树:家居类目挂得上树、不再落兜底(2026-11-23 家居店活样本)', () => {
|
||||
const homeTree: JdCategoryNode[] = [
|
||||
{ name: '收纳用品', value: '7001', children: [
|
||||
{ name: '化妆品收纳盒', value: '7002' },
|
||||
{ name: '脏衣篓', value: '7003' },
|
||||
] },
|
||||
{ name: '厨房用品', value: '7101', children: [{ name: '其他收纳架', value: '7102' }] },
|
||||
]
|
||||
const counts = [
|
||||
{ name: '化妆品收纳盒', productCount: 260 },
|
||||
{ name: '其他收纳架', productCount: 4 },
|
||||
]
|
||||
const real = jdCategoryCountTree(counts, homeTree)
|
||||
assert.equal(real.treeMatched, true, '真树有命中 ⇒ 侧栏不收树')
|
||||
assert.equal(real.extra.length, 0, '家居类目全部挂得上真树,不再落树外兜底')
|
||||
assert.equal(real.roots.length, 2)
|
||||
assert.equal(nodeAt(real.roots, ['收纳用品', '化妆品收纳盒'])!.count, 260)
|
||||
assert.equal(nodeAt(real.roots, ['收纳用品'])!.count, 260, '父级徽标=子树和')
|
||||
assert.equal(nodeAt(real.roots, ['厨房用品'])!.count, 4)
|
||||
|
||||
// 同一批计数行套内置快照树 ⇒ 整树零命中(数据没错,是树不对——这就是本次修的那个形状)。
|
||||
const snapshot = jdCategoryCountTree(counts)
|
||||
assert.equal(snapshot.treeMatched, false)
|
||||
assert.equal(snapshot.extraTotal, 264)
|
||||
})
|
||||
|
||||
test('剪枝——零命中的别店分支整支剪掉,整树剪空(2026-11-24 客户口径「要的是类目树,不是树外兜底」)', () => {
|
||||
const foreign = jdCategoryCountTree([
|
||||
{ name: '化妆品收纳盒', productCount: 260 },
|
||||
{ name: '其他收纳架', productCount: 4 },
|
||||
])
|
||||
assert.equal(jdCategoryPruneZero(foreign.roots).length, 0,
|
||||
'家居类目套服饰快照树 ⇒ 整树剪空,调用方把 extra 平铺成一级列表(不再有「本店无匹配」档)')
|
||||
})
|
||||
|
||||
test('剪枝——命中分支保留祖先链、重算 leaf,零命中兄弟支不出现', () => {
|
||||
const counted = jdCategoryCountTree([{ name: '连衣裙', productCount: 7 }])
|
||||
const pruned = jdCategoryPruneZero(counted.roots)
|
||||
assert.deepEqual(pruned.map((node) => node.name), ['服饰内衣'], '只有服饰内衣这一支真有商品')
|
||||
assert.equal(nodeAt(pruned, ['服饰内衣', '女装'])!.count, 7, '祖先链上徽标不变(子树去重和)')
|
||||
const dress = nodeAt(pruned, ['服饰内衣', '女装', '连衣裙'])!
|
||||
assert.equal(dress.leaf, true, '子级全被剪掉后重算 leaf(不再显示展开箭头)')
|
||||
assert.equal(nodeAt(pruned, ['服饰内衣', '男装']), null, '零命中兄弟支剪掉')
|
||||
assert.equal(nodeAt(pruned, ['母婴']), null, '整支零命中的一级剪掉')
|
||||
})
|
||||
|
||||
test('剪枝——空输入/异常入参回空数组(渲染层不炸)', () => {
|
||||
assert.deepEqual(jdCategoryPruneZero([]), [])
|
||||
assert.deepEqual(jdCategoryPruneZero(null as unknown as JdCategoryCountedNode[]), [])
|
||||
})
|
||||
@@ -97,9 +97,10 @@ test('列表行价格:BigDecimal 的 JSON number 形状与字符串形状都
|
||||
assert.equal(jdPriceRange(missing), '', '两侧都空回空串(列表显示 -)')
|
||||
})
|
||||
|
||||
/** 类目筛选(2026-11-15 末级等值;2026-11-18 一级/二级可选中=子树展开集合 IN):
|
||||
* 空串不下发;无路径=单元素集合(等值旧形状);带路径=jdCategoryNamesUnder 展开。 */
|
||||
test('类目筛选参数序列化:空串不下发、末级单值、父级展开子树集合', async () => {
|
||||
/** 类目筛选(2026-11-26 客户口径「京东分类是百分百有的,京东内分类就不需要」):
|
||||
* 左栏商品目录=京东平台类目(`category_path` DISTINCT 末级名)平铺,点行=单名等值;
|
||||
* 空串不下发。旧「父级点选→按授权树/内置快照展开子树集合」那一层随之退役。 */
|
||||
test('类目筛选参数序列化:空串不下发、选中末级类目=单元素集合(等值)', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
||||
await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const empty = createJdProductFilterState()
|
||||
@@ -108,45 +109,13 @@ test('类目筛选参数序列化:空串不下发、末级单值、父级展
|
||||
|
||||
const leaf = { ...empty, category: ' 艺考形体服 ' }
|
||||
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
|
||||
'无路径=去空白单元素集合(等值旧形状,后端 IN 单值等价)')
|
||||
'末级类目名 trim 后单元素集合(后端 IN 单值等价 eq)')
|
||||
assert.equal(jdProductFilterActive(leaf), true, '选中类目算激活筛选')
|
||||
|
||||
const parent = { ...empty, category: '女装', categoryPath: ['服饰内衣', '女装'] }
|
||||
const expanded = toJdProductListParams(parent, 1, 20).category as string[]
|
||||
assert.ok(Array.isArray(expanded) && expanded.length > 20, '一级/二级选中=子树展开集合')
|
||||
assert.ok(expanded.includes('女装'), '集合含节点自身名(实际末级可能就在这一级)')
|
||||
assert.ok(expanded.includes('连衣裙') && expanded.includes('短袖连衣裙'), '含后代各级名')
|
||||
assert.ok(!expanded.includes('艺考形体服'), '不越出子树(艺考形体服在运动户外支)')
|
||||
|
||||
const stale = { ...empty, category: '已下架历史类目', categoryPath: ['不存在', '的路径'] }
|
||||
assert.deepEqual(toJdProductListParams(stale, 1, 20).category, ['已下架历史类目'],
|
||||
'路径失效(树外历史名)回落单名等值,不静默丢筛选')
|
||||
})
|
||||
|
||||
/** 2026-11-25 断链修复(客户实况「收纳用品 81 点开 0 条」):页面按**服务端真树**展开好的
|
||||
* categoryNames 必须被序列化层直接采用——此前 api 入参没这个字段,集合到不了这里,
|
||||
* 序列化退回内置快照树重展开;真树≠快照(家居店的类目不在花屿巷服饰快照上)时展开失败,
|
||||
* 退化成单名等值 IN,而库里落的是叶子名 → 0 条。 */
|
||||
test('类目筛选序列化优先采用页面算好的 categoryNames,不拿快照树重展开', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams } = await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const empty = createJdProductFilterState()
|
||||
|
||||
const parent = { ...empty, category: '收纳用品', categoryPath: ['收纳用品'],
|
||||
categoryNames: ['收纳用品', '收纳盒', '收纳篮', '收纳架'] }
|
||||
assert.deepEqual(toJdProductListParams(parent, 1, 20).category,
|
||||
['收纳用品', '收纳盒', '收纳篮', '收纳架'],
|
||||
'categoryNames 有值=逐字下发,即便快照树重展开必然失败也不许退化')
|
||||
|
||||
// 对照旧形状:同样路径、无集合=快照展开失败 → 单名兜底(这正是实况 0 条的查询)。
|
||||
const legacy = { ...empty, category: '收纳用品', categoryPath: ['收纳用品'] }
|
||||
assert.deepEqual(toJdProductListParams(legacy, 1, 20).category, ['收纳用品'],
|
||||
'无集合时保留快照展开失败回落单名的旧兜底(修复只加透传,不改兜底语义)')
|
||||
|
||||
// 空数组集合=视同缺省(末级点选/清选形状),走路径展开旧口径。
|
||||
const leaf = { ...empty, category: '艺考形体服',
|
||||
categoryPath: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'], categoryNames: [] }
|
||||
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
|
||||
'空集合数组不冒充展开结果,仍走路径口径')
|
||||
// 历史「父级路径展开」字段已随内置快照树退役:带上也不影响序列化结果(不会凭空多出集合)。
|
||||
const legacy = { ...empty, category: '女装', categoryPath: ['服饰内衣', '女装'] }
|
||||
assert.deepEqual(toJdProductListParams(legacy, 1, 20).category, ['女装'],
|
||||
'没有子树展开集合这一层:父级路径就算传进来也只按单名等值下发')
|
||||
})
|
||||
|
||||
test('自定义分类使用 group_id,不发送分类状态参数', async () => {
|
||||
|
||||
@@ -34,10 +34,6 @@ import {
|
||||
jdOwnershipSelectValue,
|
||||
toJdProductListParams,
|
||||
} from '../src/pages/jd/jd-product-filter.ts'
|
||||
import {
|
||||
jdCategoryChildren,
|
||||
jdCategoryRoots,
|
||||
} from '../src/pages/jd/jd-category-tree.ts'
|
||||
import {
|
||||
JD_PRODUCT_DEFAULT_SIZE,
|
||||
jdPriceRange,
|
||||
@@ -46,20 +42,6 @@ import {
|
||||
toJdProductItem,
|
||||
} from '../src/pages/jd/jd-product-model.ts'
|
||||
|
||||
test('类目级联静态导航树——服饰内衣二级与京麦面板样本逐字同源,一级集非空且无重名', () => {
|
||||
// 京麦面板真机样本(2026-11-16 客户截图):服饰内衣下就是这五个二级,改名即红。
|
||||
assert.deepEqual(jdCategoryChildren(['服饰内衣']).map(node => node.name), ['服饰配件', '内衣', '女装', '男装', '定制服装/工装'])
|
||||
assert.deepEqual(jdCategoryChildren(['不存在的类目']), [], '未知一级回落空子级(面板不出第二栏)')
|
||||
|
||||
const roots = jdCategoryRoots().map(node => node.name)
|
||||
assert.deepEqual(roots, ['服饰内衣', '母婴', '运动户外'], '一级导航与京麦授权类目一致')
|
||||
assert.equal(new Set(roots).size, roots.length, '一级类目名不得重复')
|
||||
for (const root of roots) {
|
||||
const children = jdCategoryChildren([root]).map(node => node.name)
|
||||
assert.equal(new Set(children).size, children.length, `${root} 的二级不得重复`)
|
||||
}
|
||||
})
|
||||
|
||||
test('京东列表参数——snake 形状:keyword/店铺/价格下发,旧编码标题两框停发、日期空白/非法不下发', () => {
|
||||
const full = toJdProductListParams(
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
* 京东数据库侧栏(JdCategorySidebar,v1.6 蓝图 Phase 2)的挂载契约。
|
||||
* 京东数据库侧栏(JdCategorySidebar)的挂载契约。
|
||||
*
|
||||
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本文件零 api mock——
|
||||
* 钉的是「徽标数=点节点后列表命中的行数」(jdCategoryCountTree 同源)、双 Tab 切换、
|
||||
* 点节点 emit 形状(树内带路径/树外兜底 path 空/全部商品 null)、可写档分档入口。
|
||||
* 钉的是双 Tab 切换、商品目录「京东平台类目平铺」口径(2026-11-26 客户口径「京东分类
|
||||
* 百分百有,京东内分类不需要」:平铺一层、点行=末级类目名等值、path 恒空、无授权树/
|
||||
* 无内置快照/无「树外兜底」分组)、可写档分档入口。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/jd-category-sidebar.mount.test.ts`
|
||||
*/
|
||||
@@ -63,250 +64,86 @@ function rowByText(scope: VueWrapper<Element>, text: string) {
|
||||
return row!
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
// v1.7 起展开态持久化 localStorage:用例间清掉防串台(出厂态=无记忆)。
|
||||
localStorage.removeItem('jd_db_cat_expand')
|
||||
})
|
||||
|
||||
describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
|
||||
it('出厂停在商品目录 Tab;徽标与 Phase 1 聚合同源(根=子树去重和、全部商品=计数行总和)', () => {
|
||||
describe('商品目录 Tab(京东平台类目平铺,2026-11-26)', () => {
|
||||
it('出厂停在商品目录 Tab;「全部商品」徽标=计数行求和;一类目一行平铺(无树层级/无分组头)', () => {
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
const all = catalog.get('.jd-side-all')
|
||||
expect(all.text()).toContain('全部商品')
|
||||
expect(all.text()).toContain('37', '全部商品徽标=5 条计数行求和(7+4+5+9+12)')
|
||||
expect(rowByText(catalog, '服饰内衣').text()).toContain('20',
|
||||
'服饰内衣根徽标=子树去重和(连衣裙7+短袖4+短裤9,短裤跨支同名只记一次)')
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('母婴'))).toBe(false,
|
||||
'零命中一级整支剪掉(2026-11-24:不显示本店没有的类目分支)')
|
||||
expect(rowByText(catalog, '运动户外').text()).toContain('5')
|
||||
|
||||
const rows = catalog.findAll('.jd-side-tree .jd-side-row')
|
||||
expect(rows.map((row) => row.findAll('.jd-side-name').at(0)!.text())).toEqual([
|
||||
'连衣裙',
|
||||
'短袖连衣裙',
|
||||
'艺考形体服',
|
||||
'短裤',
|
||||
'已下架历史类目',
|
||||
], '按后端给的类目名顺序平铺,一行一个末级类目名')
|
||||
expect(rows.map((row) => row.find('.jd-side-count').text())).toEqual(['7', '4', '5', '9', '12'],
|
||||
'每行徽标=该类目的商品数(后端 productCount 原样)')
|
||||
// 平铺形状:没有层级缩进类、没有箭头、没有「授权树外的类目」分组头、没有展开操作行。
|
||||
expect(rows.every((row) => row.classes().includes('depth-0'))).toBe(true)
|
||||
expect(catalog.find('.jd-side-arrow').exists()).toBe(false, '平铺列表没有展开箭头')
|
||||
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '平铺列表没有展开/收起操作行')
|
||||
expect(catalog.text()).not.toContain('授权树外的类目', '不再有树外兜底分组(客户口径:京东分类百分百有)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('一级默认展开(二级首屏可见);逐级展开后末级行点行 emit {name, path}', async () => {
|
||||
it('点类目行 emit {name, path: []}(页面按单名集合 IN 下发);选中态按类目名高亮', async () => {
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
const women = rowByText(catalog, '女装')
|
||||
expect(women.classes()).toContain('depth-1', '一级默认展开 ⇒ 二级行(depth-1 缩进)首屏可见')
|
||||
// 末级艺考形体服在 depth-2:其父(舞蹈体操鞋服/装备)未展开时不可见。
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(false)
|
||||
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
|
||||
await rowByText(catalog, '连衣裙').trigger('click')
|
||||
await flushPromises()
|
||||
const yikao = rowByText(catalog, '艺考形体服')
|
||||
expect(yikao.classes()).toContain('depth-2', '艺考形体服是 level 3(depth 2 缩进)')
|
||||
await yikao.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '艺考形体服', path: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'] }]])
|
||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '连衣裙', path: [] }]],
|
||||
'平铺行不带路径:path 空=单名等值,与本页旧「树外名」同形')
|
||||
|
||||
await wrapper.setProps({ selectedCategory: { name: '短裤', path: [] } })
|
||||
expect(rowByText(catalog, '短裤').classes()).toContain('selected')
|
||||
expect(rowByText(catalog, '连衣裙').classes()).not.toContain('selected')
|
||||
expect(catalog.get('.jd-side-all').classes()).not.toContain('selected', '选了类目就不再是全选态')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('点二级节点 emit 完整路径(页面按子树展开 IN);箭头只折展不选中', async () => {
|
||||
it('「全部商品」行 emit null(页面清类目筛选重查)', async () => {
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
// 女装行未展开时,其子行(连衣裙)不可见。
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false)
|
||||
const women = rowByText(catalog, '女装')
|
||||
await women.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '女装', path: ['服饰内衣', '女装'] }]],
|
||||
'点行=选中即筛,emit 完整名称路径')
|
||||
// 点行顺手展开(下钻感):子行现在可见。
|
||||
expect(wrapper.emitted('select-category')).toHaveLength(1)
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(true,
|
||||
'非末级行点行后展开子级')
|
||||
|
||||
// 箭头(role=button, aria-label)只折展:点它不得触发 select-category。
|
||||
const before = wrapper.emitted('select-category')?.length ?? 0
|
||||
await catalog.get('[aria-label="展开或收起 女装"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')?.length).toBe(before, '箭头点击不选中(click.stop 防冒泡)')
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false,
|
||||
'再点箭头=收起(子行隐藏)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('「全部商品」行 emit null(页面清类目筛选重查);挂载即带选中态时祖先自动展开并高亮', async () => {
|
||||
const wrapper = mountSidebar({ selectedCategory: { name: '连衣裙', path: ['服饰内衣', '女装', '连衣裙'] } })
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
const dress = rowByText(catalog, '连衣裙')
|
||||
expect(dress.classes()).toContain('selected', '外部选中态回显高亮')
|
||||
expect(dress.classes()).toContain('depth-2', '挂载即带选中 ⇒ watch immediate 展开祖先(女装已展开,行可见)')
|
||||
|
||||
await wrapper.setProps({ selectedCategory: null })
|
||||
expect(catalog.get('.jd-side-all').classes()).toContain('selected', 'null=全部商品高亮')
|
||||
await catalog.get('.jd-side-all').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')).toEqual([[null]], '点全部商品=清选')
|
||||
expect(wrapper.emitted('select-category')).toEqual([[null]])
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('全部展开/收起(v1.7 树增强):收起后二级行隐藏、展开后末级行直接可见', async () => {
|
||||
const wrapper = mountSidebar()
|
||||
it('挂载即带选中态:对应行直接高亮(平铺无祖先链,无需自动展开)', () => {
|
||||
const wrapper = mountSidebar({ selectedCategory: { name: '已下架历史类目', path: [] } })
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
await catalog.get('[aria-label="收起全部类目"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('女装'))).toBe(false,
|
||||
'全部收起=一级也收(用户点了就是要收干净)')
|
||||
|
||||
await catalog.get('[aria-label="展开全部类目"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(true,
|
||||
'全部展开=末级行直接可见(一次到底)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('展开态持久化:切换写入 localStorage `jd_db_cat_expand`;全收起存的是空数组(不是抹掉键)', async () => {
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
// 出厂态(一级默认展开)在树根到达时补齐并落盘。
|
||||
const stored1 = JSON.parse(localStorage.getItem('jd_db_cat_expand') || 'null') as string[]
|
||||
expect(Array.isArray(stored1)).toBe(true)
|
||||
expect(stored1.length).toBeGreaterThan(0, '出厂一级展开态被记住')
|
||||
|
||||
await catalog.get('[aria-label="收起全部类目"]').trigger('click')
|
||||
await flushPromises()
|
||||
expect(JSON.parse(localStorage.getItem('jd_db_cat_expand') || '"bad"')).toEqual([],
|
||||
'全收起=空数组记忆(下次挂载不再补一级展开)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('挂载读记忆:预置空数组记忆=出厂不补一级展开(用户上次全收起的意图不被吞)', () => {
|
||||
localStorage.setItem('jd_db_cat_expand', '[]')
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('女装'))).toBe(false,
|
||||
'有记忆(哪怕空)就尊重记忆,不再补一级默认展开')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('挂载读记忆:预置展开记忆=深路径直接展开到位(切页/重进不丢)', () => {
|
||||
localStorage.setItem('jd_db_cat_expand', JSON.stringify(['运动户外', '运动户外/舞蹈体操鞋服/装备']))
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(true,
|
||||
'记忆里的展开键(含多级路径串)直接生效')
|
||||
expect(rowByText(catalog, '已下架历史类目').classes()).toContain('selected')
|
||||
expect(catalog.get('.jd-side-all').classes()).not.toContain('selected')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('树外兜底组(树上对不上的历史行,单名等值出口)', () => {
|
||||
it('兜底组头渲染计数和=extraTotal;行点击 emit {name, path:[]}(页面按单名等值回落)', async () => {
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
const head = catalog.get('.jd-side-extra-head')
|
||||
expect(head.text()).toContain('授权树外的类目', '树有命中时这一组的名字如实点名来处')
|
||||
expect(head.text()).toContain('12', '兜底组头徽标=extraTotal(历史行求和)')
|
||||
const extra = rowByText(catalog, '已下架历史类目')
|
||||
await extra.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '已下架历史类目', path: [] }]],
|
||||
'树外名 path 空数组=无路径序列化(单名等值旧形状,不静默丢筛选)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('全部是树内名时兜底组整体不渲染(不占一条空组)', () => {
|
||||
describe('类目计数未就绪(首帧加载态)', () => {
|
||||
it('未就绪 ⇒ 只留加载行,不画列表(避免空列表先闪一下再跳成有数据)', () => {
|
||||
const wrapper = mount(JdCategorySidebar, {
|
||||
props: {
|
||||
categoryOptions: [{ name: '连衣裙', productCount: 7 }],
|
||||
categoryOptions: CATEGORY_OPTIONS,
|
||||
categories: CATEGORIES,
|
||||
editable: true,
|
||||
selectedCategory: null,
|
||||
selectedGroupId: null,
|
||||
categoriesReady: false,
|
||||
},
|
||||
})
|
||||
expect(wrapper.find('.jd-side-extra').exists()).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('内置授权树与本店不同源(2026-11-24 客户口径:要的是类目树,不是「树外兜底」)', () => {
|
||||
/** 活样本:库里只有家居收纳类目(家居日用数据库店的 474 件),内置树(花屿巷旗舰店的
|
||||
* 服饰授权快照)节点全 0——旧行为照样渲染整棵服饰树(看着像「这家店卖女装」),
|
||||
* 2026-11-23 一轮收成「本店无匹配」一行+全部落「树外兜底」(客户:「正确是一开始
|
||||
* 显示的那棵树,而不是什么树兜底」)。现行口径:零命中分支整支剪掉,树空就把本店
|
||||
* 类目平铺成一级列表——始终是一棵树,不出现别店类目、也不出现退化分组。 */
|
||||
const FOREIGN_OPTIONS: JdProductCategoryOption[] = [
|
||||
{ name: '化妆品收纳盒', productCount: 260 },
|
||||
{ name: '其他收纳架', productCount: 4 },
|
||||
]
|
||||
|
||||
function mountForeign(): VueWrapper<Element> {
|
||||
return mount(JdCategorySidebar, {
|
||||
props: {
|
||||
categoryOptions: FOREIGN_OPTIONS,
|
||||
categories: CATEGORIES,
|
||||
editable: true,
|
||||
selectedCategory: null,
|
||||
selectedGroupId: null,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 树容器的 v-show 态:直接读 inline style(jsdom 的 getComputedStyle 有缓存,
|
||||
* 同一元素二次切换后 isVisible() 仍回旧值——不拿它当判据)。 */
|
||||
function treeDisplay(catalog: VueWrapper<Element>): string {
|
||||
return (catalog.get('.jd-side-tree').element as HTMLElement).style.display
|
||||
}
|
||||
|
||||
it('整树零命中 ⇒ 不渲染别店树,本店类目平铺成一级(无分组头、无「本店无匹配」行)', async () => {
|
||||
const wrapper = mountForeign()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(treeDisplay(catalog)).toBe('none', '别店快照的服饰分支一件商品都没有 ⇒ 整树剪空')
|
||||
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '没有树就不摆展开/收起')
|
||||
expect(catalog.find('.jd-side-extra-head').exists()).toBe(false,
|
||||
'本店类目就是整列内容,不再套「树外兜底」分组头')
|
||||
expect(catalog.text()).not.toContain('服饰内衣', '别店类目一个都不露脸')
|
||||
|
||||
const extra = rowByText(catalog, '化妆品收纳盒')
|
||||
expect(extra.classes()).not.toContain('depth-1', '平铺成本店一级类目(与树行同一层级)')
|
||||
expect(extra.text()).toContain('260')
|
||||
await extra.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '化妆品收纳盒', path: [] }]],
|
||||
'平铺行仍按单名等值出口(path 空数组=无路径序列化)')
|
||||
expect(catalog.text()).toContain('类目加载中…')
|
||||
expect(catalog.find('.jd-side-tree').exists()).toBe(false, '未就绪不画列表')
|
||||
expect(catalog.get('.jd-side-all').text()).toContain('—', '总数未就绪显示占位')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('树内有命中 ⇒ 只渲染命中分支(零命中的一级整支不出现)', () => {
|
||||
const wrapper = mountSidebar()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(treeDisplay(catalog)).not.toBe('none')
|
||||
expect(rowByText(catalog, '服饰内衣').text()).toContain('20')
|
||||
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('母婴'))).toBe(false,
|
||||
'母婴支零命中 ⇒ 剪掉(不拿别店的空类目占屏)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('传服务端真树(家居店):树上就是收纳类目、不同源判据不触发', () => {
|
||||
it('数据到达(就绪)后同一实例切出列表与计数,加载行消失', async () => {
|
||||
const wrapper = mount(JdCategorySidebar, {
|
||||
props: {
|
||||
categoryOptions: FOREIGN_OPTIONS,
|
||||
categories: CATEGORIES,
|
||||
editable: true,
|
||||
selectedCategory: null,
|
||||
selectedGroupId: null,
|
||||
// 2026-11-23:客户端按店铺上报的授权树(形状与内置快照同款)。
|
||||
categoryTree: [
|
||||
{ name: '收纳用品', value: '7001', children: [{ name: '化妆品收纳盒', value: '7002' }] },
|
||||
{ name: '厨房用品', value: '7101', children: [{ name: '其他收纳架', value: '7102' }] },
|
||||
],
|
||||
},
|
||||
})
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(treeDisplay(catalog)).not.toBe('none', '真树直接渲染')
|
||||
expect(rowByText(catalog, '收纳用品').text()).toContain('260', '计数徽标按真树聚合')
|
||||
expect(catalog.find('.jd-side-extra').exists()).toBe(false, '所有类目都挂得上真树,无树外组')
|
||||
expect(catalog.text()).not.toContain('服饰内衣', '内置快照树被服务端真树替换')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('类目计数未就绪(首帧加载态,2026-11-24)', () => {
|
||||
/** 首帧真实形状:/categories 还没回(categoryOptions 空)、页面 loading 投影为 false。
|
||||
* 旧行为会把回落快照整棵树先画出来(徽标全 0、「全部商品 0」),计数到达后再收成
|
||||
* 「本店无匹配」一行——用户看到「原本这样过一会变那样」的闪变。 */
|
||||
function mountLoading(): VueWrapper<Element> {
|
||||
return mount(JdCategorySidebar, {
|
||||
props: {
|
||||
categoryOptions: [],
|
||||
categories: CATEGORIES,
|
||||
@@ -316,29 +153,21 @@ describe('类目计数未就绪(首帧加载态,2026-11-24)', () => {
|
||||
categoriesReady: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
it('未就绪 ⇒ 只留加载行,不先把内置快照整棵树画出来', () => {
|
||||
const wrapper = mountLoading()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(catalog.get('.jd-side-loading').text()).toContain('加载中')
|
||||
// 树容器 v-show 收起(jsdom 的 text() 仍含隐藏子树,判据只认 inline display)。
|
||||
expect((catalog.get('.jd-side-tree').element as HTMLElement).style.display).toBe('none',
|
||||
'首帧不得闪出别店快照树')
|
||||
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '加载态不摆展开/收起')
|
||||
expect(catalog.find('.jd-side-extra').exists()).toBe(false, '加载态不摆兜底组')
|
||||
expect(catalog.get('.jd-side-all').text()).toContain('—', '总数未知时不冒充 0')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('数据到达(就绪)后同一实例切出树与计数,加载行消失', async () => {
|
||||
const wrapper = mountLoading()
|
||||
await wrapper.setProps({ categoryOptions: CATEGORY_OPTIONS, categoriesReady: true })
|
||||
await flushPromises()
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(catalog.find('.jd-side-loading').exists()).toBe(false)
|
||||
expect(catalog.get('.jd-side-all').text()).toContain('37')
|
||||
expect((catalog.get('.jd-side-tree').element as HTMLElement).style.display).not.toBe('none')
|
||||
expect(catalog.text()).toContain('服饰内衣')
|
||||
expect(catalog.findAll('.jd-side-tree .jd-side-row')).toHaveLength(5)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('计数为空(从未采集过)⇒ 空态一句话,不是空白列表', () => {
|
||||
const wrapper = mount(JdCategorySidebar, {
|
||||
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
|
||||
})
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(catalog.get('.jd-side-empty').text()).toContain('还没有采集到类目数据')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -404,13 +233,13 @@ describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () =>
|
||||
const writable = mount(JdCategorySidebar, {
|
||||
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
|
||||
})
|
||||
expect(writable.get('.jd-side-empty').text()).toBe('本组暂无分类,先新建一个')
|
||||
expect(writable.get('.jd-side-custom').get('.jd-side-empty').text()).toBe('本组暂无分类,先新建一个')
|
||||
writable.unmount()
|
||||
|
||||
const readonly = mount(JdCategorySidebar, {
|
||||
props: { categoryOptions: [], categories: [], editable: false, selectedCategory: null, selectedGroupId: null },
|
||||
})
|
||||
expect(readonly.get('.jd-side-empty').text()).toBe('本组暂无分类')
|
||||
expect(readonly.get('.jd-side-custom').get('.jd-side-empty').text()).toBe('本组暂无分类')
|
||||
readonly.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -57,14 +57,8 @@ const groupApi = vi.hoisted(() => ({
|
||||
createShopGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
// 京麦授权类目树(V215 真树)读取:默认空回执=页面回落内置快照;真树用例显式变形。
|
||||
const shopTreeApi = vi.hoisted(() => ({
|
||||
fetchJdShopCategoryTree: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
|
||||
vi.mock('@/pages/jd/jd-shop-category-api.ts', () => shopTreeApi)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
function item(id: number, over: Record<string, unknown> = {}) {
|
||||
@@ -114,9 +108,8 @@ function singleGroupScope(editable = true) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 类目计数夹具:与侧栏组件 mount 测试同源(树内连衣裙支+树外历史名),
|
||||
* 树内路径以 jd-category-tree 真树为准:连衣裙=服饰内衣/女装/连衣裙、
|
||||
* 艺考形体服=运动户外/舞蹈体操鞋服/装备/艺考形体服。 */
|
||||
/** 类目计数夹具:与侧栏组件 mount 测试同源。2026-11-26 起左栏商品目录=后端
|
||||
* `/categories` 的 `category_path` 平铺(末级类目名+商品数),不再有类目树/路径。 */
|
||||
const CATEGORY_OPTIONS = [
|
||||
{ name: '连衣裙', productCount: 7 },
|
||||
{ name: '艺考形体服', productCount: 5 },
|
||||
@@ -136,8 +129,6 @@ beforeEach(() => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||
// 真树默认「服务端还没人上报过」=页面回落内置快照(旧用例形状逐字不变)。
|
||||
shopTreeApi.fetchJdShopCategoryTree.mockResolvedValue({ nodes: [], shops: [] })
|
||||
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
|
||||
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
|
||||
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
||||
@@ -328,49 +319,24 @@ describe('布局:筛选行+工具栏上移顶部通栏(2026-11-21 用户
|
||||
})
|
||||
})
|
||||
|
||||
describe('侧栏商品目录(类目筛选迁移自级联面板)', () => {
|
||||
it('授权类目树逐级下钻:一级行点行=选中即查(path 下发),末级点行单名/路径口径与级联面板等价', async () => {
|
||||
describe('侧栏商品目录(京东平台类目平铺,2026-11-26)', () => {
|
||||
it('类目行点选=末级类目名等值下发(category+path 空),「全部商品」清选重查', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith()
|
||||
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
// 一级默认展开:二级「女装」首屏可见(侧栏与级联面板的关键差异——非末级也能直接选)。
|
||||
const women = sideRowBy(catalog, '女装')
|
||||
expect(women.classes()).toContain('depth-1')
|
||||
// 一类目一行平铺:末级类目名直接点,不再有「一级/二级下钻」与展开箭头。
|
||||
expect(catalog.find('.jd-side-arrow').exists()).toBe(false, '平铺列表没有展开箭头')
|
||||
expect(catalog.findAll('.jd-side-tree .jd-side-row').length).toBeGreaterThan(0)
|
||||
|
||||
// 点二级=选中即查(2026-11-18 客户口径「没办法选择一级跟二级类目」的侧栏形状)。
|
||||
await women.trigger('click')
|
||||
await flushPromises()
|
||||
let last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({ category: '女装', categoryPath: ['服饰内衣', '女装'], page: 1 },
|
||||
'一级/二级点行=带完整路径下发(序列化按子树展开 IN)')
|
||||
|
||||
// 展开到末级再点末级:艺考形体服(运动户外支)。
|
||||
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
|
||||
await flushPromises()
|
||||
await sideRowBy(catalog, '艺考形体服').trigger('click')
|
||||
await flushPromises()
|
||||
last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({
|
||||
category: '艺考形体服',
|
||||
categoryPath: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'],
|
||||
page: 1,
|
||||
}, '末级点行带完整名称路径(同名跨支靠路径区分)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('树外类目组(已落库但京麦树里没有的历史名):点行单名等值下发;「全部商品」行清选重查', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
// 授权树外的本店历史行收在单独一组(path 空数组=页面按无路径序列化单名等值)。
|
||||
const extra = catalog.get('.jd-side-extra')
|
||||
expect(extra.text()).toContain('授权树外的类目')
|
||||
await extra.findAll('.jd-side-row').find((row) => row.text().includes('已下架历史类目'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '已下架历史类目', categoryPath: [] })
|
||||
const leaf = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(leaf).toMatchObject({ category: '艺考形体服', page: 1 },
|
||||
'末级类目名等值过滤(后端 category_path IN 单元素集合)')
|
||||
expect('categoryPath' in leaf, '父级路径这一层已退役:api 入参不再有 categoryPath').toBe(false)
|
||||
expect('categoryNames' in leaf, '子树展开集合同样退役:入参不再有 categoryNames').toBe(false)
|
||||
|
||||
// 点「全部商品」行=清选重查(category 回空、query 层不下发,回第一页)。
|
||||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||
@@ -378,44 +344,30 @@ describe('侧栏商品目录(类目筛选迁移自级联面板)', () => {
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].categoryPath).toEqual([],
|
||||
'清选后路径回空数组(api 序列化层对空 category 不下发参数)')
|
||||
expect('categoryPath' in jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('服务端真树≠内置快照:点父级必须把按真树展开的 categoryNames 透传给列表查询(2026-11-25「收纳用品 81 点开 0 条」断链钉)', async () => {
|
||||
// 真树=家居日用店授权树(收纳用品/收纳盒/收纳篮/收纳架),内置快照(花屿巷服饰)
|
||||
// 里一个都没有——旧断链形状:页面算好集合但 api 入参丢字段,序列化退回快照展开
|
||||
// 失败 → 单名等值 IN('收纳用品') → 库里只有叶子名 → 0 条。
|
||||
shopTreeApi.fetchJdShopCategoryTree.mockResolvedValue({
|
||||
nodes: [{
|
||||
name: '收纳用品', value: '9001',
|
||||
children: [
|
||||
{ name: '收纳盒', value: '9002' },
|
||||
{ name: '收纳篮', value: '9003' },
|
||||
{ name: '收纳架', value: '9004' },
|
||||
],
|
||||
}],
|
||||
shops: [{ shopId: '228346061', shopName: '家居日用数据库店', capturedAt: '2026-11-24 10:00:00', nodeCount: 4 }],
|
||||
})
|
||||
it('2026-11-26:商品目录只读京东平台类目,页面不再取授权类目树(/jd-shop-category-tree)', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||
{ name: '收纳盒', productCount: 23 },
|
||||
{ name: '收纳篮', productCount: 14 },
|
||||
{ name: '收纳架', productCount: 44 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||
|
||||
// 客户口径「京东分类是百分百有的,京东内分类就不需要」:左栏直接是 category_path
|
||||
// 平铺,不再有按店铺上报的授权树、也不再有内置花屿巷快照/树外兜底分组。
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
// 徽标同源(真树聚合):父级 81=23+14+44,这条一直是对的,错的是过滤链。
|
||||
expect(sideRowBy(catalog, '收纳用品').text()).toContain('81')
|
||||
expect(sideRowBy(catalog, '收纳盒').text()).toContain('23')
|
||||
expect(catalog.text()).not.toContain('授权树外的类目')
|
||||
expect(catalog.text()).not.toContain('本店无匹配')
|
||||
|
||||
await sideRowBy(catalog, '收纳用品').trigger('click')
|
||||
await sideRowBy(catalog, '收纳盒').trigger('click')
|
||||
await flushPromises()
|
||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({ category: '收纳用品', categoryPath: ['收纳用品'], page: 1 })
|
||||
expect(last.categoryNames, '断链修复点:页面按真树展开的子树名集合必须进 api 入参').toBeDefined()
|
||||
expect([...last.categoryNames].sort()).toEqual(['收纳架', '收纳盒', '收纳篮', '收纳用品'].sort(),
|
||||
'集合=节点自身+全部后代(与徽标计数同一棵树算出)')
|
||||
expect(last).toMatchObject({ category: '收纳盒', page: 1 })
|
||||
expect('categoryNames' in last, '不再有「页面按树展开的集合」这层:平铺行单名等值').toBe(false)
|
||||
expect('categoryPath' in last, '也不再传类目路径').toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user