Screening route: without a requested period, open on the newest one that has published boxes
A semester that has just begun has no events and the chart opened on it, empty, while earlier ones had data. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -66,7 +66,9 @@ export function routeModel(data: Record<string, IndicadorDatos>, 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;
|
||||
|
||||
Reference in New Issue
Block a user