import { C2Distribution } from './indicadores-c2-adapter'; import { highlightFigure } from './indicadores-highlight'; import { teaC2Donut } from './indicadores-tea-c2'; const categoria = (id: string, label: string, value: number, color: string, parentId?: string) => ({ id, label, value, color, parentId }); const modelo = (extra: object = {}) => ({ period: '2025-S2', unit: 'paciente', title: 'T', total: 380, notes: [], nodes: [], parents: [], categories: [categoria('CONFIRMADO', 'Diagnóstico confirmado', 338, '#A8C243'), categoria('EN_PROCESO', 'En proceso', 42, '#B8433A')], ...extra }) as unknown as C2Distribution; describe('Dona C2 de TEA', () => { it('sin grupos dibuja un anillo con rótulos, el total al centro y un botón por categoría', () => { const { figure, highlight } = teaC2Donut(modelo(), 'claro', { text: 'T' })!; expect(figure.data).toHaveLength(1); expect(figure.data[0]).toMatchObject({ type: 'pie', values: [338, 42], labels: ['Diagnóstico confirmado', 'En proceso'] }); expect(figure.data[0]['text']).toEqual(['Diagnóstico confirmado
88.9 %', 'En proceso
11.1 %']); expect((figure.layout['annotations'] as { text: string }[])[0].text).toBe('380
TOTAL'); expect(highlight.groups).toEqual([]); expect(highlight.items.map(i => [i.label, i.color])).toEqual([['Diagnóstico confirmado', '#A8C243'], ['En proceso', '#B8433A']]); }); it('al elegir una categoría atenúa la otra y muestra su número al centro', () => { const { figure, highlight } = teaC2Donut(modelo(), 'claro', { text: 'T' })!; const elegida = highlightFigure(figure, highlight, { item: 'EN_PROCESO' }); expect((elegida.data[0]['marker'] as { colors: string[] }).colors).toEqual(['rgba(168, 194, 67, 0.3)', 'rgba(184,67,58,1)']); expect((elegida.layout['annotations'] as { text: string }[])[0].text).toBe('42
En proceso'); }); it('sin pacientes no dibuja nada', () => { expect(teaC2Donut(modelo({ total: 0 }), 'claro', {})).toBeUndefined(); }); });