feat(indicadores): domain navigation moves to the header; searchVisible reads the catalog before the domain

The in-page domain buttons are removed, since the header selector replaces them. Also fixes a computed that, after a visit to CaMa, never became true again, so CaCu and TEA lost their search box when switched to from CaMa.

(cherry picked from commit 3678c3653b33fcb98ba2334ca8f03f838dc86440)
This commit is contained in:
Angel Capetillo Zavala
2026-11-12 01:21:53 -06:00
parent d761a6fb1a
commit ff03a88ea0
7 changed files with 74 additions and 57 deletions
@@ -0,0 +1,60 @@
// Covers switching domains with requests still pending: nothing of the domain that was left may show up in
// the one that was chosen, and the controls particular to each domain stay as they were.
import { TestBed } from '@angular/core/testing';
import { provideHttpClient } from '@angular/common/http';
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
import { provideRouter } from '@angular/router';
import { IndicadoresPage } from './indicadores-page';
import { IndicadoresMemory } from './indicadores-memory';
const item = (id: string, titulo: string, contrato: string) => ({ id, titulo, contrato, figuras: ['f', 'g'], tipos_periodo: ['semestre', 'mes'] });
describe('Cambio de dominio con consultas pendientes', () => {
let fixture: ReturnType<typeof TestBed.createComponent<IndicadoresPage>>, http: HttpTestingController;
beforeEach(() => {
vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} });
TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting()] });
for (const d of ['tea', 'cacu', 'cama'] as const) TestBed.inject(IndicadoresMemory).finishInitialKpiPresentation(d);
fixture = TestBed.createComponent(IndicadoresPage); http = TestBed.inject(HttpTestingController);
http.expectOne('/tea/indicadores').flush([]); fixture.detectChanges();
});
afterEach(() => { fixture.destroy(); http.match(() => true); http.verify(); vi.unstubAllGlobals(); });
const text = () => (fixture.nativeElement as HTMLElement).textContent!;
it('el catálogo pendiente del dominio que se dejó se cancela y su respuesta tardía no se dibuja', () => {
// Fails if a late answer of CaMa shows its indicators in CaCu.
fixture.componentInstance.changeDominio('cama'); fixture.detectChanges();
const cama = http.expectOne('/cama/indicadores');
fixture.componentInstance.changeDominio('cacu'); fixture.detectChanges();
expect(cama.cancelled).toBe(true);
http.expectOne('/cacu/indicadores').flush([item('cacu_x', 'Indicador de CaCu', 'C2')]); fixture.detectChanges();
expect(text()).toContain('Indicador de CaCu');
expect(() => cama.flush([item('cama_x', 'Indicador de CaMa', 'C2')])).toThrow();
fixture.detectChanges();
expect(text()).not.toContain('Indicador de CaMa');
});
it('los controles propios de cada dominio se conservan al ir y volver', () => {
// CaCu keeps its multiple selection, search and pins; CaMa does not have them; neither state contaminates the other.
const abrir = (d: 'cacu' | 'cama', n: number) => {
fixture.componentInstance.changeDominio(d); fixture.detectChanges();
http.expectOne('/' + d + '/indicadores').flush(Array.from({ length: n }, (_, i) => item(`${d}_${i}`, `${d} ${i}`, 'C2'))); fixture.detectChanges();
http.match(() => true);
};
const el = () => fixture.nativeElement as HTMLElement;
abrir('cacu', 6);
expect(el().querySelector('.catalog-search')).not.toBeNull();
expect(el().querySelectorAll('.pin-toggle').length).toBe(6);
expect(el().textContent).toContain('Modalidad');
abrir('cama', 6);
expect(el().querySelector('.catalog-search')).toBeNull();
expect(el().querySelector('.pin-toggle')).toBeNull();
expect(el().textContent).not.toContain('Modalidad');
expect(el().textContent).not.toContain('cacu_');
abrir('cacu', 6);
// On the way back the page state (not only the DOM) says CaCu has its search again.
expect(fixture.componentInstance.dominio).toBe('cacu');
expect(fixture.componentInstance.searchVisible()).toBe(true);
expect(el().textContent).toContain('Modalidad');
expect(el().textContent).not.toContain('cama_');
});
});
@@ -44,8 +44,8 @@ describe('UX-04 navegación Angular', () => {
const harness = await setup();
await harness.navigateByUrl('/indicadores/' + domain, IndicadoresPage);
load(domain, harness); harness.detectChanges();
// Our shell keeps the domain nav on the page itself, see indicadores-page.html.
expect(harness.routeNativeElement!.querySelectorAll('nav.domain-nav a')).toHaveLength(3);
// The domain links are in the shell's header selector (app-encabezado.spec.ts); the page has none of its own.
expect(harness.routeNativeElement!.querySelectorAll('nav.domain-nav')).toHaveLength(0);
http.expectNone(() => true);
});
it('mantiene la ruta, restaura borradores y reconsulta la aplicación entre TEA/CaCu/CaMa', async () => {
@@ -10,14 +10,6 @@
}
</header>
@if (!fichaPacienteAbierta()) {
<!-- Upstream moved domain switching into its own app shell's header (a
dropdown in app.ts/app.html); our shell is shared with other workspace
sections (Conectar, Gobernanza) so it stays here instead, same as before. -->
<nav aria-label="Dominios de indicadores" class="domain-nav">
@for (domain of dominios; track domain) {
<a mat-button [routerLink]="['/indicadores', domain]" [attr.aria-current]="dominio === domain ? 'page' : null">{{ domainNavLabels[domain] }}</a>
}
</nav>
<div class="section-tabs" [class.dark-theme]="tema === 'oscuro'" role="tablist" [attr.aria-label]="'Secciones de ' + domainLabels[dominio]" (keydown)="sectionKeydown($event)">
@for (section of sections; track section.id) {
<button type="button" role="tab" [id]="'tab-' + section.id" [attr.aria-controls]="'panel-' + section.id"
@@ -7,34 +7,6 @@
h1 { font: var(--mat-sys-headline-large); font-family: var(--issste-font-heading); font-weight: 700; margin: .65rem 0; }
header p { color: var(--mat-sys-on-surface-variant); margin-bottom: 1.5rem; }
.domain { color: var(--mat-sys-primary); font: var(--mat-sys-label-large); }
// Kept here (not moved to our app shell, see the template comment above the
// nav) -- same rules as before upstream relocated its own copy into app.scss.
.domain-nav {
display: flex;
flex-wrap: wrap;
gap: var(--issste-space-2);
padding: var(--issste-space-2);
justify-content: center;
margin: var(--issste-space-4) 0;
border-radius: var(--issste-radius);
}
.domain-nav a {
flex: 0 1 6rem;
max-width: 10rem;
color: var(--issste-text);
border: 1px solid var(--issste-border);
background: var(--issste-surface);
min-height: 44px;
border-radius: var(--issste-radius);
}
.domain-nav a[aria-current='page'] {
background: var(--issste-accent);
font-weight: 700;
text-decoration: none;
}
@media (max-width: 550px) {
.domain-nav { gap: var(--issste-space-2); padding-inline: 0; }
}
.state { padding: 1.25rem; margin: 0; }
.section-title { font-family: var(--issste-font-heading); font-size: 1.5rem; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.section-description { color: var(--issste-text-secondary); margin: var(--issste-space-2) 0 var(--issste-space-4); overflow-wrap: anywhere; }
@@ -128,14 +128,11 @@ describe('UX-06E.D.3.A catálogo permanentemente desplegado', () => {
expect(fixture.nativeElement.querySelector('.pin-toggle').getAttribute('aria-label')).toContain(title);
http.expectNone(() => true);
});
it('UX-06B mantiene una sola navegación entre dominios, sin duplicar botones', () => {
// Our shell has no domain selector of its own (unlike upstream's App),
// so the page keeps exactly the one it always had -- not duplicated.
// (Needs a render pass first: unlike upstream's trivial "absent" check,
// confirming presence requires the template to have actually painted.)
it('UX-06B la navegación entre dominios es la del encabezado: la página no la duplica', () => {
// The selector is in the shell's header (app-encabezado.spec.ts); a second set of buttons on the page would duplicate it.
fixture.detectChanges();
expect(fixture.nativeElement.querySelectorAll('nav.domain-nav')).toHaveLength(1);
expect(fixture.nativeElement.querySelectorAll('nav.domain-nav a')).toHaveLength(3);
expect(fixture.nativeElement.querySelectorAll('nav.domain-nav')).toHaveLength(0);
expect(fixture.nativeElement.querySelectorAll('a[href^="/indicadores/"]')).toHaveLength(0);
expect(cards()).toHaveLength(0);
// Constructing the page legitimately initializes its domain catalog.
const catalogRequest = http.expectOne('/tea/indicadores');
@@ -1,7 +1,7 @@
import { DOCUMENT } from '@angular/common';
import { afterEveryRender, afterNextRender, ChangeDetectorRef, Component, DestroyRef, ElementRef, Injector, inject, computed, signal, viewChild, viewChildren } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ActivatedRoute, RouterLink } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
@@ -12,7 +12,7 @@ import { MatSelectModule } from '@angular/material/select';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { ConnectedPosition, Overlay, OverlayModule } from '@angular/cdk/overlay';
import { catchError, map, of, startWith, Subject, switchMap, takeUntil } from 'rxjs';
import { Dominio, DOMINIOS, isDominio, Indicador, Tema } from './indicadores.models';
import { Dominio, isDominio, Indicador, Tema } from './indicadores.models';
import { IndicadoresService } from './indicadores.service';
import { applyGlobal, domainTypes, GlobalFilterState, IndicadoresMemory, pending, validDraft } from './indicadores-memory';
import { IndicadorPeriodFilters } from './indicador-period-filters';
@@ -42,7 +42,7 @@ const SECCIONES_CON_HISTORICO: readonly { id: DashboardSection; label: string }[
@Component({
selector: 'app-indicadores-page',
imports: [RouterLink, FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, OverlayModule, IndicadorCatalogCard, IndicadorKpiPanel, IndicadorKpiCard, IndicadorPeriodFilters, IndicadoresDefinitions, IndicadoresTracking, IndicadoresNavegacionPanel, IndicadoresHistorico],
imports: [FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, OverlayModule, IndicadorCatalogCard, IndicadorKpiPanel, IndicadorKpiCard, IndicadorPeriodFilters, IndicadoresDefinitions, IndicadoresTracking, IndicadoresNavegacionPanel, IndicadoresHistorico],
templateUrl: './indicadores-page.html',
styleUrl: './indicadores-page.scss',
})
@@ -273,14 +273,10 @@ export class IndicadoresPage {
private readonly memory = inject(IndicadoresMemory);
private readonly destroyRef = inject(DestroyRef);
private readonly route = inject(ActivatedRoute, { optional: true });
readonly dominios = DOMINIOS;
dominio: Dominio = 'tea';
readonly domainLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'cáncer cervicouterino', cama: 'cáncer de mama' };
// At the start of the header line.
readonly domainTitles: Record<Dominio, string> = { ...this.domainLabels, cacu: 'Cáncer cervicouterino', cama: 'Cáncer de mama' };
// Short form for the domain-switcher buttons (our shell's own nav, see the
// template comment above it) -- `domainLabels`/`domainTitles` are prose-length.
readonly domainNavLabels: Record<Dominio, string> = { tea: 'TEA', cacu: 'CaCu', cama: 'CaMa' };
readonly kpisByDomain = KPI_BY_DOMAIN;
figureApplied(item: Indicador) { return figureApplied(this.dominio, item.id, this.filters!.applied); }
independentPeriods(item: Indicador) { return independentFigurePeriods(this.dominio, item.id); }
@@ -321,7 +317,9 @@ export class IndicadoresPage {
readonly catalog = signal<Indicador[]>([]);
readonly searchQuery = signal('');
// CaMa follows the mockup: no search box and no pins; its cards are the ones the summary draws.
readonly searchVisible = computed(() => this.dominio !== 'cama' && this.catalog().length >= 5);
// The catalog is read first: `dominio` is not a signal, so a short-circuit before the read would leave this
// computed without dependencies, and it would never change after a visit to CaMa.
readonly searchVisible = computed(() => { const total = this.catalog().length; return this.dominio !== 'cama' && total >= 5; });
readonly searchResults = computed(() => {
const catalog = this.catalog();
// Stable presentation priority; search matches and pins still take precedence.
@@ -42,10 +42,8 @@ describe('Secciones compartidas por dominio', () => {
expect(tabs.map(t => t.textContent?.trim())).toEqual(esperadas);
expect(tabs.map(t => t.getAttribute('aria-selected'))).toEqual(esperadas.map((_, i) => String(i === 0)));
expect(root.querySelector('[role="tablist"]')?.getAttribute('aria-label')).toContain(page.domainLabels[domain]);
// Upstream moved domain selection to its own App shell; ours keeps it on
// the page itself (see indicadores-page.html), since our shell is shared
// with other workspace sections.
expect(root.querySelector('nav.domain-nav')).not.toBeNull();
// Domain switching lives in the shell's header (app.html), not on the page.
expect(root.querySelector('nav.domain-nav')).toBeNull();
for (const tab of tabs) {
const panel = root.querySelector<HTMLElement>('#' + tab.getAttribute('aria-controls'))!;
expect(panel.getAttribute('aria-labelledby')).toBe(tab.id);