a5b00c2dea
- Vite+TS+ElementPlus+ECharts+Pinia+Router+Axios - auth store + JWT axios 拦截器 + 路由守卫 - 登录页 + Layout(侧栏 4 入口,回测/投研 active,模拟/实盘 disabled) - 占位页(backtest/factor,S1/S2 填充) - vitest auth store 3 tests passed + build 通过(dist 生成)
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { setActivePinia, createPinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it } from 'vitest'
|
|
import { useAuthStore } from '@/stores/auth'
|
|
|
|
describe('auth store', () => {
|
|
beforeEach(() => {
|
|
localStorage.clear()
|
|
setActivePinia(createPinia())
|
|
})
|
|
|
|
it('starts unauthenticated', () => {
|
|
const auth = useAuthStore()
|
|
expect(auth.isAuthenticated).toBe(false)
|
|
expect(auth.token).toBe(null)
|
|
})
|
|
|
|
it('setToken stores token + username and authenticates', () => {
|
|
const auth = useAuthStore()
|
|
auth.setToken('jwt-xyz', 'admin')
|
|
expect(auth.token).toBe('jwt-xyz')
|
|
expect(auth.username).toBe('admin')
|
|
expect(auth.isAuthenticated).toBe(true)
|
|
expect(localStorage.getItem('token')).toBe('jwt-xyz')
|
|
})
|
|
|
|
it('logout clears token + username', () => {
|
|
const auth = useAuthStore()
|
|
auth.setToken('jwt-xyz', 'admin')
|
|
auth.logout()
|
|
expect(auth.token).toBe(null)
|
|
expect(auth.username).toBe(null)
|
|
expect(auth.isAuthenticated).toBe(false)
|
|
expect(localStorage.getItem('token')).toBe(null)
|
|
})
|
|
})
|