Files
crawler-plugin/frontend-vue/tests/mount/jd-console-pending-menu.mount.test.ts
T
huangzd1997 36e110d27c feat(jd): 首页一级入口「京东」+工作台两菜单,获取店铺数据一键采集带进度条
首页在亚马逊/视频右侧新增「京东」一级入口(恒显示),落地页 /jd-console 按亚马逊控制台样式做两张工具卡:获取店铺数据(可用)、商品上架(占位,点开只提示「暂未开通」)。

获取店铺数据改成一键:建单 → 推 jd-shop-collect-run 到本机队列 → 轮询服务端进度。进度只读两处真源——任务行状态 + scope 行合并写游标里的 itemsReceived/cursor.total(客户端抓列表第一页时把 total 写进游标),没有分母就退回不定态动画,不编造百分比;终态即停轮询。后端新增 GET /api/jd-collect/tasks/{taskId}/progress(按 taskId+userId 校归属)。

判据:JdCollectProgressQueryTest(5)、jd-console-tool-catalog.test.ts(5)、jd-console-pending-menu.mount(3)、jd-collect-progress.mount(6);catch 棘轮 blocks 314→315 按名登记(轮询 catch 非静默)。
2026-11-14 16:50:06 +08:00

68 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 京东工作台挂载用例(v1.5):首页「京东」进来后是两个菜单。
*
* 三件事一起判,缺一条就是假绿:
* ① 两个菜单名都在 DOM 里(获取店铺数据 / 商品上架);
* ② 获取店铺数据是「可用」卡片(有 href → router-link 分支,文案是「打开工具」);
* ③ 商品上架是「假菜单」:没有 href,点开只弹一句「暂未开通」,不发任何请求。
*
* 跑法:cd frontend-vue && npx vitest run(tests/mount/** 由 vitest.config.ts 收)。
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { mount, type VueWrapper } from '@vue/test-utils'
import JdConsolePage from '@/pages/jd/JdConsolePage.vue'
let wrapper: VueWrapper | null = null
function mountConsole() {
wrapper = mount(JdConsolePage, {
global: {
stubs: {
NotificationBell: true,
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
},
},
})
return wrapper
}
describe('京东工作台两个菜单', () => {
beforeEach(() => {
window.localStorage.setItem('username', 'admin')
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
window.localStorage.clear()
})
it('两个菜单名都渲染出来', () => {
const w = mountConsole()
const text = w.text()
expect(text).toContain('获取店铺数据')
expect(text).toContain('商品上架')
expect(w.findAll('.tool-card').length).toBe(2)
})
it('获取店铺数据是可用卡片,商品上架是占位(暂未开通)', () => {
const w = mountConsole()
const cards = w.findAll('.tool-card')
expect(cards[0].classes()).not.toContain('tool-card--pending')
expect(cards[0].text()).toContain('打开工具')
expect(cards[1].classes()).toContain('tool-card--pending')
expect(cards[1].text()).toContain('暂未开通')
})
it('点假菜单只弹提示,不跳转', async () => {
const w = mountConsole()
const pending = w.findAll('.tool-card')[1]
await pending.trigger('click')
const toast = w.find('.toast')
expect(toast.text()).toContain('商品上架暂未开通')
expect(toast.classes()).toContain('show')
})
})