diff --git a/src/app/app-encabezado.spec.ts b/src/app/app-encabezado.spec.ts new file mode 100644 index 0000000..24ab7a6 --- /dev/null +++ b/src/app/app-encabezado.spec.ts @@ -0,0 +1,90 @@ +// 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. + const paths = routes.map(r => r.path); + for (const dominio of DOMINIOS) expect(paths).toContain(`indicadores/${dominio}`); + }); + it.each([['tea', 'TEA'], ['cacu', 'CaCu'], ['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(['TEA', 'CaCu']); + 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('CaCu'); + // 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(); + }); +}); diff --git a/src/app/app.html b/src/app/app.html index b41af08..0cbc82f 100644 --- a/src/app/app.html +++ b/src/app/app.html @@ -1,15 +1,28 @@ -
+
diff --git a/src/app/app.scss b/src/app/app.scss index 234d0f1..8400cfb 100644 --- a/src/app/app.scss +++ b/src/app/app.scss @@ -103,3 +103,28 @@ width: 155px; } } + +.platform-title { + color: var(--color-text); + font-family: var(--issste-font-heading); + font-size: 1.25rem; + font-weight: 500; + line-height: 1.15; + margin-inline-start: var(--issste-space-4); + margin-inline-end: auto; + overflow-wrap: anywhere; +} + +.domain-selector { + flex: 0 0 auto; + background-color: var(--issste-accent); + color: var(--issste-text); + font-weight: 700; + white-space: nowrap; +} +.domain-selector:hover { background-color: var(--issste-accent); filter: brightness(.94); } +.domain-selector:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 2px; } + +@media (max-width: 599px) { + .platform-title { font-size: 1.125rem; min-width: 0; } +} diff --git a/src/app/app.ts b/src/app/app.ts index b18cd4e..f426daf 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -1,10 +1,13 @@ import { Component, computed, inject } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterOutlet } from '@angular/router'; +import { MatButtonModule } from '@angular/material/button'; +import { MatMenuModule } from '@angular/material/menu'; import { filter, map } from 'rxjs'; +import { Dominio, DOMINIOS } from './features/indicadores/indicadores.models'; @Component({ - imports: [RouterLink, RouterOutlet], + imports: [RouterLink, RouterOutlet, MatButtonModule, MatMenuModule], selector: 'app-root', styleUrl: './app.scss', templateUrl: './app.html', @@ -28,4 +31,13 @@ export class App { /** Full-height workspace routes (`data.workspace`) drop the marketing footer. */ readonly workspace = computed(() => !!this.leafRouteData()['workspace']); readonly breadcrumb = computed(() => this.leafRouteData()['breadcrumb'] as string | undefined); + + protected readonly title = 'Plataforma de Indicadores'; + protected readonly domainLabels: Record = { tea: 'TEA', cacu: 'CaCu', cama: 'Cáncer de mama' }; + private readonly url = toSignal(this.router.events.pipe( + filter((event) => event instanceof NavigationEnd), map(event => event.urlAfterRedirects)), { initialValue: this.router.url }); + /** On an indicators page the header names its domain and switches to the others. */ + protected readonly activeDomain = computed(() => + DOMINIOS.find(domain => new RegExp(`^/indicadores/${domain}(?:[/?#]|$)`).test(this.url()))); + protected readonly otherDomains = computed(() => DOMINIOS.filter(domain => domain !== this.activeDomain())); }