From ff03a88ea0a9013b1e5b839c844c53010774681d Mon Sep 17 00:00:00 2001 From: Angel Capetillo Zavala Date: Thu, 12 Nov 2026 01:21:53 -0600 Subject: [PATCH] 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) --- .../indicadores-cambio-dominio.spec.ts | 60 +++++++++++++++++++ .../indicadores-navigation.spec.ts | 4 +- .../indicadores/indicadores-page.html | 8 --- .../indicadores/indicadores-page.scss | 28 --------- .../indicadores/indicadores-page.spec.ts | 11 ++-- .../features/indicadores/indicadores-page.ts | 14 ++--- .../indicadores/indicadores-sections.spec.ts | 6 +- 7 files changed, 74 insertions(+), 57 deletions(-) create mode 100644 src/app/features/indicadores/indicadores-cambio-dominio.spec.ts diff --git a/src/app/features/indicadores/indicadores-cambio-dominio.spec.ts b/src/app/features/indicadores/indicadores-cambio-dominio.spec.ts new file mode 100644 index 0000000..328e3e3 --- /dev/null +++ b/src/app/features/indicadores/indicadores-cambio-dominio.spec.ts @@ -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>, 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_'); + }); +}); diff --git a/src/app/features/indicadores/indicadores-navigation.spec.ts b/src/app/features/indicadores/indicadores-navigation.spec.ts index f14b57f..ffef693 100644 --- a/src/app/features/indicadores/indicadores-navigation.spec.ts +++ b/src/app/features/indicadores/indicadores-navigation.spec.ts @@ -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 () => { diff --git a/src/app/features/indicadores/indicadores-page.html b/src/app/features/indicadores/indicadores-page.html index 654018d..fdd3c73 100644 --- a/src/app/features/indicadores/indicadores-page.html +++ b/src/app/features/indicadores/indicadores-page.html @@ -10,14 +10,6 @@ } @if (!fichaPacienteAbierta()) { - -
@for (section of sections; track section.id) {