Files
admin-web/src/core/access/accessPreview.test.ts
T
2026-08-05 15:54:59 +08:00

28 lines
1.0 KiB
TypeScript

import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it } from 'vitest'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { useAuthStore } from '@/core/auth/auth'
describe('server access store', () => {
beforeEach(() => setActivePinia(createPinia()))
it('uses only the authenticated permission snapshot', () => {
const auth = useAuthStore()
auth.token = 'token'
auth.permissions = ['platform:warehouse:list']
const access = useAccessPreviewStore()
access.initializeAfterLogin()
expect(access.can('platform:warehouse:list')).toBe(true)
expect(access.can('platform:user:list')).toBe(false)
expect(access.firstAccessiblePath).toBe('/dashboard')
})
it('keeps only the unprotected dashboard when the server snapshot is empty', () => {
const access = useAccessPreviewStore()
expect(access.permissionCodes.size).toBe(0)
expect(access.filteredNavigation).toHaveLength(1)
expect(access.firstAccessiblePath).toBe('/dashboard')
})
})