feat(cama): TEA tabs, follow-up list from announced columns and histopathology donut by BI-RADS category
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { provideHttpClient } from '@angular/common/http';
|
||||
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
||||
import eu7 from './fixtures/eu7-c2-ejemplos.json';
|
||||
import { Indicador, IndicadorDatos } from './indicadores.models';
|
||||
import { modelo, vistaEscenario } from './indicadores-eu7-escenario';
|
||||
import { IndicadoresTracking } from './indicadores-tracking';
|
||||
import { seguimientoTablaResponse } from './seguimiento-tabla.service';
|
||||
|
||||
// Covers what lets a domain reuse CaCu's views without code of its own: the interactive donut and bars
|
||||
// chosen by the catalog's `escenario`, and the follow-up list whose filters and columns come in the answer.
|
||||
// Fixtures: `eu7-c2-ejemplos.json` (CaCu's EU7 answers, relabelled here as another stratum) and `lista`,
|
||||
// a two-patient CaMa list built below.
|
||||
|
||||
// Two CaMa patients, one without a biopsy, with the filters and columns the list announces.
|
||||
const lista = () => ({
|
||||
simulado: true, corte: '2026-10-20', ventana: { meses: 3, desde: '2026-07-21', hasta: '2026-10-20' },
|
||||
filtros: { birads: null }, filtros_disponibles: [{ clave: 'birads', etiqueta: 'Categoría BI-RADS', opciones: [{ codigo: 'BIRADS_5', etiqueta: 'BI-RADS 5' }] }],
|
||||
columnas: [{ clave: 'id_seudonimo', etiqueta: 'Identificador seudónimo' },
|
||||
{ clave: 'birads', etiqueta: 'Última mastografía', detalles: [{ clave: 'mastografia_fecha', etiqueta: 'Fecha' }] },
|
||||
{ clave: 'biopsia', etiqueta: 'Resultado histopatológico' }],
|
||||
paginacion: { page: 1, page_size: 50, total_items: 2, total_pages: 1 },
|
||||
items: [{ id_seudonimo: 'M-0001', birads: 'BI-RADS 5', mastografia_fecha: '2026-09-01', biopsia: 'Carcinoma invasor' },
|
||||
{ id_seudonimo: 'M-0002', birads: 'BI-RADS 4A', mastografia_fecha: '2026-08-15', biopsia: null }],
|
||||
});
|
||||
|
||||
describe('Vista de dona y barras por estrato', () => {
|
||||
const item = (extra: Partial<Indicador> = {}): Indicador => ({ id: 'x', titulo: 'X', contrato: 'C2', figuras: [], tipos_periodo: ['semestre'], ...extra });
|
||||
it('la elige el campo escenario del catálogo, y CaCu EU7 la conserva sin él', () => {
|
||||
// Fails if the view goes back to being recognised by CaCu's indicator id only.
|
||||
expect(vistaEscenario('cama', item({ escenario: { estrato: 'birads', etiqueta: 'categoría BI-RADS' } }))?.estrato).toBe('birads');
|
||||
expect(vistaEscenario('cacu', item({ id: 'cacu_eu7' }))?.estrato).toBe('estatus_seguimiento');
|
||||
expect(vistaEscenario('cama', item())).toBeUndefined();
|
||||
});
|
||||
it('arma el modelo con otro indicador y otro estrato', () => {
|
||||
// Fails if `modelo` checks CaCu's id or its stratum instead of the ones it is given.
|
||||
const relabel = (d: unknown, estrato: string | null) => ({ ...structuredClone(d) as IndicadorDatos, id: 'cama_histopatologia_birads', ...(estrato ? { estrato } : {}) });
|
||||
const general = relabel(eu7.general, null), porBirads = relabel(eu7.estatus_seguimiento, 'birads');
|
||||
expect(modelo(general, porBirads, '2025-S2', 'birads').total).toBe(946);
|
||||
expect(() => modelo(general, porBirads, '2025-S2')).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Seguimiento con filtros y columnas anunciados', () => {
|
||||
let fixture: ReturnType<typeof TestBed.createComponent<IndicadoresTracking>>, http: HttpTestingController;
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
|
||||
fixture = TestBed.createComponent(IndicadoresTracking); http = TestBed.inject(HttpTestingController);
|
||||
fixture.componentRef.setInput('dominio', 'cama'); fixture.componentRef.setInput('domainLabel', 'CaMa');
|
||||
fixture.componentRef.setInput('active', true); fixture.detectChanges();
|
||||
});
|
||||
afterEach(() => { fixture.destroy(); http.verify(); });
|
||||
const text = () => fixture.nativeElement.textContent as string;
|
||||
|
||||
it('pinta las columnas, los detalles y los valores ausentes de la respuesta', () => {
|
||||
// Fails if CaMa stops querying its own list or the table stops following `columnas`.
|
||||
http.expectOne(r => r.url === '/cama/seguimiento').flush(lista()); fixture.detectChanges();
|
||||
const headers = Array.from(fixture.nativeElement.querySelectorAll('thead th')).map(e => (e as HTMLElement).textContent?.trim());
|
||||
expect(headers).toEqual(['Identificador seudónimo', 'Última mastografía', 'Resultado histopatológico']);
|
||||
expect(text()).toContain('Fecha: 2026-09-01');
|
||||
expect(fixture.nativeElement.querySelectorAll('tbody tr')[1].textContent).toContain('No disponible');
|
||||
});
|
||||
it('envía cada filtro anunciado con su clave y sin los vacíos', () => {
|
||||
// Fails if the announced filters stop reaching the query, or an empty choice is sent as a value.
|
||||
http.expectOne(r => r.url === '/cama/seguimiento').flush(lista()); fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('select[name="filtro-birads"]')).not.toBeNull();
|
||||
expect(fixture.nativeElement.querySelector('select[name="estatus"]')).toBeNull();
|
||||
fixture.componentInstance.filtrosDraft['birads'] = 'BIRADS_5'; fixture.componentInstance.apply();
|
||||
let req = http.expectOne(r => r.url === '/cama/seguimiento');
|
||||
expect(req.request.params.get('birads')).toBe('BIRADS_5');
|
||||
req.flush({ ...lista(), filtros: { birads: 'BIRADS_5' } });
|
||||
fixture.componentInstance.filtrosDraft['birads'] = ''; fixture.componentInstance.apply();
|
||||
req = http.expectOne(r => r.url === '/cama/seguimiento');
|
||||
expect(req.request.params.has('birads')).toBe(false);
|
||||
req.flush(lista());
|
||||
});
|
||||
it('sin lista publicada queda pendiente', () => {
|
||||
// Fails if a 404 on the first page is shown as an error instead of a list not yet published.
|
||||
http.expectOne(r => r.url === '/cama/seguimiento').flush({}, { status: 404, statusText: 'Not found' }); fixture.detectChanges();
|
||||
expect(text()).toContain('Funcionalidad pendiente de publicación');
|
||||
});
|
||||
it('solo admite datos de demostración y respuestas coherentes', () => {
|
||||
// Fails if the validation stops guarding the table from real records or from filters it didn't announce.
|
||||
expect(() => seguimientoTablaResponse({ ...lista(), simulado: false })).toThrow();
|
||||
expect(() => seguimientoTablaResponse({ ...lista(), filtros: { edad: '40-49' } })).toThrow();
|
||||
expect(() => seguimientoTablaResponse({ ...lista(), filtros_disponibles: [{ clave: 'page', etiqueta: 'X', opciones: [] }] })).toThrow();
|
||||
expect(() => seguimientoTablaResponse({ ...lista(), items: [{ birads: 'BI-RADS 5' }] })).toThrow();
|
||||
http.expectOne(r => r.url === '/cama/seguimiento').flush(lista());
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user