This commit is contained in:
2026-08-12 18:50:03 +08:00
parent 41a131a33b
commit 2c5f53ec00
29 changed files with 513 additions and 283 deletions
+10 -3
View File
@@ -7,6 +7,9 @@ import { ElMessageBox } from 'element-plus'
import { useAuthStore } from '@/core/auth/auth'
import AppLayout from './AppLayout.vue'
const { getUnreadCount } = vi.hoisted(() => ({ getUnreadCount: vi.fn() }))
vi.mock('@/modules/notifications/api/notificationCenter', () => ({ getUnreadCount }))
const CachedPage = defineComponent({
setup() {
const count = ref(0)
@@ -26,31 +29,35 @@ async function mountLayout(path = '/') {
const auth = useAuthStore()
auth.token = 'token'
auth.user = { id: '1', name: '平台管理员', account: 'admin', roles: ['PLATFORM_ADMIN'] }
auth.permissions = ['platform:warehouse:list']
auth.permissions = ['platform:warehouse:list', 'platform:notification:view']
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/', name: 'home', component: { template: '<p>page</p>' }, 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: '<p>warehouses</p>' }, meta: { title: '仓库管理', requiresAuth: true } },
{ path: '/notifications/mine', name: 'my-notifications', component: { template: '<p>messages</p>' }, meta: { title: '我的消息', requiresAuth: true } },
{ path: '/login', component: { template: '<p>login</p>' } },
],
})
await router.push(path)
await router.isReady()
const wrapper = mount(AppLayout, {
global: { plugins: [pinia, router], stubs: { AdminSidebarMenu: { template: '<nav />' }, WorkspaceTabs: { template: '<div class="workspace-tabs-stub" />' }, 'el-button': { emits: ['click'], template: '<button @click="$emit(\'click\')"><slot /></button>' } } },
global: { plugins: [pinia, router], stubs: { AdminSidebarMenu: { template: '<nav />' }, WorkspaceTabs: { template: '<div class="workspace-tabs-stub" />' }, 'el-dropdown': { template: '<div><slot /><slot name="dropdown" /></div>' }, 'el-dropdown-menu': { template: '<div><slot /></div>' }, 'el-dropdown-item': { emits: ['click'], template: '<button @click="$emit(\'click\')"><slot /></button>' }, 'el-button': { emits: ['click'], template: '<button @click="$emit(\'click\')"><slot /></button>' } } },
})
return { wrapper, router }
}
describe('AppLayout', () => {
beforeEach(() => vi.mocked(ElMessageBox.confirm).mockReset())
beforeEach(() => { vi.mocked(ElMessageBox.confirm).mockReset(); getUnreadCount.mockReset().mockResolvedValue(4) })
it('shows the authenticated identity without a role preview switcher', async () => {
const { wrapper } = await mountLayout()
expect(wrapper.text()).toContain('登录身份:平台管理员(admin)')
expect(wrapper.text()).not.toContain('权限预览')
await flushPromises()
expect(wrapper.get('[aria-label="消息中心,4 条未读"]').attributes('disabled')).toBeUndefined()
expect(wrapper.get('.notification-count').text()).toBe('4')
})
it('hides the shell heading when the route opts out', async () => {