feat(jd): 列表列对齐+主图投影+SKU 矩阵+删除链收口(B101/B102 服务端与后管)
This commit is contained in:
@@ -23,13 +23,17 @@ const jdApi = vi.hoisted(() => ({
|
||||
fetchJdProductList: vi.fn(),
|
||||
fetchJdProductDetail: vi.fn(),
|
||||
exportJdProductList: vi.fn(),
|
||||
deleteJdProducts: vi.fn(),
|
||||
fetchJdProductGroups: vi.fn(),
|
||||
createJdProductGroup: vi.fn(),
|
||||
updateJdProductGroup: vi.fn(),
|
||||
deleteJdProductGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
function item(id: number, over: Record<string, unknown> = {}) {
|
||||
return {
|
||||
@@ -38,6 +42,9 @@ function item(id: number, over: Record<string, unknown> = {}) {
|
||||
shopName: '旗舰自营店',
|
||||
productCode: `JD-100${id}`,
|
||||
skuId: `SKU-${id}`,
|
||||
itemNum: `ITEM-${id}`,
|
||||
skuCount: 12,
|
||||
healthScore: 81,
|
||||
title: '304不锈钢保温杯大容量便携',
|
||||
brand: '锅宝',
|
||||
categoryPath: '家居 > 厨具 > 保温杯',
|
||||
@@ -46,7 +53,9 @@ function item(id: number, over: Record<string, unknown> = {}) {
|
||||
stockTotal: 500,
|
||||
saleStatus: '上架中',
|
||||
listTab: 'search',
|
||||
jdUpdatedAt: '2026-11-10 08:30:00',
|
||||
jdCreatedAt: '2026-11-07 18:49:47',
|
||||
jdOnlineAt: '2026-11-12 15:03:37',
|
||||
jdUpdatedAt: '2026-11-13 14:06:07',
|
||||
mainImageUrl: `https://img.example/main-${id}.jpg`,
|
||||
attrCount: 6,
|
||||
imageCount: 9,
|
||||
@@ -66,6 +75,7 @@ beforeEach(() => {
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
confirmMock.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
@@ -88,26 +98,43 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.find('.jd-summary').text()).toContain('共 42 条京东商品')
|
||||
})
|
||||
|
||||
it('行内容=主图/店铺/商品编码/标题/品牌/价格区间/库存/状态/分组/京东更新时间/同步时间(11 列)', async () => {
|
||||
it('行内容与京麦后台列对齐:勾选/主图/标题/编码/货号/类目/品牌/信息分/SKU数/店铺/库存/价格/上架时间/状态/创建/修改/分组/同步(18 列)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const cells = wrapper.findAll('tbody tr')[0].findAll('td')
|
||||
expect(cells).toHaveLength(11)
|
||||
expect(cells[1].text()).toBe('旗舰自营店')
|
||||
expect(cells[2].text()).toBe('JD-1001')
|
||||
expect(cells[3].text()).toContain('304不锈钢保温杯')
|
||||
expect(cells[4].text()).toBe('锅宝')
|
||||
expect(cells[5].text()).toBe('12.90 ~ 15.90', '价格区间=min ~ max')
|
||||
expect(cells[6].text()).toBe('500')
|
||||
expect(cells[7].text()).toBe('上架中')
|
||||
expect(cells[8].text()).toBe('甲组')
|
||||
expect(cells[9].text()).not.toBe('-', '京东更新时间格式化展示')
|
||||
expect(cells[10].text()).not.toBe('-', '同步时间格式化展示')
|
||||
expect(cells).toHaveLength(18)
|
||||
expect(cells[0].find('input[type="checkbox"]').exists()).toBe(true, '第 1 列是勾选框')
|
||||
expect(cells[1].find('.jd-thumb').exists()).toBe(true, '第 2 列是主图')
|
||||
expect(cells[2].text()).toContain('304不锈钢保温杯')
|
||||
expect(cells[3].text()).toBe('JD-1001')
|
||||
expect(cells[4].text()).toBe('ITEM-1', '货号列=京麦后台「货号」')
|
||||
expect(cells[5].text()).toBe('家居 > 厨具 > 保温杯')
|
||||
expect(cells[6].text()).toBe('锅宝')
|
||||
expect(cells[7].text()).toBe('81', '信息分列')
|
||||
expect(cells[8].text()).toBe('12', 'SKU 数列')
|
||||
expect(cells[9].text()).toBe('旗舰自营店')
|
||||
expect(cells[10].text()).toBe('500', '总库存列')
|
||||
expect(cells[11].text()).toBe('12.90 ~ 15.90', '价格区间=min ~ max')
|
||||
expect(cells[12].text()).not.toBe('-', '上架时间格式化展示')
|
||||
expect(cells[13].text()).toBe('上架中')
|
||||
expect(cells[14].text()).not.toBe('-', '创建时间格式化展示')
|
||||
expect(cells[15].text()).not.toBe('-', '修改时间格式化展示')
|
||||
expect(cells[16].text()).toBe('甲组')
|
||||
expect(cells[17].text()).not.toBe('-', '同步时间格式化展示')
|
||||
expect(wrapper.find('.jd-thumb').exists()).toBe(true, '主图列渲染缩略图')
|
||||
})
|
||||
|
||||
it('主图列:有自有桶 URL 才出图,没有就显示「无图」(不拿京东原图域名顶)', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [item(1), item(2, { mainImageUrl: '' })], total: 2, page: 1, pageSize: 20,
|
||||
})
|
||||
const rowTexts = wrapper.findAll('tbody tr').map((tr) => tr.text())
|
||||
expect(wrapper.findAll('.jd-thumb')).toHaveLength(1)
|
||||
expect(rowTexts[1]).toContain('无图')
|
||||
})
|
||||
|
||||
it('分组读不到的那行展示「未分组」(不猜名字)', 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')[8].text()).toBe('未分组')
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[16].text()).toBe('未分组')
|
||||
})
|
||||
|
||||
it('筛选生效:店铺/编码/关键字/状态/分组/起止日期,查询回第一页重发', async () => {
|
||||
@@ -242,6 +269,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
item: item(1),
|
||||
attrGroups: [{ groupName: '规格', attrs: [{ key: 'capacity', label: '容量', value: '500ml' }] }],
|
||||
images: [{ imageType: 'MAIN', attrName: '', sortNo: 1, url: 'https://img.example/main-1.jpg', byteSize: null, width: 800, height: 800 }],
|
||||
skus: [],
|
||||
attrJsonRaw: '',
|
||||
}),
|
||||
)
|
||||
@@ -260,6 +288,113 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('容量')
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('500ml')
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('主图')
|
||||
const drawerText = wrapper.find('.drawer-mask').text()
|
||||
expect(drawerText).toContain('货号')
|
||||
expect(drawerText).toContain('ITEM-1')
|
||||
expect(drawerText).toContain('信息分')
|
||||
expect(drawerText).toContain('上架时间')
|
||||
})
|
||||
|
||||
it('详情抽屉的销售属性=京麦那 12 行 SKU 矩阵:颜色/尺码两列维度 + 京东价 + 库存 + skuId', async () => {
|
||||
const skuRows = [
|
||||
{ skuId: '10238877506570', skuName: '花屿巷… 上衣 S', skuSeq: '1', price: 162, stock: 200, sortNo: 0,
|
||||
saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'S' }] },
|
||||
{ skuId: '10238877506574', skuName: '花屿巷… 上衣 M', skuSeq: '2', price: 168, stock: 150, sortNo: 1,
|
||||
saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'M' }] },
|
||||
{ skuId: '10238877506580', skuName: '花屿巷… 半裙 S', skuSeq: '3', price: 162, stock: 80, sortNo: 2,
|
||||
saleAttrs: [{ name: '颜色', value: '半裙' }, { name: '尺码', value: 'S' }] },
|
||||
]
|
||||
jdApi.fetchJdProductDetail.mockImplementation(() =>
|
||||
Promise.resolve({
|
||||
item: item(1),
|
||||
attrGroups: [],
|
||||
images: [],
|
||||
skus: skuRows,
|
||||
attrJsonRaw: '',
|
||||
}),
|
||||
)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody tr')[0].trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('销售属性 / SKU 矩阵')
|
||||
const headers = wrapper.findAll('.sku-table thead th').map((th) => th.text())
|
||||
expect(headers).toEqual(['序号', '颜色', '尺码', '京东价', '库存', 'SKU ID', 'SKU 名称'],
|
||||
'维度列从各 SKU 的 saleAttrs 派生(京麦「颜色/尺码」两列)')
|
||||
|
||||
const rows = wrapper.findAll('.sku-table tbody tr')
|
||||
expect(rows).toHaveLength(3, '12 行矩阵按入库行数渲染')
|
||||
const first = rows[0].findAll('td').map((td) => td.text())
|
||||
expect(first).toEqual(['1', '上衣', 'S', '¥162', '200', '10238877506570', '花屿巷… 上衣 S'])
|
||||
expect(rows[1].findAll('td').map((td) => td.text())[3]).toBe('¥168', '每行自己的京东价')
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('3 个 SKU')
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('库存 430', '汇总=各行库存之和')
|
||||
})
|
||||
|
||||
it('旧行没有 SKU 矩阵时给可解释的空态(不渲染空表、不静默吞)', async () => {
|
||||
jdApi.fetchJdProductDetail.mockImplementation(() =>
|
||||
Promise.resolve({ item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '' }),
|
||||
)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody tr')[0].trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.find('.sku-table').exists()).toBe(false)
|
||||
expect(wrapper.find('.drawer-mask').text()).toContain('暂无 SKU 矩阵')
|
||||
})
|
||||
|
||||
it('删除:勾选两行点删除 → 二次确认点名数量与桶清理 → 批量端点带 (ids, companyId),成功后刷新并清勾选', async () => {
|
||||
jdApi.deleteJdProducts.mockResolvedValue({ deleted: 2, imagesDeleted: 18, objectsDeleted: 16, objectsKept: 2, objectsSkipped: 0 })
|
||||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 20 })
|
||||
|
||||
const boxes = wrapper.findAll('tbody input[type="checkbox"]')
|
||||
await boxes[0].setValue(true)
|
||||
await boxes[1].setValue(true)
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '勾选后工具栏出「删除勾选」')
|
||||
await wrapper.find('.jd-delete-btn').trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
const options = confirmMock.mock.calls[0][0]
|
||||
expect(options.title).toBe('删除京东商品')
|
||||
expect(options.message).toContain('确定删除勾选的 2 个商品吗')
|
||||
expect(options.message).toContain('jd-products 桶内图片文件一并删除', '确认弹窗必须点名「桶文件也会删」')
|
||||
expect(options.danger).toBe(true)
|
||||
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(1)
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1, 2], 1)
|
||||
expect(document.body.textContent).toContain('已删除 2 个商品')
|
||||
expect(document.body.textContent).toContain('2 个共用图片保留', '共用对象计数要透出到反馈')
|
||||
// 成功后重取列表并清勾选:工具栏按钮消失。
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1)
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('删除:确认弹窗点取消就不发请求(防误删的第一道闸)', async () => {
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await wrapper.find('.jd-delete-btn').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
expect(jdApi.deleteJdProducts).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('删除失败把后端「本次未删除任何数据」文案弹出来(整批拒绝的语义必须到界面)', async () => {
|
||||
jdApi.deleteJdProducts.mockRejectedValue(new Error('桶内对象删除失败,本次未删除任何数据(jd-products/5/a.jpg):oss 5xx'))
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
|
||||
await wrapper.find('.jd-delete-btn').trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(document.body.textContent).toContain('本次未删除任何数据')
|
||||
// 失败后勾选保留,用户可重试。
|
||||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('管理分组弹窗:打开即拉分组列表,变更后刷新分组下拉与列表', async () => {
|
||||
|
||||
Reference in New Issue
Block a user