Files
gongxue-base/apps/admin/src/auth/permission-navigation.integration.test.ts
xiong cbc04fea4f
Some checks failed
CI 检查 / lint (pull_request) Has been cancelled
CI 检查 / typecheck (pull_request) Has been cancelled
CI 检查 / test (pull_request) Has been cancelled
feat: add exam score management
2026-07-21 16:04:17 +08:00

38 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
findFirstAccessiblePath,
getRequiredPermission,
canAccessPath,
} from './permission-navigation';
describe('permission navigation', () => {
it('does not default to dashboard when dashboard permission is absent', () => {
const permissions = ['class:view', 'schedule:view'];
expect(findFirstAccessiblePath(permissions)).toBe('/classes');
});
it('lands teachers on the teacher workspace without global student or class access', () => {
expect(
findFirstAccessiblePath(['teacher-workspace:view', 'schedule:view', 'attendance:view']),
).toBe('/teacher-workspace');
expect(canAccessPath('/students', ['teacher-workspace:view'])).toBe(false);
expect(canAccessPath('/classes', ['teacher-workspace:view'])).toBe(false);
});
it('uses dashboard when it is the first accessible page', () => {
expect(findFirstAccessiblePath(['dashboard:view', 'student:view'])).toBe('/dashboard');
});
it('returns null when the user has no page permissions', () => {
expect(findFirstAccessiblePath(['profile:view'])).toBeNull();
});
it('keeps route permission lookup aligned for nested detail routes', () => {
expect(getRequiredPermission('/classes/12')).toBe('class:view');
expect(getRequiredPermission('/students/8/profile')).toBe('student:view');
expect(getRequiredPermission('/exams/8')).toBe('exam:view');
expect(canAccessPath('/ai-config', ['ai:config:read'])).toBe(true);
expect(canAccessPath('/ai-config', ['integration:read'])).toBe(false);
});
});