feat(后管): 京东数据库商品目录恢复一级/二级/末级层级树(2026-11-26 晚客户口径「怎么都没有分类一级二级分类」「管理员要分类时候那么多怎么看」)
- 新纯函数 jd-category-hierarchy.ts:京麦授权类目真树(GET /api/jd-shop-category-tree, 按平台 node_id 并集)× /categories 末级名计数,名称精确等值挂接;计数按去重名字集合 求和(同名跨支不重复计)、零计数分支剪枝、树外历史名进「平台树外」兜底组; 树空=退化末级平铺(上一窗行为逐字相同),没有内置快照——第二份树不再存在 - 新 jd-shop-category-api.ts:只剩服务端真树一条路,失败/空静默回空数组 - 侧栏层级渲染:展开/收起、点父级=整棵子树末级名集合过滤(11-18 口径恢复)、 挂载即展开选中行祖先链;同名跨支按路径核选中态 - filter/api:categoryPath(只喂回显展开)+categoryNames(选中那一刻展开好的过滤集合) 复活,下发走后端既有 category IN 多值;清选时两者一起清,不留幽灵谓词 - 判据:jd-category-hierarchy.test.ts(挂接/去重/剪枝/兜底/平铺退化)+ sidebar/database-page mount(真树层级、父级点选下发集合、树空平铺、回显展开)
This commit is contained in:
@@ -57,7 +57,14 @@ const groupApi = vi.hoisted(() => ({
|
||||
createShopGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
/** 授权类目树 API(2026-11-26 恢复层级:页面取 `GET /api/jd-shop-category-tree`)。
|
||||
* 必须 mock——不 mock 就真发请求(jsdom 里静默失败 ⇒ 树恒空 ⇒ 层级用例假绿)。 */
|
||||
const treeApi = vi.hoisted(() => ({
|
||||
fetchJdShopCategoryTree: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||
vi.mock('@/pages/jd/jd-shop-category-api.ts', () => treeApi)
|
||||
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
@@ -129,6 +136,9 @@ beforeEach(() => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||
// 授权类目树:默认「还没上报过」(树空 ⇒ 侧栏退化为末级平铺,保持既有用例的行集不变);
|
||||
// 层级用例显式给树。
|
||||
treeApi.fetchJdShopCategoryTree.mockResolvedValue({ nodes: [], shops: [] })
|
||||
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
|
||||
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
|
||||
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
||||
@@ -319,55 +329,77 @@ describe('布局:筛选行+工具栏上移顶部通栏(2026-11-21 用户
|
||||
})
|
||||
})
|
||||
|
||||
describe('侧栏商品目录(京东平台类目平铺,2026-11-26)', () => {
|
||||
it('类目行点选=末级类目名等值下发(category+path 空),「全部商品」清选重查', async () => {
|
||||
/** 授权树夹具(2026-11-26 恢复层级):与 CATEGORY_OPTIONS 同源,父级徽标=子树命中行数。 */
|
||||
const CATEGORY_TREE = [
|
||||
{
|
||||
name: '服饰内衣',
|
||||
value: '1',
|
||||
children: [
|
||||
{
|
||||
name: '女装',
|
||||
value: '11',
|
||||
children: [
|
||||
{ name: '连衣裙', value: '111' },
|
||||
{ name: '艺考形体服', value: '112' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
describe('侧栏商品目录(京东平台类目层级树,2026-11-26)', () => {
|
||||
it('页面取授权树画一级/二级;点一级=整棵子树名字集合下发(父级也能选来批量分类)', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
||||
treeApi.fetchJdShopCategoryTree.mockResolvedValue({ nodes: CATEGORY_TREE, shops: [] })
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith()
|
||||
expect(treeApi.fetchJdShopCategoryTree).toHaveBeenCalled()
|
||||
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
// 一类目一行平铺:末级类目名直接点,不再有「一级/二级下钻」与展开箭头。
|
||||
expect(catalog.find('.jd-side-arrow').exists()).toBe(false, '平铺列表没有展开箭头')
|
||||
expect(catalog.findAll('.jd-side-tree .jd-side-row').length).toBeGreaterThan(0)
|
||||
// 默认收起:只露一级(「服饰内衣」),但有展开箭头;末级要展开才出来。
|
||||
expect(catalog.find('.jd-side-arrow').exists()).toBe(true, '有下级的一级行带展开箭头')
|
||||
expect(sideRowBy(catalog, '服饰内衣').find('.jd-side-count').text()).toBe('12',
|
||||
'一级徽标=子树命中行数(连衣裙 7+艺考形体服 5)')
|
||||
expect(catalog.text()).toContain('平台树外', '「已下架历史类目」不在树里 ⇒ 进兜底组')
|
||||
|
||||
await sideRowBy(catalog, '艺考形体服').trigger('click')
|
||||
await sideRowBy(catalog, '服饰内衣').trigger('click')
|
||||
await flushPromises()
|
||||
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)
|
||||
const parent = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(parent).toMatchObject({ category: '服饰内衣', page: 1 },
|
||||
'父级点选:category 存回显名')
|
||||
expect(parent.categoryNames).toEqual(['服饰内衣', '女装', '连衣裙', '艺考形体服'],
|
||||
'整棵子树的节点名集合(后端 category_path IN 多值)')
|
||||
expect(parent.categoryPath).toEqual(['服饰内衣'], '路径只供侧栏展开回显,不参与过滤')
|
||||
|
||||
// 点「全部商品」行=清选重查(category 回空、query 层不下发,回第一页)。
|
||||
// 点「全部商品」行=清选重查(名字与集合一起清干净,不留幽灵谓词)。
|
||||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||
await catalog.get('.jd-side-all').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||||
expect('categoryPath' in jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toBe(false)
|
||||
const cleared = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(cleared.category).toBe('')
|
||||
expect(cleared.categoryNames).toEqual([])
|
||||
expect(cleared.categoryPath).toEqual([])
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('2026-11-26:商品目录只读京东平台类目,页面不再取授权类目树(/jd-shop-category-tree)', async () => {
|
||||
it('点末级行=单名集合;树未上报(空树)时退化为末级平铺(上一窗行为不变)', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||
{ name: '收纳盒', productCount: 23 },
|
||||
{ name: '收纳篮', productCount: 14 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||||
|
||||
// 客户口径「京东分类是百分百有的,京东内分类就不需要」:左栏直接是 category_path
|
||||
// 平铺,不再有按店铺上报的授权树、也不再有内置花屿巷快照/树外兜底分组。
|
||||
// 默认 beforeEach 给的是空树:没有层级,一行一个末级名,点行=单名额。
|
||||
const catalog = wrapper.get('.jd-side-catalog')
|
||||
expect(catalog.find('.jd-side-arrow').exists()).toBe(false, '没有树就没有展开箭头')
|
||||
expect(sideRowBy(catalog, '收纳盒').text()).toContain('23')
|
||||
expect(catalog.text()).not.toContain('授权树外的类目')
|
||||
expect(catalog.text()).not.toContain('本店无匹配')
|
||||
|
||||
await sideRowBy(catalog, '收纳盒').trigger('click')
|
||||
await flushPromises()
|
||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({ category: '收纳盒', page: 1 })
|
||||
expect('categoryNames' in last, '不再有「页面按树展开的集合」这层:平铺行单名等值').toBe(false)
|
||||
expect('categoryPath' in last, '也不再传类目路径').toBe(false)
|
||||
expect(last.categoryNames).toEqual(['收纳盒'], '平铺行按单名集合下发(与父级同一参数面)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user