feat(jd): 京东数据库分组改店铺分类+左右分栏弹窗人工归类

This commit is contained in:
2026-11-15 21:46:26 +08:00
parent 91cf5dfaf7
commit e175e85973
18 changed files with 1022 additions and 144 deletions
@@ -1,8 +1,8 @@
/**
* 京东数据库页(v1.4 Phase 5)的挂载契约。
*
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/分组/同步起止 date 对)+
* 查询/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/分类/同步起止 date 对)+
* 查询/重置/店铺分类 + 自绘明细表(点行开详情抽屉)+ OldPagination;
* 公司 tab 切换=清筛选重取(company-tab-wiring 同口径)。
* 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留)。
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
@@ -30,6 +30,7 @@ const jdApi = vi.hoisted(() => ({
updateJdProductGroup: vi.fn(),
deleteJdProductGroup: vi.fn(),
updateJdProduct: vi.fn(),
batchAssignJdProductGroup: vi.fn(),
}))
const confirmMock = vi.hoisted(() => vi.fn())
@@ -214,9 +215,9 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(wrapper.find('.drawer-mask').exists()).toBe(false, '点复制按钮不冒泡开抽屉')
})
it('分组读不到的那行展示「未分组」(不猜名字)', async () => {
it('分类读不到的那行展示「未分类」(不猜名字;2026-11-15「分组管理」改「店铺分类」只换措辞)', async () => {
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
expect(wrapper.findAll('tbody tr')[0].findAll('td')[2].text()).toBe('未分组')
expect(wrapper.findAll('tbody tr')[0].findAll('td')[2].text()).toBe('未分类')
})
it('筛选生效:店铺/编码/关键字/分组/起止日期,查询回第一页重发', async () => {
@@ -259,7 +260,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
const groupSelect = wrapper.find('select')
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
expect(optionTexts).toContain('全部分组')
expect(optionTexts).toContain('全部分类')
expect(optionTexts).toContain('甲组')
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
@@ -471,20 +472,25 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
})
it('管理分组弹窗:打开即拉分组列表,变更后刷新分组下拉与列表', async () => {
it('店铺分类弹窗(原「管理分组」):打开即拉分类列表与右栏商品行集,变更后刷新分类下拉与列表', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
await wrapper.findAll('button').find((b) => b.text() === '管理分组')!.trigger('click')
await wrapper.findAll('button').find((b) => b.text() === '店铺分类')!.trigger('click')
await flushPromises()
await flushPromises()
expect(wrapper.find('.group-modal').exists()).toBe(true)
// 打开弹窗 = 拉一次分组列表(第 2 次:首屏已拉过一次;分组全平台一份、不带公司维度)
expect(wrapper.find('.group-modal').text()).toContain('店铺分类', '弹窗标题改「店铺分类」')
// 打开弹窗 = 拉一次分类列表(第 2 次:首屏已拉过一次;分类全平台一份、不带公司维度)
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith()
// 右栏取数复用 fetchJdProductList:不带公司维度(公共库),默认「全部」范围不带 ungrouped=true。
const dialogCall = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(dialogCall.companyId).toBeNull()
expect(dialogCall.ungrouped).toBe(false)
// 模拟分组管理里删了一个分组:emit changed → 页面刷新分组下拉与列表(回第一页)
// 模拟分类管理里删了一个分类:emit changed → 页面刷新分类下拉与列表(回第一页)
wrapper.findComponent(JdProductGroupDialog).vm.$emit('changed')
await flushPromises()
await flushPromises()
@@ -492,6 +498,66 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, companyId: 1 })
})
it('店铺分类弹窗:左侧点亮分类→勾选商品→「归入所选分类」按(ids, 目标分类 id)调批量归类', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([
{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 },
{ id: 8, name: '乙组', sortOrder: 1, productCount: 0 },
])
jdApi.fetchJdProductList.mockImplementation(() =>
Promise.resolve({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 }))
const wrapper = mount(JdProductGroupDialog, { props: { visible: false }, global: { plugins: [pinia] } })
await wrapper.setProps({ visible: true })
await flushPromises()
await flushPromises()
// 左侧点亮「甲组」=归类目标;只点亮还没勾选时按钮仍置灰(归入=目标+勾选两者齐备)。
const assignBtn = () => wrapper.findAll('button').find((b) => b.text().includes('归入'))
expect(assignBtn()!.attributes('disabled')).toBeDefined()
await wrapper.findAll('.group-row')[0].trigger('click')
await flushPromises()
expect(assignBtn()!.attributes('disabled')).toBeDefined()
expect(assignBtn()!.text()).toContain('甲组', '按钮点名归类目标')
// 勾选两行 → 按钮点亮 → 归入「甲组」。
const boxes = wrapper.findAll('tbody input[type="checkbox"]')
await boxes[0].setValue(true)
await boxes[1].setValue(true)
expect(assignBtn()!.attributes('disabled')).toBeUndefined()
jdApi.batchAssignJdProductGroup.mockResolvedValue(2)
await assignBtn()!.trigger('click')
await flushPromises()
await flushPromises()
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledTimes(1)
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 2], 7)
// 成功后刷新左栏分类数(商品数)与右栏行集,勾选清空。
expect(jdApi.fetchJdProductGroups).toHaveBeenCalled()
expect(wrapper.findAll('tbody input[type="checkbox"]').every((b) => !(b.element as HTMLInputElement).checked).valueOf()).toBe(true)
})
it('店铺分类弹窗:「未分类」页签走 ungrouped=true 取行集;「移出分类」按(ids, null)调批量归类', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
jdApi.fetchJdProductList.mockImplementation(() =>
Promise.resolve({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 }))
const wrapper = mount(JdProductGroupDialog, { props: { visible: false }, global: { plugins: [pinia] } })
await wrapper.setProps({ visible: true })
await flushPromises()
await flushPromises()
const listCallsBefore = jdApi.fetchJdProductList.mock.calls.length
await wrapper.findAll('.scope-tabs button').find((b) => b.text() === '未分类')!.trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(listCallsBefore + 1, '切「未分类」必须立刻重取')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ungrouped: true, companyId: null })
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
await wrapper.findAll('button').find((b) => b.text() === '移出分类')!.trigger('click')
await flushPromises()
await flushPromises()
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null)
})
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径;分组公共不清)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })