// Covers the shell's header: on an indicators page it carries the platform title and the domain selector; on // the institutional routes it keeps the breadcrumb. The pages are stubs: only the header and the router matter. import { Component } from '@angular/core'; import { Location } from '@angular/common'; import { TestBed } from '@angular/core/testing'; import { provideRouter, Router } from '@angular/router'; import { provideHttpClient } from '@angular/common/http'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { App } from './app'; import { routes } from './app.routes'; import { DOMINIOS } from './features/indicadores/indicadores.models'; @Component({ template: 'página', selector: 'app-stub' }) class Stub {} describe('Encabezado del marco', () => { const rutas = [ { path: '', component: Stub }, { path: 'conectar', component: Stub, data: { workspace: true, breadcrumb: 'Conectar datos' } }, { path: 'gobernanza', component: Stub, data: { workspace: true, breadcrumb: 'Gobernanza de modelos' } }, ...DOMINIOS.map(dominio => ({ path: `indicadores/${dominio}`, component: Stub, data: { workspace: true, breadcrumb: 'Indicadores', dominio } })), ]; let fixture: ReturnType>, router: Router; beforeEach(async () => { await TestBed.configureTestingModule({ imports: [App], providers: [provideRouter(rutas), provideHttpClient(), provideHttpClientTesting()] }).compileComponents(); fixture = TestBed.createComponent(App); router = TestBed.inject(Router); fixture.detectChanges(); }); afterEach(() => { fixture.destroy(); document.querySelectorAll('.cdk-overlay-container').forEach(e => e.replaceChildren()); }); const root = () => fixture.nativeElement as HTMLElement; async function ir(url: string) { await router.navigateByUrl(url); await fixture.whenStable(); fixture.detectChanges(); } const selector = () => root().querySelector('.domain-selector') as HTMLButtonElement | null; async function abrirMenu() { selector()!.click(); fixture.detectChanges(); await fixture.whenStable(); fixture.detectChanges(); return [...document.querySelectorAll('.mat-mdc-menu-panel a[mat-menu-item]')] as HTMLAnchorElement[]; } it('las rutas de los tres dominios existen en el enrutador de la aplicación', () => { // Fails if the selector would point at a route the application does not have. // The application's routes live under the guarded parent ('login' is its sibling). const paths = routes.flatMap((ruta) => [ruta.path, ...(ruta.children ?? []).map((hijo) => hijo.path)]); for (const dominio of DOMINIOS) expect(paths).toContain(`indicadores/${dominio}`); }); it.each([['tea', 'Trastorno del espectro autista'], ['cacu', 'Cáncer cervicouterino'], ['cama', 'Cáncer de mama']] as const)('en /indicadores/%s muestra el título de la plataforma y el selector con «%s»', async (dominio, etiqueta) => { await ir('/indicadores/' + dominio); expect(root().querySelector('.platform-title')?.textContent).toBe('Plataforma de Indicadores'); expect(selector()?.textContent?.replace(/\s+/g, ' ').trim()).toBe(etiqueta + ' ▾'); expect(root().querySelector('.brand img')?.getAttribute('alt')).toBe('ISSSTELEON'); // The breadcrumb is replaced, not duplicated beside the selector. expect(root().querySelector('.site-header__nav')).toBeNull(); expect(root().querySelector('.app-shell--indicadores')).not.toBeNull(); }); it('el selector tiene nombre accesible con el dominio actual y anuncia un menú', async () => { await ir('/indicadores/cama'); expect(selector()!.getAttribute('aria-label')).toBe('Dominio actual: Cáncer de mama. Cambiar dominio'); expect(selector()!.getAttribute('aria-haspopup')).toBe('menu'); expect(selector()!.tagName).toBe('BUTTON'); expect(selector()!.tabIndex).toBeGreaterThanOrEqual(0); }); it('el menú ofrece los otros dos dominios con sus rutas institucionales', async () => { await ir('/indicadores/cama'); const items = await abrirMenu(); expect(items.map(a => a.textContent?.trim())).toEqual(['Trastorno del espectro autista', 'Cáncer cervicouterino']); expect(items.map(a => a.getAttribute('href'))).toEqual(['/indicadores/tea', '/indicadores/cacu']); expect(selector()!.getAttribute('aria-expanded')).toBe('true'); }); it('elegir otro dominio navega por el enrutador, actualiza el selector y deja una entrada en el historial', async () => { await ir('/indicadores/cama'); const items = await abrirMenu(); items[1].click(); await fixture.whenStable(); fixture.detectChanges(); expect(router.url).toBe('/indicadores/cacu'); expect(selector()!.textContent).toContain('Cáncer cervicouterino'); // The choice is a router navigation (a history entry), not a page reload: going back lands on the previous domain. const ubicacion = TestBed.inject(Location); ubicacion.back(); await new Promise(r => setTimeout(r, 100)); expect(ubicacion.path()).toBe('/indicadores/cama'); }); it.each(['/', '/conectar', '/gobernanza'])('en %s conserva el encabezado institucional sin selector', async url => { // Fails if the indicators header leaks into the institutional routes. await ir(url); expect(selector()).toBeNull(); expect(root().querySelector('.platform-title')).toBeNull(); expect(root().querySelector('.site-header__section')?.textContent).toBe('Análisis de información'); expect(root().querySelector('.app-shell--indicadores')).toBeNull(); if (url !== '/') expect(root().querySelector('.site-header__crumb')?.textContent).toContain(url === '/conectar' ? 'Conectar datos' : 'Gobernanza de modelos'); }); it('una ruta parecida que no es de indicadores no activa el selector', async () => { await router.navigateByUrl('/'); fixture.detectChanges(); expect(selector()).toBeNull(); }); });