10dec12ec0
用户端 frontend-vue: - jd-publish-shop.ts:shopLabel 只出店名(缺名兜底「店铺 N」),跨店/多店琥珀文案压成一两句,判据逻辑零改动 - JdPublishTab:删工具头/分类解释/品牌句后半,默认店铺/选品/collect-hint/中断回执/加价规则各压一句 - JdCollectTab:删工具头 desc、分类机制句、断点游标行,「页面筛选未生效兜底翻页中」从任务卡撤下 - jd-on-shelf 空态一句、JdConsolePage hero-sub 整段删(含过时的「正在建设中」) - 品牌 10 个 tab:输入/筛选/加载长句压一句或删,任务卡删「结果ID/店铺ID/平台」技术行(店名已显形) - 保留:错误出口、额度「当前在架X/Y」、GROUPS_EMPTY 空态动作句、检测按钮与店铺显形 后管 admin-frontend-vue: - 每页顶部「当前页面操作提示」条整条下线(删 OperationGuide.vue+operation-guides.ts) - 撞款/任务中心/关键词用量/密钥用量/客户端包/教程/软件版本/数字人/菜单/店铺密钥/登录页逐页删说明小字(保留:踢线警示、「留空=永不过期」、「不要带v前缀」、「仅支持.zip」、草稿需手动发布、已授权人数、安全提示) - 编辑/建号弹窗 label 括号收短;代理弹窗/设备日志(删 pywebview/kk-browser 进程名)/密钥 pill title/授权弹窗 dim/品牌门控空态收短 测试同步(16 支改反钉或同步断言,全部当场绿): - align-operation-guide 整份重写为反钉(组件与文案表不得回流) - source-pin 台账 task-center-board 条目手工点名 7/3/5→24/14/28:旧值是切分器把正则字面量内裸引号当字符串开关吞掉 18 支用例的误量(stripNonCode 不识别 regex literal),本次改写恰好移除该文件最后两处带引号正则后测出真值;真实用例数反而 25→24(删 1 支 guide 用例),非真实增长 门禁:后管 node --test 1965/1965+vitest 253/253+vue-tsc rc=0;用户端 node 1150/mount 149/vue-tsc rc=0;ops 快检 --fast overall=pass(后端9.5/后管8.8/客户端9.8/用户端9.6)。本窗不发版;app_client/jar/后端零改动。
141 lines
4.9 KiB
TypeScript
141 lines
4.9 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-25 额度改口径):余量读数、展开取数、
|
||
* 标记已下架走确认框两臂+成功回执+重取列表。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
|
||
}
|
||
|
||
it('默认收起不取数;展开后拉第一页并显余量读数', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
const w = await mountPanel()
|
||
expect(api.onShelf).not.toHaveBeenCalled()
|
||
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
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.findAll('.on-shelf-row')).toHaveLength(2)
|
||
expect(w.text()).toContain('收纳盒A')
|
||
})
|
||
|
||
it('不限档显「不限」,绝不显「/0」坏数', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] }))
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
expect(w.text()).toContain('当前在架 0/不限')
|
||
expect(w.text()).not.toContain('/0')
|
||
expect(w.text()).toContain('当前没有已上架商品')
|
||
})
|
||
|
||
it('额度到顶出琥珀提醒句', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 }))
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
expect(w.find('.on-shelf-warn').text()).toContain('额度已满')
|
||
expect(w.find('.on-shelf-warn').text()).toContain('标记已下架')
|
||
})
|
||
|
||
it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockResolvedValue(true)
|
||
api.markDelisted.mockResolvedValue(null)
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
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(2)
|
||
})
|
||
|
||
it('确认框取消(reject 臂)不发起标记', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockRejectedValue('cancel')
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
await w.findAll('.on-shelf-mark')[1].trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(api.markDelisted).not.toHaveBeenCalled()
|
||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||
})
|
||
|
||
it('标记失败透出服务端原文(跨团队 403 等)', async () => {
|
||
api.onShelf.mockResolvedValue(pageVo())
|
||
api.confirm.mockResolvedValue(true)
|
||
api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品'))
|
||
const w = await mountPanel()
|
||
await w.get('.on-shelf-toggle').trigger('click')
|
||
await flushPromises()
|
||
|
||
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('本团队')
|
||
})
|