fix lint and type error

This commit is contained in:
2026-03-18 20:08:04 +08:00
parent 58e1c34b69
commit 1040e3ecfd
9 changed files with 67 additions and 38 deletions
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { mount } from '@vue/test-utils'
import { createRouter, createMemoryHistory } from 'vue-router'
@@ -56,6 +56,8 @@ describe('MainLayout', () => {
LogoutOutlined: { template: '<span />' },
SettingOutlined: { template: '<span />' },
KeyOutlined: { template: '<span />' },
// Stub dropdown to render overlay inline (avoids Teleport in jsdom)
ADropdown: { template: '<div><slot /><slot name="overlay" /></div>' },
Brand: { template: '<div class="brand-stub" />' },
},
},
@@ -143,26 +145,27 @@ describe('MainLayout', () => {
const wrapper = await mountLayout()
const vm = wrapper.getCurrentComponent()
const router = vm.appContext.config.globalProperties.$router
const pushSpy = vi.spyOn(router, 'push')
// Find and click the profile menu item
const menuItems = wrapper.findAll('.ant-dropdown-menu-item, .ant-menu-item')
// ADropdown is stubbed to render overlay inline, so menu items are in the wrapper
const menuItems = wrapper.findAll('.ant-menu-item')
const profileItem = menuItems.find((item) => item.text().includes('个人信息'))
if (profileItem) {
await profileItem.trigger('click')
}
// Verify the route in the router after navigation
await router.push('/profile')
expect(router.currentRoute.value.path).toBe('/profile')
expect(profileItem).toBeTruthy()
await profileItem!.trigger('click')
expect(pushSpy).toHaveBeenCalledWith('/profile')
})
it('navigates to /profile/password when clicking password menu item', async () => {
const wrapper = await mountLayout()
const vm = wrapper.getCurrentComponent()
const router = vm.appContext.config.globalProperties.$router
const pushSpy = vi.spyOn(router, 'push')
await router.push('/profile/password')
expect(router.currentRoute.value.path).toBe('/profile/password')
const menuItems = wrapper.findAll('.ant-menu-item')
const passwordItem = menuItems.find((item) => item.text().includes('修改密码'))
expect(passwordItem).toBeTruthy()
await passwordItem!.trigger('click')
expect(pushSpy).toHaveBeenCalledWith('/profile/password')
})
it('renders profile breadcrumb on /profile path', async () => {