This commit is contained in:
2026-08-14 16:06:30 +08:00
parent 1c1c48f8d3
commit d1b4a4d3f3
26 changed files with 187 additions and 29 deletions
+19
View File
@@ -92,6 +92,25 @@ describe('AppLayout', () => {
expect(menuButton.attributes('aria-expanded')).toBe('true')
})
it('closes the mobile menu when returning to the desktop breakpoint and removes the listener', async () => {
mockViewport(true)
const { wrapper } = await mountLayout()
const menuButton = wrapper.get('.shell-menu-button')
const mediaQuery = vi.mocked(window.matchMedia).mock.results[0]?.value as MediaQueryList
const changeHandler = vi.mocked(mediaQuery.addEventListener).mock.calls[0]?.[1] as ((event: MediaQueryListEvent) => void)
await menuButton.trigger('click')
expect(menuButton.attributes('aria-expanded')).toBe('true')
changeHandler({ matches: false } as MediaQueryListEvent)
await wrapper.vm.$nextTick()
expect(menuButton.attributes('aria-label')).toBe('收起导航')
expect(menuButton.attributes('aria-expanded')).toBe('true')
wrapper.unmount()
expect(mediaQuery.removeEventListener).toHaveBeenCalledWith('change', changeHandler)
})
it('shows the authenticated identity without a role preview switcher', async () => {
const { wrapper } = await mountLayout()
expect(wrapper.text()).toContain('登录身份:平台管理员(admin)')