/** * 京东工作台挂载用例(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: '' }, 'router-link': { template: '' }, }, }, }) 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') }) })