fix: align permission navigation and page access
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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('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(canAccessPath('/ai-config', ['ai:config:read'])).toBe(true);
|
||||
expect(canAccessPath('/ai-config', ['integration:read'])).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user