feat(admin-jd): 商品目录只渲染本店有商品的类目分支(去掉「树外兜底」退化解)

客户口径:「正确是一开始显示的那棵树,而不是什么树兜底」。授权树里零命中的分
支整支剪掉:

- 本店商品名挂得上树(花屿巷旗舰店)⇒ 只显示命中分支,别店的空类目不再占屏;
- 树与本店不同源(家居日用店看别店快照)⇒ 整树剪空,本店类目名平铺成一级列表,
  不再出现「授权类目树(本店无匹配)」行 + 说明框,也不再出现「树外兜底」分组;
- 树有命中时,挂不上树的本店历史名仍收在一组(改名「授权树外的类目」)。

- 纯函数 jdCategoryPruneZero(零命中整支剪掉、重算 leaf)
- 一级默认展开改挂剪枝后的根(空根不置位,等真根到达再补)
- 判据:jd-category-tree.test.ts +3(剪枝三态)、侧栏 mount 改写(平铺/剪支/真树)、
  page mount 组名同步;source-pin 台账按文件点名 17→20
- 后管 node --test 1982 绿、vitest 252 绿、vue-tsc rc=0,快检四面绿
This commit is contained in:
2026-11-24 13:50:53 +08:00
parent 10fb52d0e9
commit 0591d6ee6d
8 changed files with 129 additions and 107 deletions
@@ -77,7 +77,8 @@ describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
expect(all.text()).toContain('37', '全部商品徽标=5 条计数行求和(7+4+5+9+12)')
expect(rowByText(catalog, '服饰内衣').text()).toContain('20',
'服饰内衣根徽标=子树去重和(连衣裙7+短袖4+短裤9,短裤跨支同名只记一次)')
expect(rowByText(catalog, '母婴').text()).toContain('0', '无词条一级归 0 不缺节点')
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('母婴'))).toBe(false,
'零命中一级整支剪掉(2026-11-24:不显示本店没有的类目分支)')
expect(rowByText(catalog, '运动户外').text()).toContain('5')
wrapper.unmount()
})
@@ -193,7 +194,7 @@ describe('树外兜底组(树上对不上的历史行,单名等值出口)'
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('授权树外的类目', '树有命中时这一组的名字如实点名来处')
expect(head.text()).toContain('12', '兜底组头徽标=extraTotal(历史行求和)')
const extra = rowByText(catalog, '已下架历史类目')
await extra.trigger('click')
@@ -218,9 +219,12 @@ describe('树外兜底组(树上对不上的历史行,单名等值出口)'
})
})
describe('内置授权树与本店不同源(2026-11-23:家居日用店打开服饰快照树)', () => {
/** 活样本:库里只有家居收纳类目(家居日用数据库店的 264 件),内置树(花屿巷旗舰店的
* 服饰授权快照)节点全 0——旧行为照样渲染整棵服饰树,界面看着像「这家店卖女装」。 */
describe('内置授权树与本店不同源(2026-11-24 客户口径:要的是类目树,不是「树外兜底」)', () => {
/** 活样本:库里只有家居收纳类目(家居日用数据库店的 474 件),内置树(花屿巷旗舰店的
* 服饰授权快照)节点全 0——旧行为照样渲染整棵服饰树(看着像「这家店卖女装」),
* 2026-11-23 一轮收成「本店无匹配」一行+全部落「树外兜底」(客户:「正确是一开始
* 显示的那棵树,而不是什么树兜底」)。现行口径:零命中分支整支剪掉,树空就把本店
* 类目平铺成一级列表——始终是一棵树,不出现别店类目、也不出现退化分组。 */
const FOREIGN_OPTIONS: JdProductCategoryOption[] = [
{ name: '化妆品收纳盒', productCount: 260 },
{ name: '其他收纳架', productCount: 4 },
@@ -244,44 +248,36 @@ describe('内置授权树与本店不同源(2026-11-23:家居日用店打开
return (catalog.get('.jd-side-tree').element as HTMLElement).style.display
}
it('整树零命中 ⇒ 树默认收起、只留一行「本店无匹配」,兜底行仍可选', async () => {
it('整树零命中 ⇒ 不渲染别店树,本店类目平铺成一级(无分组头、无「本店无匹配」行)', async () => {
const wrapper = mountForeign()
const catalog = wrapper.get('.jd-side-catalog')
const head = catalog.get('.jd-side-foreign-head')
expect(head.text()).toContain('本店无匹配', '点名「这棵树不适用本店」,不让人以为本店有服饰类目')
expect(treeDisplay(catalog)).toBe('none', '整棵树收起(别店快照不冒充本店类目)')
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(false, '收起态不摆展开/收起按钮')
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 空数组=无路径序列化)')
wrapper.unmount()
})
it('点说明行 ⇒ 展开原树与提示文案;再点收起', async () => {
const wrapper = mountForeign()
const catalog = wrapper.get('.jd-side-catalog')
await catalog.get('.jd-side-foreign-head').trigger('click')
await flushPromises()
expect(treeDisplay(catalog)).not.toBe('none', '点开仍可查原树形状(只读参考)')
expect(catalog.get('.jd-side-foreign-tip').text()).toContain('固定快照')
expect(catalog.find('.jd-side-tree-ops').exists()).toBe(true, '点开后恢复展开/收起操作')
await catalog.get('.jd-side-foreign-head').trigger('click')
await flushPromises()
expect(treeDisplay(catalog)).toBe('none')
wrapper.unmount()
})
it('树内有命中时照旧全树渲染(不同源判据不误伤正常店)', () => {
it('树内有命中 ⇒ 只渲染命中分支(零命中的一级整支不出现)', () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
expect(catalog.find('.jd-side-foreign-head').exists()).toBe(false)
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('传服务端真树(家居店):树上就是收纳类目、不同源判据不触发', () => {
const wrapper = mount(JdCategorySidebar, {
props: {
categoryOptions: FOREIGN_OPTIONS,
@@ -297,11 +293,9 @@ describe('内置授权树与本店不同源(2026-11-23:家居日用店打开
},
})
const catalog = wrapper.get('.jd-side-catalog')
expect(catalog.find('.jd-side-foreign-head').exists()).toBe(false,
'真树有命中 ⇒ 不再点名「本店无匹配」')
expect(treeDisplay(catalog)).not.toBe('none', '真树直接渲染,不收起')
expect(treeDisplay(catalog)).not.toBe('none', '真树直接渲染')
expect(rowByText(catalog, '收纳用品').text()).toContain('260', '计数徽标按真树聚合')
expect(catalog.find('.jd-side-extra').exists()).toBe(false, '所有类目都挂得上真树,兜底组不占位')
expect(catalog.find('.jd-side-extra').exists()).toBe(false, '所有类目都挂得上真树,无树外组')
expect(catalog.text()).not.toContain('服饰内衣', '内置快照树被服务端真树替换')
wrapper.unmount()
})