feat(jd-database): v1.7 侧栏店铺名单——分类下挂店铺、点店铺过滤、行内改名/移除、添加店铺弹窗

This commit is contained in:
2026-11-21 16:45:28 +08:00
parent 6685491fcb
commit 08b1f3f7f8
6 changed files with 1247 additions and 21 deletions
@@ -29,20 +29,29 @@ const CATEGORIES: JdProductGroup[] = [
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
]
/** 店铺名单夹具(v1.7 F6):裙装带两名单店,裤装无名单(无箭头)。 */
const CATEGORIES_WITH_SHOPS: JdProductGroup[] = [
{ id: 7, name: '裙装', ownerGroupId: 11, sortOrder: 0, productCount: 3, shops: ['绿屿街道店', '花屿巷旗舰店'] },
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
]
interface MountOptions {
editable?: boolean
selectedCategory?: { name: string; path: string[] } | null
selectedGroupId?: number | null
selectedShopName?: string | null
categories?: JdProductGroup[]
}
function mountSidebar(options: MountOptions = {}): VueWrapper<Element> {
return mount(JdCategorySidebar, {
props: {
categoryOptions: CATEGORY_OPTIONS,
categories: CATEGORIES,
categories: options.categories ?? CATEGORIES,
editable: options.editable ?? true,
selectedCategory: options.selectedCategory ?? null,
selectedGroupId: options.selectedGroupId ?? null,
selectedShopName: options.selectedShopName ?? null,
},
})
}
@@ -231,3 +240,164 @@ describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () =>
readonly.unmount()
})
})
/** 店铺名单(v1.7 F6 完整对齐原型《商品数据商城》):分类行展开箭头→店铺行(点选过滤/
* 行内改名移除)+「+ 添加店铺」入口+分类行 hover 改名/删除。侧栏纯展示:全部只 emit,
* API 调用与刷新在页面。 */
describe('店铺名单(v1.7:分类下挂店铺名单)', () => {
async function openCustomTab(wrapper: VueWrapper<Element>): Promise<void> {
const tabs = wrapper.findAll('.jd-sidebar-tab')
await tabs[1]!.trigger('click')
await flushPromises()
}
it('有名单的分类行出展开箭头(无名单不出);出厂收起,点箭头展开店铺行+添加店铺入口,再点收起', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').exists()).toBe(true, '有名单出箭头')
expect(custom.find('[aria-label="展开或收起 裤装 的店铺名单"]').exists()).toBe(false, '无名单不出箭头')
expect(custom.findAll('.jd-side-shop')).toHaveLength(0, '出厂收起(店铺行不可见)')
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
const shops = custom.findAll('.jd-side-shop')
expect(shops).toHaveLength(2, '展开后店铺行可见(服务端升序原样渲染)')
expect(shops[0]!.text()).toContain('绿屿街道店')
expect(shops[1]!.text()).toContain('花屿巷旗舰店')
expect(custom.get('.jd-side-shop-add').text()).toContain('+ 添加店铺', '可写档名单尾出添加入口')
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')).toHaveLength(0, '再点箭头=收起')
wrapper.unmount()
})
it('点店铺行 emit {groupId, shopName} 成对下发;选中回流高亮;再点已选 emit null(只清店铺保留分类)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7 })
await openCustomTab(wrapper)
await wrapper.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
const shopRow = wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!
await shopRow.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-shop')).toEqual([[{ groupId: 7, shopName: '绿屿街道店' }]],
'点店铺=分类+店铺成对(页面发 group_id+shop_name 精确过滤)')
await wrapper.setProps({ selectedShopName: '绿屿街道店' })
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!.classes()).toContain('selected', '选中回流高亮')
await wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-shop')?.at(-1)).toEqual([null], '再点已选=清店铺筛选(分类保留)')
wrapper.unmount()
})
it('页面带着店铺筛选挂载:宿主分类自动展开(店铺行可见,不用再点箭头)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7, selectedShopName: '花屿巷旗舰店' })
await openCustomTab(wrapper)
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')).toHaveLength(2,
'watch immediate 展开宿主分类')
const selected = wrapper.get('.jd-side-custom').findAll('.jd-side-shop').find((row) => row.text().includes('花屿巷旗舰店'))
expect(selected!.classes()).toContain('selected')
wrapper.unmount()
})
it('可写档:分类行与店铺行 hover 出改名/删除操作钮;分类行内改名 Enter 提交 emit (cat, 新名)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.get('[aria-label="改名分类 裙装"]').exists()).toBe(true)
expect(custom.get('[aria-label="删除分类 裙装"]').exists()).toBe(true)
// 分类行内改名:点 ✎ → 行替换成编辑输入(预填原名)→ Enter 提交。
await custom.get('[aria-label="改名分类 裙装"]').trigger('click')
await flushPromises()
const editInput = custom.get('[aria-label="修改分类名称(原:裙装)"]')
expect((editInput.element as HTMLInputElement).value).toBe('裙装', '编辑形态预填原名')
await editInput.setValue('长裙')
await editInput.trigger('keyup.enter')
await flushPromises()
expect(wrapper.emitted('rename-category')).toEqual([[CATEGORIES_WITH_SHOPS[0], '长裙']],
'侧栏只 emit(API 调用与刷新在页面)')
// 空名/未改动不 emit(静默收编辑态)。
await custom.get('[aria-label="改名分类 裙装"]').trigger('click')
await flushPromises()
const unchanged = custom.get('[aria-label="修改分类名称(原:裙装)"]')
await unchanged.setValue(' 裙装 ')
await unchanged.trigger('keyup.enter')
await flushPromises()
expect(wrapper.emitted('rename-category')).toHaveLength(1, '未改动不白发请求')
// 店铺行 hover 操作钮在展开后可见。
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
expect(custom.get('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(true)
expect(custom.get('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(true)
wrapper.unmount()
})
it('店铺行内改名 emit (cat, oldName, newName);移除 emit (cat, shopName);添加店铺入口 emit (cat)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
// 店铺改名:✎ → 预填 → 改名 → ✓ 提交。
await custom.get('[aria-label="改名店铺 绿屿街道店"]').trigger('click')
await flushPromises()
const shopEdit = custom.get('[aria-label="修改店铺名称(原:绿屿街道店)"]')
expect((shopEdit.element as HTMLInputElement).value).toBe('绿屿街道店')
await shopEdit.setValue('绿屿新址店')
await custom.get('[aria-label="确认改名店铺 绿屿街道店"]').trigger('click')
await flushPromises()
expect(wrapper.emitted('rename-shop')).toEqual([[CATEGORIES_WITH_SHOPS[0], '绿屿街道店', '绿屿新址店']])
// 移除:hover ✕ 直接 emit(可重做,不设二次确认)。
await custom.get('[aria-label="移除店铺 花屿巷旗舰店"]').trigger('click')
await flushPromises()
expect(wrapper.emitted('remove-shop')).toEqual([[CATEGORIES_WITH_SHOPS[0], '花屿巷旗舰店']])
// 添加店铺入口。
await custom.get('.jd-side-shop-add').trigger('click')
await flushPromises()
expect(wrapper.emitted('add-shops')).toEqual([[CATEGORIES_WITH_SHOPS[0]]])
wrapper.unmount()
})
it('只读档:无 hover 操作钮、无添加店铺入口;店铺行仍可见可点(读面 V203)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, editable: false })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.find('[aria-label="改名分类 裙装"]').exists()).toBe(false, '分类行无改名钮')
expect(custom.find('[aria-label="删除分类 裙装"]').exists()).toBe(false, '分类行无删除钮')
await custom.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
expect(custom.findAll('.jd-side-shop')).toHaveLength(2, '店铺行照常可见(读面)')
expect(custom.find('.jd-side-shop-add').exists()).toBe(false, '只读档无添加店铺入口')
expect(custom.find('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(false, '店铺行无改名钮')
expect(custom.find('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(false, '店铺行无移除钮')
await custom.findAll('.jd-side-shop')[0]!.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-shop')).toEqual([[{ groupId: 7, shopName: '绿屿街道店' }]],
'只读档点店铺照常过滤')
wrapper.unmount()
})
it('分类行仍是 toggle 选中(点行 emit id/再点 null),店铺行高亮不改变分类行选中判定', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7 })
await openCustomTab(wrapper)
await wrapper.get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
expect(rowByText(wrapper, '裙装').classes()).toContain('selected', '分类行选中(含选店铺时)')
await rowByText(wrapper, '裙装').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-group')).toEqual([[null]], '再点已选分类=清选(页面同清店铺筛选)')
wrapper.unmount()
})
})
@@ -43,6 +43,12 @@ const jdApi = vi.hoisted(() => ({
deleteJdProductGroup: vi.fn(),
updateJdProduct: vi.fn(),
batchAssignJdProductGroup: vi.fn(),
// v1.7 店铺名单(V214):侧栏名单交互与添加店铺弹窗的 API 面。
removeJdGroupShop: vi.fn(),
renameJdGroupShop: vi.fn(),
fetchJdGroupShops: vi.fn(),
addJdGroupShops: vi.fn(),
fetchJdAvailableShops: vi.fn(),
}))
const confirmMock = vi.hoisted(() => vi.fn())
@@ -112,7 +118,7 @@ const CATEGORY_OPTIONS = [
]
const GROUPS = [
{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3 },
{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3, shops: ['绿屿街道店', '花屿巷旗舰店'] },
{ id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 },
]
@@ -124,6 +130,11 @@ beforeEach(() => {
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
jdApi.fetchJdProductGroups.mockResolvedValue([])
jdApi.fetchJdProductCategories.mockResolvedValue([])
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
jdApi.fetchJdAvailableShops.mockResolvedValue([])
jdApi.addJdGroupShops.mockResolvedValue(0)
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
confirmMock.mockResolvedValue(true)
})
@@ -1375,3 +1386,147 @@ describe('首屏作用域同源与静默降级(Phase 0 黄金测试)', () =>
wrapper.unmount()
})
})
/** 店铺名单接线(v1.7 F6,2026-11-21 拍板「完整对齐」):侧栏点店铺行→列表按
* group_id+shop_name 成对过滤;行内改名/移除与分类行删除走对应 API;添加店铺弹窗
* 开合与批量提交。API 全部 mock(端点形状在 jd-product-api 与后端 controller 对撞)。 */
describe('店铺名单接线(v1.7:点店铺过滤+名单维护+添加店铺弹窗)', () => {
/** 挂载带名单的页面并展开裙装的名单。 */
async function mountWithShops(): Promise<VueWrapper<Element>> {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSideTab(wrapper, '店铺分类')
await sideCustom(wrapper).get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
return wrapper
}
function shopRows(wrapper: VueWrapper<Element>) {
return sideCustom(wrapper).findAll('.jd-side-shop')
}
it('点店铺行 → 列表按 (groupId, shopName) 成对过滤回第一页;回显条出店铺芯片;再点已选=清店铺保留分类', async () => {
const wrapper = await mountWithShops()
await shopRows(wrapper)[0]!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject(
{ groupId: '7', shopName: '绿屿街道店', page: 1 },
'点店铺=该分类归属 ∩ 该店铺(精确 eq,后端 SQL 谓词)')
expect(wrapper.get('.jd-filter-chips').text()).toContain('店铺:绿屿街道店', '回显条带店铺芯片')
await shopRows(wrapper)[0]!.trigger('click')
await flushPromises()
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last.shopName).toBe('', '再点已选=清店铺筛选')
expect(last.groupId).toBe('7', '分类选中保留(每层独立 toggle)')
wrapper.unmount()
})
it('分类行内删除:二次确认(点名只解挂归属)→ deleteJdProductGroup → 停在该分类的筛选清空并重取', async () => {
const wrapper = await mountWithShops()
await shopRows(wrapper)[0]!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7' })
await sideCustom(wrapper).get('[aria-label="删除分类 裙装"]').trigger('click')
await flushPromises()
await flushPromises()
const options = confirmMock.mock.calls.at(-1)![0]
expect(options.title).toBe('删除分类')
expect(options.message).toContain('商品本身保留在公共库', '确认弹窗点名删除语义(只解挂归属)')
expect(options.danger).toBe(true)
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ groupId: '', shopName: '' }, '停在该分类(含店铺行)的筛选随删除清空')
wrapper.unmount()
})
it('店铺行内改名:renameJdGroupShop 三参提交并刷新名单;筛选正停在该店时筛选词同步成新名', async () => {
const wrapper = await mountWithShops()
await shopRows(wrapper)[0]!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].shopName).toBe('绿屿街道店')
const custom = sideCustom(wrapper)
await custom.get('[aria-label="改名店铺 绿屿街道店"]').trigger('click')
await flushPromises()
await custom.get('[aria-label="修改店铺名称(原:绿屿街道店)"]').setValue('绿屿新址店')
await custom.get('[aria-label="确认改名店铺 绿屿街道店"]').trigger('click')
await flushPromises()
await flushPromises()
expect(jdApi.renameJdGroupShop).toHaveBeenCalledWith(7, '绿屿街道店', '绿屿新址店')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].shopName).toBe('绿屿新址店',
'筛选词同步成新名(不然界面按旧店名查,名单里已没有这一行)')
expect(document.body.textContent).toContain('已把店铺「绿屿街道店」改名为「绿屿新址店」')
wrapper.unmount()
})
it('店铺行移除:removeJdGroupShop 提交;筛选正停在该店时清店铺筛选重取(可重做不设确认)', async () => {
const wrapper = await mountWithShops()
await shopRows(wrapper)[0]!.trigger('click')
await flushPromises()
await sideCustom(wrapper).get('[aria-label="移除店铺 绿屿街道店"]').trigger('click')
await flushPromises()
await flushPromises()
expect(jdApi.removeJdGroupShop).toHaveBeenCalledWith(7, '绿屿街道店')
expect(confirmMock).not.toHaveBeenCalledWith(expect.objectContaining({ title: '移除店铺' }),
'移除可重做(再加回名单即可),不设二次确认')
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last.shopName).toBe('', '筛选正停在移除的店上=清店铺筛选')
expect(last.groupId).toBe('7', '分类选中保留')
wrapper.unmount()
})
it('添加店铺弹窗:打开即拉候选(排除本分类已有名单),勾选+手输合并批量提交,done 刷新名单', async () => {
jdApi.fetchJdAvailableShops.mockResolvedValue(['旗舷店', '望江路店'])
jdApi.addJdGroupShops.mockResolvedValue(2)
const wrapper = await mountWithShops()
const custom = sideCustom(wrapper)
const groupsCallsBefore = jdApi.fetchJdProductGroups.mock.calls.length
await custom.get('.jd-side-shop-add').trigger('click')
await flushPromises()
const modal = wrapper.get('.shop-picker-modal')
expect(modal.text()).toContain('添加店铺')
expect(modal.text()).toContain('裙装', '标题带目标分类名')
expect(jdApi.fetchJdAvailableShops).toHaveBeenCalledWith('', 7)
// 勾选一个候选+手输一个自定义项。
await modal.findAll('.shop-candidate-row')[0]!.trigger('click')
await modal.get('[aria-label="自定义店铺名"]').setValue('手输新店')
await modal.findAll('button').find((b) => b.text() === '加入')!.trigger('click')
await flushPromises()
expect(modal.text()).toContain('手输新店', '自定义项进待添加清单')
expect(modal.text()).toContain('添加(2)')
await modal.findAll('button').find((b) => /^添加(2)$/.test(b.text()))!.trigger('click')
await flushPromises()
await flushPromises()
expect(jdApi.addJdGroupShops).toHaveBeenCalledWith(7, ['旗舷店', '手输新店'])
expect(document.body.textContent).toContain('已把 2 个店铺加进「裙装」')
expect(wrapper.find('.shop-picker-modal').exists()).toBe(false, '成功后弹窗自动关闭')
expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(groupsCallsBefore, 'done 刷新名单')
wrapper.unmount()
})
it('普通员工(editable=false):侧栏无名单写入口(无添加店铺/无行内改名移除),点店铺过滤照常', async () => {
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' }
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSideTab(wrapper, '店铺分类')
await sideCustom(wrapper).get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
await flushPromises()
const custom = sideCustom(wrapper)
expect(custom.findAll('.jd-side-shop')).toHaveLength(2, '店铺行照常可见(读面)')
expect(custom.find('.jd-side-shop-add').exists()).toBe(false, '只读档无添加店铺入口')
expect(custom.find('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(false)
await custom.findAll('.jd-side-shop')[0]!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', shopName: '绿屿街道店' },
'只读档点店铺照常过滤')
wrapper.unmount()
})
})