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:
@@ -2,7 +2,7 @@
|
||||
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
|
||||
"totals": {
|
||||
"files": 265,
|
||||
"cases": 1859,
|
||||
"cases": 1860,
|
||||
"pins": 463,
|
||||
"reads": 664
|
||||
},
|
||||
@@ -318,7 +318,7 @@
|
||||
"reads": 5
|
||||
},
|
||||
"jd-category-tree.test.ts": {
|
||||
"cases": 14,
|
||||
"cases": 15,
|
||||
"pins": 0,
|
||||
"reads": 0
|
||||
},
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -218,6 +218,70 @@ describe('树外兜底组(树上对不上的历史行,单名等值出口)'
|
||||
})
|
||||
})
|
||||
|
||||
describe('内置授权树与本店不同源(2026-11-23:家居日用店打开服饰快照树)', () => {
|
||||
/** 活样本:库里只有家居收纳类目(家居日用数据库店的 264 件),内置树(花屿巷旗舰店的
|
||||
* 服饰授权快照)节点全 0——旧行为照样渲染整棵服饰树,界面看着像「这家店卖女装」。 */
|
||||
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')
|
||||
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, '收起态不摆展开/收起按钮')
|
||||
const extra = rowByText(catalog, '化妆品收纳盒')
|
||||
await extra.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('select-category')).toEqual([[{ name: '化妆品收纳盒', 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('树内有命中时照旧全树渲染(不同源判据不误伤正常店)', () => {
|
||||
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')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () => {
|
||||
it('点店铺分类切 Tab;分类行带计数;点行 emit id、再点已选中的 emit null(toggle 清选)', async () => {
|
||||
const wrapper = mountSidebar()
|
||||
|
||||
Reference in New Issue
Block a user