Files
basic-erp/apps/web/src/app/app.routes.spec.ts
T

44 lines
1.9 KiB
TypeScript
Raw Normal View History

import { MENU } from '@basic-erp/sap-types';
import { describe, expect, it } from 'vitest';
import { routes } from './app.routes';
import { permissionGuard } from './core/auth/guards';
import { DOCUMENT_SCREENS } from './features/documents/document-screens';
const shell = routes.find((r) => r.path === '')!;
const children = shell.children!;
describe('rutas', () => {
it('cada pantalla del menú tiene su ruta protegida por permiso', () => {
for (const item of MENU.flatMap((m) => m.items)) {
const route = children.find((r) => r.path === item.path.slice(1));
expect(route, item.path).toBeDefined();
expect(route?.canActivate, item.path).toContain(permissionGuard);
expect(route?.data?.['path'], item.path).toBe(item.path);
}
});
it('cada documento ofrece lista, "nuevo" y "ver/editar" bajo la ruta del menú', () => {
for (const screen of DOCUMENT_SCREENS) {
const route = children.find((r) => r.path === screen.path.slice(1))!;
expect(route.children?.map((c) => c.path), screen.path).toEqual(['', 'nuevo', ':docEntry']);
expect(route.data?.['screen']).toBe(screen);
}
});
it('las pantallas que no son documentos (maestros) siguen como "no disponible"', () => {
const route = children.find((r) => r.path === 'socios/clientes')!;
expect(route.children).toBeUndefined();
expect(route.loadComponent).toBeDefined();
});
it('la página de componentes está restringida a desarrollo y no está en el menú', () => {
const route = children.find((r) => r.path === 'dev/componentes');
expect(route?.loadComponent).toBeDefined();
expect(route?.canMatch).toHaveLength(1); // solo coincide en desarrollo
expect(MENU.flatMap((m) => m.items).some((i) => i.path.startsWith('/dev/'))).toBe(false);
});
it('las rutas desconocidas vuelven al inicio', () => {
expect(routes.at(-1)).toMatchObject({ path: '**', redirectTo: '' });
});
});