This commit is contained in:
2026-04-08 21:26:18 +08:00
commit 8fdc7ac0c3
401 changed files with 53093 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useUserStore } from '@/stores/user'
// Mock @vueuse/core 的 useLocalStorage用 Vue 的 ref 替代以避免 localStorage 副作用
vi.mock('@vueuse/core', async () => {
const { ref } = await import('vue')
return {
useLocalStorage: (_key: string, defaultValue: unknown) => ref(defaultValue),
}
})
describe('useUserStore — Token 管理', () => {
beforeEach(() => {
setActivePinia(createPinia())
})
it('setToken 应正确设置 token 值', () => {
const store = useUserStore()
store.setToken('abc123')
expect(store.token).toBe('abc123')
})
it('setRToken 应正确设置 refreshToken 值', () => {
const store = useUserStore()
store.setRToken('refresh_xyz')
expect(store.rtoken).toBe('refresh_xyz')
})
it('setRTokenTime 应正确设置刷新时间戳', () => {
const store = useUserStore()
const timestamp = Date.now()
store.setRTokenTime(timestamp)
expect(store.rtokenTime).toBe(timestamp)
})
it('setDeviceType 应正确设置设备类型', () => {
const store = useUserStore()
store.setDeviceType('mobile')
expect(store.deviceType).toBe('mobile')
})
})