7b8fd9e01d
CaMa reads «cáncer de mama» everywhere on the indicators page and uses the compact filter: interval, one period and Aplicar on one row, without the mode selector, the multiple selection or the editing summaries. The opportunity strip is the four cards only, and the biopsy distribution card is no longer drawn in the summary (it stays in Datos y definiciones). Other domains keep their filter and strip. (cherry picked from commit 7c9dcf634e5870fec35ab96347b0863b2e3bb86e)
99 lines
6.9 KiB
TypeScript
99 lines
6.9 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
import { provideHttpClient } from '@angular/common/http';
|
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
|
import { IndicadoresInitialPeriod } from './indicadores-initial-period';
|
|
import { KPI_BY_DOMAIN } from './indicadores-kpi';
|
|
import { AvailablePeriod } from './indicadores-periodos';
|
|
import { TipoPeriodo } from './indicadores.models';
|
|
|
|
describe.each(['cacu', 'cama'] as const)('P0 búsqueda del ancla C2 de %s', domain => {
|
|
let service: IndicadoresInitialPeriod, http: HttpTestingController;
|
|
const anchor = KPI_BY_DOMAIN[domain][0];
|
|
const periods = ['2026-S2', '2026-S1', '2025-S2'];
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
|
|
service = TestBed.inject(IndicadoresInitialPeriod); http = TestBed.inject(HttpTestingController);
|
|
});
|
|
afterEach(() => http.verify());
|
|
function data(period: string, kind = 'positive') {
|
|
const categories = domain === 'cama' ? ['B4A', 'B4B', 'B4C', 'B5', 'B6', 'SIN_DATO'] : ['A'];
|
|
return { id: anchor.id, contrato: 'C2', tipo_periodo: period.includes('-S') ? 'semestre' : 'mes', periodos: [period],
|
|
categorias: Object.fromEntries([...categories, ...(kind === 'incomplete' ? ['MISSING'] : [])].map(c => [c, {}])),
|
|
filas: kind === 'empty' ? [] : categories.map((categoria, i) => ({ periodo: period,
|
|
grupo: kind === 'group' ? 'OTHER' : 'TOTAL', categoria, estrato: kind === 'stratum' ? 'sintetico' : null,
|
|
suprimido: kind === 'suppressed' ? 1 : 0, n: kind === 'null' ? null : kind === 'zero' || i > 0 ? 0 : 9 })) };
|
|
}
|
|
function inventory(values = [...periods].reverse()) {
|
|
http.expectOne(`/${domain}/indicadores/${anchor.id}/periodos`).flush({ id: anchor.id,
|
|
periodos: values.map(periodo => ({ periodo, tipo: periodo.includes('-S') ? 'semestre' : 'mes' })) });
|
|
}
|
|
function request(period: string) { return http.expectOne(r => r.url === `/${domain}/indicadores/${anchor.id}/datos` && r.params.get('periodos') === period); }
|
|
function start(tipo: TipoPeriodo = 'semestre') {
|
|
let selected: AvailablePeriod | undefined, completed = false, failed = false;
|
|
const subscription = service.find(domain, anchor, tipo).subscribe({ next: result => { selected = result; completed = true; }, error: () => { failed = true; } });
|
|
return { selected: () => selected, completed: () => completed, failed: () => failed, subscription };
|
|
}
|
|
it('elige el positivo más reciente, reutiliza la respuesta y no consulta periodos anteriores', () => {
|
|
const run = start(); inventory(); request(periods[0]).flush(data(periods[0]));
|
|
expect(run.selected()).toEqual({ periodo: periods[0], tipo: 'semestre' }); http.expectNone(() => true);
|
|
const cached = start(); expect(cached.selected()).toEqual(run.selected()); http.expectNone(() => true);
|
|
});
|
|
it.each(['zero', 'null', 'suppressed', 'incomplete', 'empty', 'group', 'stratum'])('omite %s sin convertirlo en cero y se detiene en el primer positivo', kind => {
|
|
const run = start(); inventory(); const first = request(periods[0]); http.expectNone(() => true);
|
|
first.flush(data(periods[0], kind)); expect(run.completed()).toBe(false);
|
|
request(periods[1]).flush(data(periods[1], 'zero')); request(periods[2]).flush(data(periods[2]));
|
|
expect(run.selected()?.periodo).toBe(periods[2]); http.expectNone(() => true);
|
|
});
|
|
it('conserva los identificadores y la población vigente del ancla, sin recuperar el ancla histórica', () => {
|
|
if (domain === 'cama') {
|
|
expect(anchor.id).toBe('cama_birads_456_paciente');
|
|
expect(anchor.title).toBe('Pacientes evaluadas con BI-RADS 4, 5 y 6');
|
|
expect(KPI_BY_DOMAIN.cama.map(d => d.id)).toEqual(['cama_birads_456_paciente', 'cama_eu38a']);
|
|
} else expect(anchor.id).toBe('cacu_eu7');
|
|
const run = start(); inventory(); request(periods[0]).flush(data(periods[0]));
|
|
expect(run.selected()?.periodo).toBe(periods[0]);
|
|
http.expectNone(r => r.url.includes('/cama_birads/'));
|
|
});
|
|
it('ningún positivo termina sin seleccionar un periodo arbitrario', () => {
|
|
const run = start(); inventory();
|
|
[periods[0], periods[1], periods[2]].forEach((p, i) => request(p).flush(data(p, ['suppressed', 'null', 'incomplete'][i])));
|
|
expect(run.completed()).toBe(true); expect(run.selected()).toBeUndefined(); http.expectNone(() => true);
|
|
});
|
|
it('inventario vacío es ausencia conocida sin consultas de datos', () => {
|
|
const run = start(); inventory([]); expect(run.completed()).toBe(true);
|
|
expect(run.selected()).toBeUndefined(); expect(run.failed()).toBe(false); http.expectNone(() => true);
|
|
});
|
|
it.each([404, 503])('HTTP %s durante datos interrumpe, no salta al pasado y puede reintentarse', status => {
|
|
const run = start(); inventory(); request(periods[0]).flush(data(periods[0], 'zero'));
|
|
request(periods[1]).flush({ error: 'private' }, { status, statusText: 'Failure' });
|
|
expect(run.failed()).toBe(true); expect(run.completed()).toBe(false); http.expectNone(() => true);
|
|
const retry = start(); request(periods[1]).flush(data(periods[1]));
|
|
expect(retry.selected()?.periodo).toBe(periods[1]); http.expectNone(() => true);
|
|
});
|
|
it('HTTP 404 del inventario es indeterminado, no ausencia conocida ni cero', () => {
|
|
const run = start(); http.expectOne(`/${domain}/indicadores/${anchor.id}/periodos`).flush('', { status: 404, statusText: 'Missing' });
|
|
expect(run.failed()).toBe(true); expect(run.completed()).toBe(false); http.expectNone(() => true);
|
|
});
|
|
it.each(['semestre', 'mes'] as const)('busca únicamente el intervalo de tiempo activo %s, sin mezclar tipos ni usar un mes más reciente', tipo => {
|
|
const run = start(tipo); inventory(['2026-12', '2025-10', '2026-S1', '2025-S2']);
|
|
const expected = tipo === 'mes' ? '2026-12' : '2026-S1'; request(expected).flush(data(expected));
|
|
expect(run.selected()).toEqual({ periodo: expected, tipo }); http.expectNone(() => true);
|
|
});
|
|
it('si solo hay meses no los usa para inicializar semestre', () => {
|
|
const run = start(); inventory(['2026-12']); expect(run.completed()).toBe(true);
|
|
expect(run.selected()).toBeUndefined(); http.expectNone(() => true);
|
|
});
|
|
it('cancelación descarta el recorrido y no retiene datos no resueltos', () => {
|
|
const run = start(); inventory(); const old = request(periods[0]); run.subscription.unsubscribe();
|
|
expect(old.cancelled).toBe(true); expect(() => old.flush(data(periods[0]))).toThrow();
|
|
const retry = start(); request(periods[0]).flush(data(periods[0])); expect(retry.selected()?.periodo).toBe(periods[0]);
|
|
});
|
|
});
|
|
|
|
it('el mecanismo rechaza como ancla una definición ajena a C2', () => {
|
|
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
|
|
let failed = false;
|
|
TestBed.inject(IndicadoresInitialPeriod).find('cacu', KPI_BY_DOMAIN.cacu[1], 'semestre').subscribe({ error: () => { failed = true; } });
|
|
expect(failed).toBe(true); TestBed.inject(HttpTestingController).expectNone(() => true);
|
|
});
|