import { createPinia, setActivePinia } from 'pinia' import { flushPromises, mount } from '@vue/test-utils' import { defineComponent, ref } from 'vue' import { createMemoryHistory, createRouter } from 'vue-router' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { ElMessageBox } from 'element-plus' import { useAuthStore } from '@/core/auth/auth' import AppLayout from './AppLayout.vue' const CachedPage = defineComponent({ setup() { const count = ref(0) return { count } }, template: '', }) vi.mock('element-plus', async (importOriginal) => { const actual = await importOriginal() return { ...actual, ElMessage: { warning: vi.fn(), error: vi.fn() }, ElMessageBox: { confirm: vi.fn() } } }) async function mountLayout(path = '/') { const pinia = createPinia() setActivePinia(pinia) const auth = useAuthStore() auth.token = 'token' auth.user = { id: '1', name: '平台管理员', account: 'admin', roles: ['PLATFORM_ADMIN'] } auth.permissions = ['platform:warehouse:list', 'platform:notification:task:list', 'platform:notification:template:list'] const router = createRouter({ history: createMemoryHistory(), routes: [ { path: '/', name: 'home', component: { template: '

page

' }, meta: { requiresAuth: true, workspaceTab: false, keepAlive: false } }, { path: '/customers', name: 'customers', component: CachedPage, meta: { title: '客户管理', showPageHeading: false, requiresAuth: true } }, { path: '/warehouses', name: 'warehouses', component: { template: '

warehouses

' }, meta: { title: '仓库管理', requiresAuth: true } }, { path: '/login', component: { template: '

login

' } }, ], }) await router.push(path) await router.isReady() const wrapper = mount(AppLayout, { global: { plugins: [pinia, router], stubs: { AdminSidebarMenu: { template: '