6a7c1d0cbd
The topbar no longer shows «Análisis de información» next to the logo; the breadcrumb stays on the workspace routes. The home eyebrow reads «ISSSTELEON» and the «Indicadores» action is «Modelos predictivos de riesgo».
127 lines
5.4 KiB
TypeScript
127 lines
5.4 KiB
TypeScript
import { signal } from '@angular/core';
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { provideHttpClient } from '@angular/common/http';
|
|
import { provideHttpClientTesting } from '@angular/common/http/testing';
|
|
import { provideRouter, Router } from '@angular/router';
|
|
import { of } from 'rxjs';
|
|
import { App } from './app';
|
|
import { routes } from './app.routes';
|
|
import { AuthService, Usuario } from './auth/auth.service';
|
|
|
|
const TODOS: Usuario = { usuario: 'admin', nombre: 'Administrador', dominios: ['cacu', 'cama', 'tea'] };
|
|
|
|
/**
|
|
* Doble de la sesión: `App` lee la señal y los guards preguntan si hay sesión y
|
|
* qué dominios alcanza. Las pruebas de este archivo cubren el marco, no el
|
|
* inicio de sesión en sí (`auth/auth.service.spec.ts`).
|
|
*/
|
|
function authFalso(sesion: Usuario | null) {
|
|
return {
|
|
usuario: signal(sesion),
|
|
autenticado: signal(sesion !== null),
|
|
sesion: () => of(sesion),
|
|
puedeVer: (dominio: string) => sesion?.dominios.includes(dominio) ?? false,
|
|
logout: () => of(undefined),
|
|
limpiar: () => undefined,
|
|
};
|
|
}
|
|
|
|
async function montar(sesion: Usuario | null): Promise<Router> {
|
|
await TestBed.configureTestingModule({
|
|
imports: [App],
|
|
providers: [
|
|
provideRouter(routes),
|
|
provideHttpClient(),
|
|
provideHttpClientTesting(),
|
|
{ provide: AuthService, useValue: authFalso(sesion) },
|
|
],
|
|
}).compileComponents();
|
|
return TestBed.inject(Router);
|
|
}
|
|
|
|
describe('App', () => {
|
|
async function render(url: string) {
|
|
const fixture = TestBed.createComponent(App);
|
|
fixture.detectChanges();
|
|
await TestBed.inject(Router).navigateByUrl(url).catch(() => false);
|
|
await fixture.whenStable();
|
|
fixture.detectChanges();
|
|
return fixture.nativeElement as HTMLElement;
|
|
}
|
|
|
|
describe('con sesión de administrador', () => {
|
|
beforeEach(() => montar(TODOS));
|
|
|
|
it('renders the ISSSTELEON shell and home page with its footer', async () => {
|
|
const page = await render('/');
|
|
expect(page.querySelector('.brand img')?.getAttribute('alt')).toBe('ISSSTELEON');
|
|
expect(page.querySelector('h1')?.textContent).toContain('Analiza tu información');
|
|
expect(page.querySelector('.home__action')?.getAttribute('href')).toBe('/conectar');
|
|
expect(page.querySelector('.site-footer')).not.toBeNull();
|
|
});
|
|
|
|
it('home shows only the brand name as eyebrow and names the risk models action', async () => {
|
|
// Fails if the eyebrow regains the section text or the action goes back to «Indicadores».
|
|
const page = await render('/');
|
|
expect(page.querySelector('.home__eyebrow')?.textContent?.trim()).toBe('ISSSTELEON');
|
|
const acciones = Array.from(page.querySelectorAll('.home__action')).map(a => a.textContent?.replace(/\s+/g, ' ').trim());
|
|
expect(acciones.some(t => t?.endsWith('Modelos predictivos de riesgo'))).toBe(true);
|
|
expect(acciones.some(t => t?.endsWith('Indicadores'))).toBe(false);
|
|
});
|
|
|
|
it('/conectar opens the full-height workspace (breadcrumb, no footer)', async () => {
|
|
const page = await render('/conectar');
|
|
expect(page.querySelector('app-connect-page')).not.toBeNull();
|
|
expect(page.querySelector('.site-header__crumb')?.textContent).toContain('Conectar datos');
|
|
expect(page.querySelector('.site-footer')).toBeNull();
|
|
}, 15000);
|
|
|
|
it('/gobernanza opens the governance workspace (breadcrumb, no footer)', async () => {
|
|
const page = await render('/gobernanza');
|
|
expect(page.querySelector('app-governance-page')).not.toBeNull();
|
|
expect(page.querySelector('.site-header__crumb')?.textContent).toContain('Gobernanza de modelos');
|
|
expect(page.querySelector('.site-footer')).toBeNull();
|
|
});
|
|
|
|
it('el encabezado nombra al usuario de la sesión y ofrece cerrarla', async () => {
|
|
// Fails if the shell forgets the session: the user would have no way out.
|
|
const page = await render('/');
|
|
expect(page.querySelector('.site-header__salir')?.textContent).toContain('Administrador');
|
|
});
|
|
});
|
|
|
|
describe('con una cuenta de un solo dominio', () => {
|
|
beforeEach(() => montar({ usuario: 'cacu', nombre: 'Equipo CaCu', dominios: ['cacu'] }));
|
|
|
|
it('no deja abrir el dominio ajeno: la manda al suyo', async () => {
|
|
// Fails if the domain scope exists only on the server: the interface would show an empty page.
|
|
await render('/indicadores/cama');
|
|
expect(TestBed.inject(Router).url).toBe('/indicadores/cacu');
|
|
}, 15000);
|
|
|
|
it('el encabezado no ofrece los otros dominios', async () => {
|
|
const page = await render('/indicadores/cacu');
|
|
expect(page.querySelector('app-domain-selector')).toBeNull();
|
|
expect(page.querySelector('.domain-selector--espera')?.textContent).toContain('Cáncer cervicouterino');
|
|
});
|
|
});
|
|
|
|
describe('sin sesión', () => {
|
|
beforeEach(() => montar(null));
|
|
|
|
it('cualquier ruta manda al inicio de sesión y no muestra el marco', async () => {
|
|
const page = await render('/conectar');
|
|
expect(TestBed.inject(Router).url).toContain('/login');
|
|
expect(page.querySelector('.login')).not.toBeNull();
|
|
expect(page.querySelector('.site-header')).toBeNull();
|
|
expect(page.querySelector('.site-footer')).toBeNull();
|
|
expect(page.querySelector('app-connect-page')).toBeNull();
|
|
});
|
|
|
|
it('el destino pedido viaja en returnUrl para volver después de entrar', async () => {
|
|
await render('/gobernanza');
|
|
expect(TestBed.inject(Router).url).toContain('returnUrl=%2Fgobernanza');
|
|
});
|
|
});
|
|
});
|