import { bars, Mode } from './bars'; import { BIOPSY_COLORS, CYTOLOGY_COLORS, HPV_COLORS, NEUTRAL, PPV_CYTOLOGY_COLORS, PPV_DONUT, PPV_LEVEL_COLORS, REQUEST_COLORS, ROUND_COLORS, STEEL, } from './cacu-palette'; import type { Measure } from 'fhir/r4'; import { donut, Reading } from './measures'; const VPH = { negative: HPV_COLORS['negative'], positive: HPV_COLORS['positive_other'] }; describe('CaCu palette', () => { it('a PPV group has the colour of its category elsewhere on the page', () => { expect(PPV_CYTOLOGY_COLORS['ascus_plus']).toBe(CYTOLOGY_COLORS['ASC-US']); expect(PPV_CYTOLOGY_COLORS['lsil_plus']).toBe(CYTOLOGY_COLORS['LSIL']); expect(PPV_CYTOLOGY_COLORS['hsil_plus']).toBe(CYTOLOGY_COLORS['HSIL']); expect(PPV_LEVEL_COLORS['cin1_plus']).toBe(BIOPSY_COLORS['LSIL']); expect(PPV_LEVEL_COLORS['cin2_plus']).toBe(BIOPSY_COLORS['HSIL']); expect(PPV_LEVEL_COLORS['carcinoma']).toBe(BIOPSY_COLORS['carcinoma']); expect(HPV_COLORS['hpv_16']).toBe(HPV_COLORS['positive_16']); expect(HPV_COLORS['hpv_18']).toBe(HPV_COLORS['positive_18']); expect(HPV_COLORS['positive']).toBe(HPV_COLORS['positive_other']); expect(REQUEST_COLORS['high_grade']).toBe(CYTOLOGY_COLORS['HSIL']); }); it('"Sin dato" and what is not classified are neutral everywhere', () => { for (const colors of [ CYTOLOGY_COLORS, HPV_COLORS, BIOPSY_COLORS, ROUND_COLORS, PPV_CYTOLOGY_COLORS, ]) expect(colors['no_data']).toBe(NEUTRAL); expect(REQUEST_COLORS['pending']).toBe(NEUTRAL); expect(PPV_DONUT['rest']).toBe(NEUTRAL); expect(ROUND_COLORS['initial']).toBe(STEEL); }); it('a donut colours by category, not by place in the report', () => { const measure = { scoring: { coding: [{ code: 'cohort' }] } } as unknown as Measure; const cells = (order: string[]): Reading => ({ populations: {}, strata: { category: Object.fromEntries(order.map((c) => [c, { 'initial-population': 1 }])) }, }); const colours = (order: string[]) => (donut(measure, cells(order), 'category', VPH).data[0] as any).marker.colors; expect(colours(['negative', 'positive'])).toEqual([VPH['negative'], VPH['positive']]); expect(colours(['positive', 'negative'])).toEqual([VPH['positive'], VPH['negative']]); }); it('bars take their colour from the mode by group, absent groups included', () => { const r: Reading = { populations: { 'initial-population': 5 }, strata: { round: { subsequent: { numerator: 1, denominator: 5 } } }, }; const mode: Mode = { kind: 'shares', label: 'x', measure: 'M', stratum: 'round', order: ['initial', 'subsequent', 'no_data'], complete: true, colors: ROUND_COLORS, }; expect(bars(mode, () => r)!.rows.map((x) => x.color)).toEqual([ ROUND_COLORS['initial'], ROUND_COLORS['subsequent'], ROUND_COLORS['no_data'], ]); }); });