feaed5ff0e
An input's max only flags the field and still lets a larger number be typed. The follow-up table and the tracking
list now clamp the value when it changes and when the query is sent, and both read the single PAGE_SIZE_MAX instead
of a literal 200.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
(cherry picked from commit 1342b1712d)
148 lines
9.1 KiB
TypeScript
148 lines
9.1 KiB
TypeScript
// Covers the generic follow-up client: what it sends, and which answers it accepts. The fixture is the answer
|
|
// the reference prototype serves for CaMa (fixtures/cama_seguimiento.json): synthetic records, 27 of them,
|
|
// with the seven columns, four announced filters and the pagination block. It is only used by tests.
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { provideHttpClient } from '@angular/common/http';
|
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
|
import fixtureData from './fixtures/cama_seguimiento.json';
|
|
import finalResponse from './fixtures/cama_seguimiento-final.json';
|
|
import outsideResponse from './fixtures/cama_seguimiento-out-of-range.json';
|
|
import { acotarTamano, PAGE_SIZE_MAX, SeguimientoInvalido, SeguimientoTablaQuery, SeguimientoTablaResponse, SeguimientoTablaService, seguimientoTablaResponse, validQuery } from './seguimiento-tabla.service';
|
|
|
|
const clonar = () => structuredClone(fixtureData) as unknown as Record<string, any>;
|
|
const consulta: SeguimientoTablaQuery = { meses: 3, page: 1, page_size: 50 };
|
|
|
|
describe('Seguimiento genérico: respuesta', () => {
|
|
it('accepts final API responses, including an out-of-range HTTP 200 page', () => {
|
|
// These responses come from the API endpoint, not the prototype's 27-row fixture.
|
|
const page = seguimientoTablaResponse(structuredClone(finalResponse));
|
|
expect(page.simulado).toBe(true);
|
|
expect(page.columnas).toHaveLength(7);
|
|
expect(page.filtros_disponibles.map(f => f.clave)).toEqual(['estatus', 'birads', 'grupo_edad', 'prioridad']);
|
|
expect(page.items).toHaveLength(5);
|
|
const outside = seguimientoTablaResponse(structuredClone(outsideResponse));
|
|
expect(outside.items).toEqual([]);
|
|
expect(outside.paginacion).toEqual({ page: 4, page_size: 1, total_items: 3, total_pages: 3 });
|
|
});
|
|
it('acepta la respuesta del prototipo: siete columnas, cuatro filtros, 27 registros y la paginación', () => {
|
|
const r = seguimientoTablaResponse(clonar()) as SeguimientoTablaResponse;
|
|
expect(r.columnas.map(c => c.clave)).toEqual(['id_seudonimo', 'grupo_edad', 'estatus', 'birads', 'biopsia', 'dias_mastografia_diagnostico', 'prioridad']);
|
|
expect(r.columnas.filter(c => c.detalles).map(c => [c.clave, c.detalles!.map(d => d.clave)])).toEqual([['birads', ['mastografia_fecha']], ['biopsia', ['biopsia_fecha']]]);
|
|
expect(r.filtros_disponibles.map(f => f.clave)).toEqual(['estatus', 'birads', 'grupo_edad', 'prioridad']);
|
|
expect(r.filtros_disponibles.map(f => f.opciones.length)).toEqual([5, 5, 4, 3]);
|
|
expect(r.paginacion).toEqual({ page: 1, page_size: 50, total_items: 27, total_pages: 1 });
|
|
expect(r.items).toHaveLength(27);
|
|
expect(r.ventana).toEqual({ meses: 3, desde: '2026-07-21', hasta: '2026-10-20' });
|
|
});
|
|
it('los valores null (sin biopsia) son válidos y no se convierten en otra cosa', () => {
|
|
const r = seguimientoTablaResponse(clonar());
|
|
const sinBiopsia = r.items.find(i => i['biopsia'] === null)!;
|
|
expect(sinBiopsia['biopsia_fecha']).toBeNull(); expect(sinBiopsia['dias_mastografia_diagnostico']).toBeNull();
|
|
});
|
|
it('los campos extra de la respuesta (campo_ventana, códigos) no estorban', () => {
|
|
const r = seguimientoTablaResponse(clonar());
|
|
expect(r.items[0]).toHaveProperty('estatus_codigo');
|
|
});
|
|
it('una página vacía y una lista de opciones vacía son válidas', () => {
|
|
const d = clonar(); d['items'] = []; d['paginacion'] = { page: 1, page_size: 50, total_items: 0, total_pages: 1 }; d['filtros_disponibles'][0].opciones = [];
|
|
expect(seguimientoTablaResponse(d).items).toEqual([]);
|
|
});
|
|
it.each([
|
|
['sin el marcador de demostración', (d: any) => { delete d.simulado; }],
|
|
['simulado distinto de true', (d: any) => { d.simulado = 'true'; }],
|
|
['simulado falso', (d: any) => { d.simulado = false; }],
|
|
['corte que no es una fecha real', (d: any) => { d.corte = '2026-13-45'; }],
|
|
['ventana de 7 meses', (d: any) => { d.ventana.meses = 7; }],
|
|
['ventana con fecha inválida', (d: any) => { d.ventana.hasta = '2026-02-30'; }],
|
|
['página 0', (d: any) => { d.paginacion.page = 0; }],
|
|
['tamaño de página mayor que 200', (d: any) => { d.paginacion.page_size = PAGE_SIZE_MAX + 1; }],
|
|
['total negativo', (d: any) => { d.paginacion.total_items = -1; }],
|
|
['más ítems que el tamaño de página', (d: any) => { d.paginacion.page_size = 5; }],
|
|
['sin columnas', (d: any) => { d.columnas = []; }],
|
|
['columna sin etiqueta', (d: any) => { d.columnas[1].etiqueta = ''; }],
|
|
['filtro con clave reservada', (d: any) => { d.filtros_disponibles[0].clave = 'corte'; }],
|
|
['filtro con clave inválida', (d: any) => { d.filtros_disponibles[0].clave = 'Estatus Seguimiento'; }],
|
|
['filtros repetidos', (d: any) => { d.filtros_disponibles[1].clave = 'estatus'; }],
|
|
['opción sin código', (d: any) => { d.filtros_disponibles[0].opciones[0].codigo = ''; }],
|
|
['filtro activo que no se anunció', (d: any) => { d.filtros['otro'] = 'x'; }],
|
|
['filtro activo que no es texto', (d: any) => { d.filtros['estatus'] = 3; }],
|
|
['ítem sin identificador', (d: any) => { delete d.items[0].id_seudonimo; }],
|
|
['ítem con un valor que no es escalar', (d: any) => { d.items[0].biopsia = { x: 1 }; }],
|
|
['ítem con un número no finito', (d: any) => { d.items[0].dias_mastografia_diagnostico = Infinity; }],
|
|
['ítems que no son una lista', (d: any) => { d.items = {}; }],
|
|
])('rechaza la respuesta con %s', (_nombre, daño) => {
|
|
// Fails if a response outside the contract reaches the view.
|
|
const d = clonar(); daño(d);
|
|
expect(() => seguimientoTablaResponse(d)).toThrow(SeguimientoInvalido);
|
|
});
|
|
it('rechaza lo que no es un objeto', () => {
|
|
for (const v of [null, undefined, 'x', 3, []]) expect(() => seguimientoTablaResponse(v)).toThrow(SeguimientoInvalido);
|
|
});
|
|
});
|
|
|
|
describe('Seguimiento genérico: petición', () => {
|
|
it('valida la consulta antes de enviarla', () => {
|
|
expect(validQuery(consulta)).toBe(true);
|
|
expect(validQuery({ ...consulta, meses: 7 as never })).toBe(false);
|
|
expect(validQuery({ ...consulta, page: 0 })).toBe(false);
|
|
expect(validQuery({ ...consulta, page_size: 0 })).toBe(false);
|
|
expect(validQuery({ ...consulta, page_size: 201 })).toBe(false);
|
|
expect(validQuery({ ...consulta, corte: '2026-02-30' })).toBe(false);
|
|
expect(validQuery({ ...consulta, corte: '2026-10-20' })).toBe(true);
|
|
expect(validQuery({ ...consulta, filtros: { meses: 'x' } })).toBe(false);
|
|
expect(validQuery({ ...consulta, filtros: { 'a b': 'x' } })).toBe(false);
|
|
});
|
|
|
|
describe('HTTP', () => {
|
|
let service: SeguimientoTablaService, http: HttpTestingController;
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting()] });
|
|
service = TestBed.inject(SeguimientoTablaService); http = TestBed.inject(HttpTestingController);
|
|
});
|
|
afterEach(() => http.verify());
|
|
it('pide /cama/seguimiento con la ventana, la página, el tamaño, el corte y solo los filtros con valor', () => {
|
|
let respuesta: SeguimientoTablaResponse | undefined;
|
|
service.consultar('cama', { ...consulta, corte: '2026-10-20', filtros: { estatus: 'CANCER_CONFIRMADO', birads: undefined, grupo_edad: '' } }).subscribe(r => respuesta = r);
|
|
const r = http.expectOne(req => req.url === '/cama/seguimiento');
|
|
expect(r.request.method).toBe('GET');
|
|
expect(r.request.params.keys().sort()).toEqual(['corte', 'estatus', 'meses', 'page', 'page_size']);
|
|
expect(r.request.params.get('estatus')).toBe('CANCER_CONFIRMADO');
|
|
r.flush(clonar());
|
|
expect(respuesta?.items).toHaveLength(27);
|
|
});
|
|
it('sin corte ni filtros solo envía ventana, página y tamaño', () => {
|
|
service.consultar('cama', consulta).subscribe();
|
|
const r = http.expectOne(req => req.url === '/cama/seguimiento');
|
|
expect(r.request.params.keys().sort()).toEqual(['meses', 'page', 'page_size']);
|
|
r.flush(clonar());
|
|
});
|
|
it('una consulta inválida no llega a la red', () => {
|
|
expect(() => service.consultar('cama', { ...consulta, page_size: 500 })).toThrow(SeguimientoInvalido);
|
|
http.expectNone(() => true);
|
|
});
|
|
it('una respuesta fuera de contrato falla en el flujo, no se entrega', () => {
|
|
const d = clonar(); d['simulado'] = false;
|
|
let error: unknown;
|
|
service.consultar('cama', consulta).subscribe({ error: e => error = e });
|
|
http.expectOne(req => req.url === '/cama/seguimiento').flush(d);
|
|
expect(error).toBeInstanceOf(SeguimientoInvalido);
|
|
});
|
|
it('un dominio que no existe se rechaza', () => {
|
|
expect(() => service.consultar('otro' as never, consulta)).toThrow();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('acotarTamano', () => {
|
|
it('brings a typed page size into 1 to the maximum, and falls back when it is not a number', () => {
|
|
expect(acotarTamano(500)).toBe(PAGE_SIZE_MAX);
|
|
expect(acotarTamano('999')).toBe(PAGE_SIZE_MAX);
|
|
expect(acotarTamano(0)).toBe(1);
|
|
expect(acotarTamano(-7)).toBe(1);
|
|
expect(acotarTamano(25.9)).toBe(25);
|
|
expect(acotarTamano('')).toBe(1);
|
|
expect(acotarTamano('x')).toBe(50);
|
|
expect(acotarTamano(undefined, 20)).toBe(20);
|
|
});
|
|
});
|