fix(admin-jd): 别店快照类目树不再冒充本店——整树零命中时收树并点名

- jdCategoryCountTree 增 treeMatched(树内任一节点 count>0);侧栏据此判「内置授权树
  与本店不同源」:JD_CATEGORY_TREE 是 2026-11-16 从花屿巷旗舰店抓的固定快照,
  家居日用店打开时整树 0 命中、商品全落树外兜底,旧行为让界面看着像这家店卖女装。
- 整树零命中 ⇒ 树默认收起成一行「授权类目树(本店无匹配)」、点开给一句固定快照说明;
  兜底行照旧单名等值可选(筛选不因收树失效);树内有命中时渲染与判据都不变。
- 判据:jd-category-tree.test.ts +1(treeMatched 三态)、mount +3(收起/点开/不误伤);
  反向验证关掉判据=2 红。后管 node --test 1977 绿、vitest 250 绿、vue-tsc rc=0;
  源码钉子基线只动本笔 cases 14→15(pins/reads 不变)。
- 可读性基线逐条点名:JdCategorySidebar.vue 846→890 行(本笔 +44,树消歧模板/文案/CSS)。
This commit is contained in:
2026-11-23 20:35:24 +08:00
parent 2a194d3340
commit c64dbfd8d1
5 changed files with 153 additions and 6 deletions
@@ -244,6 +244,33 @@ test('计数聚合——脏值归一:空名跳过、非有限/负数归 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 非空才判「不同源」,
// 否则加载中会闪一下「本店无匹配」。
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)