20260904232445

This commit is contained in:
oneao committed 2026-09-04 23:24:45 +08:00
1 parent 4e167df0f0
commit 1b01a31252
19 files changed
+1099 -1013

No files matched your search

@@ -0,0 +1,44 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useAuthStore } from '@/stores/auth'
import router from '@/router'
// mock 后端数据接口(权限/菜单/多语言都走 loadDataApi)
vi.mock('@/services/api', () => ({
loadDataApi: vi.fn(() => Promise.resolve({ data: [], code: 0, success: true })),
}))
beforeEach(async () => {
localStorage.clear()
sessionStorage.clear()
setActivePinia(createPinia())
// 复位到登录页,避免上一用例的受保护路由状态泄漏
await router.push('/login').catch(() => {})
})
function login(account, id) {
useAuthStore().setSession({ token: 't', user: { id, account, name: account } }, 'ORG')
}
describe('路由守卫:模块中心 /module/* 仅 g3soft 可访问', () => {
it('普通用户:访问 /module/* 一律拦截回工作台', async () => {
login('001', 123)
await router.push('/module/i18n-type')
expect(router.currentRoute.value.path).toBe('/dashboard')
await router.push('/module/module-management')
expect(router.currentRoute.value.path).toBe('/dashboard')
})
it('普通用户:其它受保护页面不受影响', async () => {
login('001', 123)
await router.push('/demo')
expect(router.currentRoute.value.path).toBe('/demo')
})
it('g3soft:模块中心页面可正常访问', async () => {
login('g3soft', 1)
await router.push('/module/i18n-type')
expect(router.currentRoute.value.path).toBe('/module/i18n-type')
})
})