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_PATHS } from './features/documents/document-paths'; import { DOCUMENT_SCREENS } from './features/documents/document-screens'; import { MASTER_PATHS } from './features/masters/master-paths'; import { MASTER_SCREENS } from './features/masters/master-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.resolve?.['screen'], screen.path).toBeDefined(); // la configuración se carga al abrir la pantalla } }); it('la lista de rutas de documento del enrutador coincide con las pantallas', () => { expect([...DOCUMENT_PATHS].sort()).toEqual(DOCUMENT_SCREENS.map((s) => s.path).sort()); }); it('el resolver entrega la pantalla de su ruta', async () => { for (const path of ['/ventas/ordenes', '/inventario/entradas']) { const route = children.find((r) => r.path === path.slice(1))!; const screen = await (route.resolve!['screen'] as () => Promise<{ path: string }>)(); expect(screen.path).toBe(path); } }); it('cada maestro ofrece lista, "nuevo" y "ver/editar" por su clave de texto', async () => { for (const path of MASTER_PATHS) { const route = children.find((r) => r.path === path.slice(1))!; expect(route.children?.map((c) => c.path), path).toEqual(['', 'nuevo', ':key']); expect(route.canActivate, path).toContain(permissionGuard); const screen = await (route.resolve!['screen'] as () => Promise<{ path: string }>)(); expect(screen.path).toBe(path); } }); it('la lista de rutas de maestros del enrutador coincide con las pantallas', () => { expect([...MASTER_PATHS].sort()).toEqual(MASTER_SCREENS.map((s) => s.path).sort()); }); 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: '' }); }); });