86 lines
6.0 KiB
TypeScript
86 lines
6.0 KiB
TypeScript
// Covers how the Indicadores tab arranges TEA's figures: the time figures under «Indicadores de oportunidad», the
|
|
// clinical ones under «Indicadores clínicos», each in its order, and the tab's name in the three domains.
|
|
// Fixtures: a TEA catalog shaped like /tea/indicadores, published out of order on purpose.
|
|
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';
|
|
import { Dominio } from './indicadores.models';
|
|
|
|
const item = (id: string, titulo: string, contrato: string, figuras: string[]) => ({ id, titulo, contrato, figuras, tipos_periodo: ['semestre', 'mes'] });
|
|
const TEA = [
|
|
item('M30_resultado_eeg', 'Porcentaje de EEG normal y anormal', 'C1', ['fig_c1_barras_alteracion']),
|
|
item('M29_calidad_eeg', 'Calidad del EEG', 'C2', ['fig_c2_barras']),
|
|
item('M28_casos_por_estado', 'Casos por estatus', 'C2', ['fig_c2_barras']),
|
|
item('M27_dias_ados2_diagnostico', 'Días de ADOS-2 a diagnóstico', 'C3r', ['fig_c3r_caja']),
|
|
item('M26_dias_mchat_ados2', 'Días de M-CHAT a ADOS-2', 'C3r', ['fig_c3r_caja']),
|
|
item('M25_dias_mchat_diagnostico', 'Días de M-CHAT a diagnóstico positivo', 'C3r', ['fig_c3r_caja']),
|
|
item('M24_confirmacion_diagnostico', 'Porcentaje de confirmación diagnóstica', 'C1', ['fig_c1_barras_apiladas_edad']),
|
|
item('M23_pacientes_evaluados', 'Pacientes evaluados por resultado diagnóstico', 'C2', ['fig_c2_barras']),
|
|
item('M22_diagnosticados_sin_eeg', 'Porcentaje de pacientes con diagnóstico de TEA sin EEG', 'C1', ['fig_c1_barras_edad']),
|
|
item('M21_diagnosticados_con_eeg', 'Porcentaje de pacientes con diagnóstico de TEA con EEG', 'C1', ['fig_c1_barras_edad']),
|
|
];
|
|
|
|
describe('Indicadores de TEA: figuras de oportunidad y clínicas', () => {
|
|
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 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();
|
|
});
|
|
// The KPI and period requests are not what these tests are about.
|
|
afterEach(() => { fixture.destroy(); http.match(() => true); http.verify(); vi.unstubAllGlobals(); });
|
|
function open(domain: Dominio, catalog: unknown[]) {
|
|
// The page starts in TEA, whose catalog is already answered: leave it first to load it again.
|
|
if (domain === fixture.componentInstance.dominio) {
|
|
fixture.componentInstance.changeDominio(domain === 'cacu' ? 'cama' : 'cacu'); fixture.detectChanges();
|
|
http.match(() => true);
|
|
}
|
|
fixture.componentInstance.changeDominio(domain); fixture.detectChanges();
|
|
http.expectOne('/' + domain + '/indicadores').flush(catalog); fixture.detectChanges();
|
|
http.match(() => true); fixture.detectChanges();
|
|
}
|
|
const root = () => fixture.nativeElement as HTMLElement;
|
|
const titles = (selector: string) => [...root().querySelectorAll(selector + ' app-indicador-catalog-card h2')].map(e => e.textContent?.trim());
|
|
|
|
it('las figuras de tiempo van en oportunidad y las clínicas en su orden, sin duplicarse', () => {
|
|
// M30 belongs to Trazabilidad even when the catalog publishes it.
|
|
open('tea', TEA);
|
|
expect(titles('.kpi-section')).toEqual(['Días de M-CHAT a ADOS-2', 'Días de ADOS-2 a diagnóstico', 'Días de M-CHAT a diagnóstico positivo']);
|
|
expect(titles('.graphic-section')).toEqual([
|
|
'Pacientes evaluados por resultado diagnóstico', 'Porcentaje de confirmación diagnóstica',
|
|
'Porcentaje de pacientes con diagnóstico de TEA con EEG', 'Porcentaje de pacientes con diagnóstico de TEA sin EEG',
|
|
'Casos por estatus', 'Calidad del EEG']);
|
|
expect(root().querySelector('#kpi-section-title')?.textContent).toBe('Indicadores de oportunidad');
|
|
expect(root().querySelector('#graphic-section-title')?.textContent).toBe('Indicadores clínicos');
|
|
expect(fixture.componentInstance.catalogOrder().map(item => item.id)).not.toContain('M30_resultado_eeg');
|
|
});
|
|
|
|
it('un indicador no publicado deja el resto en su orden', () => {
|
|
// Fails if the order depends on every figure being published.
|
|
open('tea', TEA.filter(entry => entry.id !== 'M27_dias_ados2_diagnostico' && entry.id !== 'M23_pacientes_evaluados'));
|
|
expect(titles('.kpi-section')).toEqual(['Días de M-CHAT a ADOS-2', 'Días de M-CHAT a diagnóstico positivo']);
|
|
expect(titles('.graphic-section').slice(0, 2)).toEqual(['Porcentaje de confirmación diagnóstica', 'Porcentaje de pacientes con diagnóstico de TEA con EEG']);
|
|
});
|
|
|
|
it('CaMa no recibe el resumen ni el orden de TEA en oportunidad', () => {
|
|
// Fails if TEA's summary or its figure order leaks into CaMa's opportunity strip (CaMa has its own time section).
|
|
open('cama', [item('cama_eu38a', 'Días de la toma de la mastografía a su resultado', 'C3r', ['fig_c3r_caja'])]);
|
|
expect(root().querySelector('app-tea-resumen-periodo')).toBeNull();
|
|
});
|
|
|
|
it('la primera pestaña se llama Resumen en TEA e Indicadores en CaCu y CaMa', () => {
|
|
// Fails if TEA's first tab loses its name, if CaCu or CaMa take it, or if the section id changes.
|
|
for (const domain of ['tea', 'cacu', 'cama'] as const) {
|
|
open(domain, [item(domain + '_x', 'Indicador', 'C2', ['fig_c2_barras'])]);
|
|
const first = root().querySelector('[role="tab"]') as HTMLElement;
|
|
expect(first.textContent?.trim()).toBe(domain === 'tea' ? 'Resumen' : 'Indicadores');
|
|
expect(first.id).toBe('tab-resumen');
|
|
}
|
|
});
|
|
});
|