优化
This commit is contained in:
@@ -2,7 +2,7 @@ import { createPinia, setActivePinia } from 'pinia'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { defineComponent, ref } from 'vue'
|
||||
import { createMemoryHistory, createRouter } from 'vue-router'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
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'
|
||||
@@ -44,8 +44,53 @@ async function mountLayout(path = '/') {
|
||||
return { wrapper, router }
|
||||
}
|
||||
|
||||
function mockViewport(isMobile: boolean) {
|
||||
const mediaQuery = {
|
||||
matches: isMobile,
|
||||
media: '(max-width: 720px)',
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
} as unknown as MediaQueryList
|
||||
vi.stubGlobal('matchMedia', vi.fn(() => mediaQuery))
|
||||
}
|
||||
|
||||
describe('AppLayout', () => {
|
||||
beforeEach(() => { vi.mocked(ElMessageBox.confirm).mockReset() })
|
||||
beforeEach(() => {
|
||||
vi.mocked(ElMessageBox.confirm).mockReset()
|
||||
mockViewport(false)
|
||||
})
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
it('reports the desktop navigation expanded and collapsed states', async () => {
|
||||
const { wrapper } = await mountLayout()
|
||||
const menuButton = wrapper.get('.shell-menu-button')
|
||||
|
||||
expect(menuButton.attributes('aria-label')).toBe('收起导航')
|
||||
expect(menuButton.attributes('aria-expanded')).toBe('true')
|
||||
|
||||
await menuButton.trigger('click')
|
||||
|
||||
expect(menuButton.attributes('aria-label')).toBe('展开导航')
|
||||
expect(menuButton.attributes('aria-expanded')).toBe('false')
|
||||
})
|
||||
|
||||
it('reports the mobile menu closed and open states', async () => {
|
||||
mockViewport(true)
|
||||
const { wrapper } = await mountLayout()
|
||||
const menuButton = wrapper.get('.shell-menu-button')
|
||||
|
||||
expect(menuButton.attributes('aria-label')).toBe('打开菜单')
|
||||
expect(menuButton.attributes('aria-expanded')).toBe('false')
|
||||
|
||||
await menuButton.trigger('click')
|
||||
|
||||
expect(menuButton.attributes('aria-label')).toBe('关闭菜单')
|
||||
expect(menuButton.attributes('aria-expanded')).toBe('true')
|
||||
})
|
||||
|
||||
it('shows the authenticated identity without a role preview switcher', async () => {
|
||||
const { wrapper } = await mountLayout()
|
||||
|
||||
Reference in New Issue
Block a user