// What this module covers: the screening route chart in CaCu's page: it appears only when the catalog publishes the seven // measures it reads, and then those measures that nothing else draws lose their own cards. Catalogs are synthetic, // shaped like /cacu/indicadores. import { TestBed } from '@angular/core/testing'; import { provideHttpClient } from '@angular/common/http'; import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; import { By } from '@angular/platform-browser'; import { provideRouter } from '@angular/router'; import { IndicadorCatalogCard } from './indicador-catalog-card'; import { IndicadoresPage } from './indicadores-page'; import { IndicadoresMemory } from './indicadores-memory'; import { Dominio } from './indicadores.models'; import { ROUTE_IDS, ROUTE_ONLY_IDS } from './screening-route'; // Each measure carries the figure of its contract, as the published ones do: the Indicadores tab draws no card for an indicator without figures. const item = (id: string, contrato = 'C3r') => ({ id, titulo: id, contrato, figuras: [contrato === 'C2' ? 'fig_c2_donas' : 'fig_c3r_caja'], tipos_periodo: ['semestre', 'mes'] }); describe('Ruta del tamizaje: página de CaCu', () => { let fixture: ReturnType>, http: HttpTestingController; beforeEach(() => { vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} }); TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting()] }); for (const domain of ['tea', 'cacu', 'cama'] as const) TestBed.inject(IndicadoresMemory).finishInitialKpiPresentation(domain); 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(); }); function abrir(domain: Dominio, catalog: unknown[]) { fixture.componentInstance.changeDominio(domain); fixture.detectChanges(); http.expectOne('/' + domain + '/indicadores').flush(catalog); fixture.detectChanges(); http.match(() => true); } const ruta = () => fixture.nativeElement.querySelector('app-indicador-screening-route'); const tarjetas = () => fixture.debugElement.queryAll(By.directive(IndicadorCatalogCard)).map(d => (d.componentInstance as IndicadorCatalogCard).indicador.id); it('con las siete medidas publicadas aparece la gráfica y sus medidas exclusivas no tienen tarjeta', () => { // Pins down: the chart replaces the cards of the five measures only it draws, while the cytology's and the diagnosis' // keep theirs. Fails if the chart stops appearing, or a measure it draws also shows as a card. abrir('cacu', [item('cacu_eu7', 'C2'), ...ROUTE_IDS.map(id => item(id))]); expect(ruta()).not.toBeNull(); const ids = tarjetas(); for (const id of ROUTE_ONLY_IDS) expect(ids).not.toContain(id); expect(ids).toContain('cacu_eu_tiempo_reporte'); expect(ids).toContain('cacu_eu7'); }); it('si el catálogo no publica alguna de las siete, no hay gráfica y las medidas conservan sus tarjetas', () => { // Fails if the chart appears with a measure missing, or the cards of the others disappear anyway. abrir('cacu', [item('cacu_eu7', 'C2'), ...ROUTE_IDS.filter(id => id !== 'cacu_dias_toma_biopsia').map(id => item(id))]); expect(ruta()).toBeNull(); const ids = tarjetas(); for (const id of ROUTE_ONLY_IDS.filter(id => id !== 'cacu_dias_toma_biopsia')) expect(ids).toContain(id); }); it('las otras áreas no la tienen', () => { // Fails if the CaCu chart leaks into TEA or CaMa. abrir('cama', [item('cama_eu38a'), ...ROUTE_IDS.map(id => item(id))]); expect(ruta()).toBeNull(); }); });