2ab740c529
- 面板默认只显「当前在架 N/上限 M」一行,挂载即取数;「展开在架商品」「刷新」两按钮删 - 商品数据与「标记已下架」收进「管理」小入口,点开重取(读数与列表都新鲜),再点收起 - 「标记已下架」保留:它是腾额度的唯一界面出口(京麦人工下架系统感知不到),不能随列表一起删 - 满额琥珀提醒改经 quotaFullWarning 单出口,点名「管理」入口不再提「本列表」 - 判据:纯函数 9 支+mount 8 支全绿(含取数失败透出原文新格);反向验证两向(旧文案回流绊线红/数据默认常驻行为红)当场红逐字节复原 - 台账无涉:catch blocks 仍 339(两支 catch 形状未动)、JdOnShelfPanel 不在可读基线点名册
169 lines
6.2 KiB
TypeScript
169 lines
6.2 KiB
TypeScript
import { beforeEach, expect, it, vi } from 'vitest'
|
||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||
import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue'
|
||
|
||
/**
|
||
* 在架余量面板 mount 判据(2026-11-28 客户口径「只要个统计数,不需要显示上架的数据」):
|
||
* 挂载即取数只显余量读数一行,商品数据与「标记已下架」默认不显、点「管理」才见;
|
||
* 标记已下架走确认框两臂+成功回执+重取列表。api 模块整体 mock——面板必须经
|
||
* fetchJdOnShelf/markJdItemDelisted 出口(裸 URL 回退当场红)。
|
||
*/
|
||
|
||
const api = vi.hoisted(() => ({
|
||
onShelf: vi.fn(),
|
||
markDelisted: vi.fn(),
|
||
confirm: vi.fn(),
|
||
success: vi.fn(),
|
||
error: vi.fn(),
|
||
}))
|
||
|
||
vi.mock('@/shared/api/types/modules/jd-publish', () => ({
|
||
fetchJdOnShelf: api.onShelf,
|
||
markJdItemDelisted: api.markDelisted,
|
||
}))
|
||
vi.mock('element-plus', async (importOriginal) => ({
|
||
...await importOriginal<typeof import('element-plus')>(),
|
||
ElMessage: { success: api.success, error: api.error },
|
||
ElMessageBox: { confirm: api.confirm },
|
||
}))
|
||
|
||
function pageVo(overrides: Record<string, unknown> = {}) {
|
||
return {
|
||
used: 2, limit: 5000, unlimited: false, total: 2,
|
||
items: [
|
||
{ itemId: 100, productId: 7, productCode: '100365361600', title: '收纳盒A', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:30:04' },
|
||
{ itemId: 101, productId: 8, productCode: '100365355826', title: '纸巾盒B', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:21:29' },
|
||
],
|
||
...overrides,
|
||
}
|
||
}
|
||
|
||
let wrapper: VueWrapper | undefined
|
||
|
||
beforeEach(() => {
|
||
vi.clearAllMocks()
|
||
wrapper?.unmount()
|
||
wrapper = undefined
|
||
})
|
||
|
||
async function mountPanel() {
|
||
// 替身注册法与 jd-publish-dispatch.mount.test.ts 同族:分页替身+loading 指令空实现
|
||
wrapper = mount(JdOnShelfPanel, {
|
||
global: {
|
||
stubs: { ElPagination: { emits: ['current-change'], template: '<div />' } },
|
||
directives: { loading: () => undefined },
|
||
},
|
||
})
|
||
await flushPromises()
|
||
return wrapper
|
||
}
|
||
|
||
/** 展开管理小入口(列表唯一入口,2026-11-28 起数据默认不显)。 */
|
||
async function openManage(w: VueWrapper) {
|
||
await w.get('.on-shelf-manage').trigger('click')
|
||
await flushPromises()
|
||
}
|
||
|
||
it('挂载即取数,只显余量读数一行;商品数据默认不显', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
const w = await mountPanel()
|
||
|
||
// 挂载即取数(余量统计数不用等任何点击)
|
||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||
expect(api.onShelf.mock.calls[0][0]).toBe(1)
|
||
expect(api.onShelf.mock.calls[0][1]).toBe(20)
|
||
expect(w.text()).toContain('当前在架 2/5000')
|
||
// 数据展示默认收起:没有商品行,也没有「展开在架商品」这类按钮
|
||
expect(w.find('.on-shelf-row').exists()).toBe(false)
|
||
expect(w.text()).not.toContain('收纳盒A')
|
||
expect(w.find('.on-shelf-manage').text()).toBe('管理')
|
||
})
|
||
|
||
it('不限档显「不限」,绝不显「/0」坏数;空态在管理里显一句', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] }))
|
||
const w = await mountPanel()
|
||
expect(w.text()).toContain('当前在架 0/不限')
|
||
expect(w.text()).not.toContain('/0')
|
||
|
||
await openManage(w)
|
||
expect(w.text()).toContain('当前没有已上架商品')
|
||
})
|
||
|
||
it('点「管理」才显商品数据与标记按钮;再点收起', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
const w = await mountPanel()
|
||
|
||
await openManage(w)
|
||
// 点开管理重取一遍(读数与列表都新鲜)
|
||
expect(api.onShelf).toHaveBeenCalledTimes(2)
|
||
expect(w.findAll('.on-shelf-row')).toHaveLength(2)
|
||
expect(w.text()).toContain('收纳盒A')
|
||
expect(w.find('.on-shelf-manage').text()).toBe('收起')
|
||
|
||
await w.get('.on-shelf-manage').trigger('click')
|
||
await flushPromises()
|
||
expect(w.find('.on-shelf-row').exists()).toBe(false)
|
||
})
|
||
|
||
it('额度到顶出琥珀提醒句,点名「管理」入口', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 }))
|
||
const w = await mountPanel()
|
||
expect(w.find('.on-shelf-warn').text()).toContain('额度已满')
|
||
expect(w.find('.on-shelf-warn').text()).toContain('「管理」')
|
||
expect(w.find('.on-shelf-warn').text()).toContain('标记已下架')
|
||
})
|
||
|
||
it('取数失败透出错误原文,余量读数不留旧数也不显坏数', async () => {
|
||
api.onShelf.mockRejectedValue(new Error('服务暂时不可用'))
|
||
const w = await mountPanel()
|
||
await flushPromises()
|
||
|
||
expect(api.error).toHaveBeenCalledTimes(1)
|
||
expect(String(api.error.mock.calls[0][0])).toContain('服务暂时不可用')
|
||
expect(w.text()).toContain('余量读取中…')
|
||
expect(w.text()).not.toContain('当前在架')
|
||
})
|
||
|
||
it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockResolvedValue(true)
|
||
api.markDelisted.mockResolvedValue(null)
|
||
const w = await mountPanel()
|
||
await openManage(w)
|
||
|
||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.markDelisted).toHaveBeenCalledWith(100, true)
|
||
expect(api.success).toHaveBeenCalledTimes(1)
|
||
expect(String(api.success.mock.calls[0][0])).toContain('100365361600')
|
||
// 标记成功后重取(腾额度读数当场回跳)
|
||
expect(api.onShelf).toHaveBeenCalledTimes(3)
|
||
})
|
||
|
||
it('确认框取消(reject 臂)不发起标记', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockRejectedValue('cancel')
|
||
const w = await mountPanel()
|
||
await openManage(w)
|
||
|
||
await w.findAll('.on-shelf-mark')[1].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.markDelisted).not.toHaveBeenCalled()
|
||
})
|
||
|
||
it('标记失败透出服务端原文(跨团队 403 等)', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockResolvedValue(true)
|
||
api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品'))
|
||
const w = await mountPanel()
|
||
await openManage(w)
|
||
|
||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.error).toHaveBeenCalledTimes(1)
|
||
expect(String(api.error.mock.calls[0][0])).toContain('本团队')
|
||
})
|