70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
/**
|
||
* 京东工作台挂载用例(v1.5):首页「京东」进来后是两个菜单。
|
||
*
|
||
* 三件事一起判,缺一条就是假绿:
|
||
* ① 两个菜单名都在 DOM 里(获取店铺数据 / 商品上架);
|
||
* ② 两张卡都是「可用」卡片(有 href → router-link 分支,文案是「打开工具」);
|
||
* ③ 商品上架卡(v1.5 Phase 4 由占位转正式)的 router-link 指向 /jd-publish。
|
||
*
|
||
* 历史锁(2026-11-17):本文件原本钉「商品上架是假菜单(tool-card--pending,点开只弹
|
||
* 暂未开通)」;占位随 Phase 4 转正式后这两条断言翻转为可用卡形状,假菜单分支在
|
||
* JdConsolePage 保留为通用防御(后续新工具再用)。
|
||
*
|
||
* 跑法: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: { props: ['to'], template: '<a class="router-link-stub" :data-to="to"><slot /></a>' },
|
||
'router-link': { props: ['to'], template: '<a class="router-link-stub" :data-to="to"><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()).not.toContain('tool-card--pending')
|
||
expect(cards[1].text()).toContain('打开工具')
|
||
})
|
||
|
||
it('商品上架卡的 router-link 指向 /jd-publish(占位已转正式)', () => {
|
||
const w = mountConsole()
|
||
const links = w.findAll('a.router-link-stub').map((a) => a.attributes('data-to'))
|
||
expect(links).toContain('/jd-collect')
|
||
expect(links).toContain('/jd-publish')
|
||
})
|
||
})
|