diff --git a/src/app/features/indicadores/screening-route.spec.ts b/src/app/features/indicadores/screening-route.spec.ts index 090b023..bd397c0 100644 --- a/src/app/features/indicadores/screening-route.spec.ts +++ b/src/app/features/indicadores/screening-route.spec.ts @@ -42,6 +42,13 @@ describe('Ruta del tamizaje: modelo', () => { expect(routeModel(all(), 'semestre', '2025-S1').period).toBe('2025-S1'); expect(routeModel(all(), 'semestre', '2024-S1').period).toBe('2025-S2'); }); + it('sin periodo pedido, el más reciente vacío no se elige: se usa el más reciente con cajas publicadas', () => { + // Fails if the chart opens on a semester that has just begun and shows nothing while an earlier one has data. + const vacio = (id: string) => payload(id, [row('2025-S2', S2[id]), row('2026-S1', [0, null as never, null as never, null as never], { suprimido: 1 })], ['2025-S2', '2026-S1']); + const data = Object.fromEntries(ROUTE_IDS.map(id => [id, vacio(id)])); + expect(routeModel(data, 'semestre').period).toBe('2025-S2'); + expect(routeModel(data, 'semestre', '2026-S1').period).toBe('2026-S1'); + }); it('un paso suprimido o sin datos no se dibuja y la cadena sigue desde el último publicado', () => { // Pins down: nothing is drawn as zero and the next step starts at the last published end. Fails if a suppressed box // becomes a bar or leaves a gap in the chain. diff --git a/src/app/features/indicadores/screening-route.ts b/src/app/features/indicadores/screening-route.ts index d782659..0f8f768 100644 --- a/src/app/features/indicadores/screening-route.ts +++ b/src/app/features/indicadores/screening-route.ts @@ -66,7 +66,9 @@ export function routeModel(data: Record, tipo: TipoPerio } } const periods = [...new Set(ROUTE_IDS.flatMap(id => data[id].periodos))].sort().reverse(); - const period = requested && periods.includes(requested) ? requested : periods[0]; + // Without a valid request the newest period that has a published box: a semester that has just begun is empty. + const hasData = (p: string) => ROUTE_IDS.some(id => boxes[id][p]?.estado === 'Publicado'); + const period = requested && periods.includes(requested) ? requested : periods.find(hasData) ?? periods[0]; let cursor = 0; const rows = ROUTE_STEPS.map((step): RouteRow => { const fromSample = period ? boxes[step.sinceSample][period] ?? NOT_AVAILABLE : NOT_AVAILABLE;