46 lines
3.2 KiB
TypeScript
46 lines
3.2 KiB
TypeScript
import { figureTitle, presentationFigure } from './indicadores.presentation';
|
|
import { FigureSelection, PlotlyFigure } from './indicadores.models';
|
|
|
|
const selection: FigureSelection = { dominio: 'cacu', figura: 'fig_c1_puntos', indicador: 'x', tipoPeriodo: 'mes', tema: 'claro' };
|
|
const monthly: PlotlyFigure = {
|
|
data: [{ type: 'scatter', mode: 'markers', x: ['2025-03', '2025-01', '2025-02'], y: [100, null, 0], customdata: [[1, 1], [null, null], [0, 1]] }],
|
|
layout: { title: { text: 'Título completo<br>con contexto', font: { size: 18 } }, xaxis: { gridcolor: 'gray' }, annotations: [{ text: 'Nota' }] },
|
|
frames: [{ name: 'original' }], config: { displayModeBar: true }, future: { preserved: true },
|
|
};
|
|
describe('Dashboard presentation', () => {
|
|
it.each(['cacu', 'cama'] as const)('ordena ticks mensuales de %s sin cambiar observaciones ni HTTP', dominio => {
|
|
const original = structuredClone(monthly);
|
|
const adapted = presentationFigure(monthly, { ...selection, dominio });
|
|
expect(monthly).toEqual(original);
|
|
expect(adapted.data).toEqual(original.data);
|
|
expect(adapted.data).not.toBe(monthly.data);
|
|
expect(adapted.frames).toEqual(original.frames);
|
|
expect(adapted.config).toEqual(original.config);
|
|
expect(adapted['future']).toEqual(original['future']);
|
|
expect(adapted.layout['annotations']).toEqual(original.layout['annotations']);
|
|
expect(adapted.layout['xaxis']).toEqual({ gridcolor: 'gray', type: 'category', categoryorder: 'array', categoryarray: ['2025-01', '2025-02', '2025-03'], tickmode: 'array', tickvals: ['2025-01', '2025-02', '2025-03'], ticktext: ['2025-01', '2025-02', '2025-03'], tickangle: 0, automargin: true });
|
|
expect(figureTitle(monthly, 'catálogo')).toBe('Título completo<br>con contexto');
|
|
expect(adapted.layout['title']).toEqual({ text: '', font: { size: 18 } });
|
|
});
|
|
it.each(['fig_c1_grupos', 'fig_c2_apiladas', 'fig_c3r_caja'])('preserva ejes y trazas de %s', figura => {
|
|
const adapted = presentationFigure(monthly, { ...selection, figura });
|
|
expect(adapted.layout['xaxis']).toEqual(monthly.layout['xaxis']);
|
|
expect(adapted.data).toEqual(monthly.data);
|
|
});
|
|
it('conserva semestres, TEA, representaciones binarias y figuras vacías', () => {
|
|
for (const input of [monthly, { data: [], layout: {} }, { data: [{ type: 'scatter', mode: 'markers', x: ['2025-S1', '2025-S2'], y: { dtype: 'f8', bdata: 'AAAAAAAAVEAAAAAAAABJQA==' } }], layout: { xaxis: { type: 'category' } } }] as PlotlyFigure[]) {
|
|
const original = structuredClone(input);
|
|
for (const request of [{ ...selection, tipoPeriodo: 'semestre' as const }, { ...selection, dominio: 'tea' as const }, selection]) {
|
|
const adapted = presentationFigure(input, request);
|
|
expect(adapted.data).toEqual(original.data);
|
|
if (input !== monthly || request !== selection) expect(adapted.layout['xaxis']).toEqual(original.layout['xaxis']);
|
|
}
|
|
expect(input).toEqual(original);
|
|
}
|
|
});
|
|
it('conserva títulos string y usa catálogo cuando no hay título', () => {
|
|
expect(figureTitle({ data: [], layout: { title: 'Título completo' } }, 'fallback')).toBe('Título completo');
|
|
expect(figureTitle({ data: [], layout: { title: { text: '' } } }, 'Catálogo')).toBe('Catálogo');
|
|
});
|
|
});
|