import { describe, expect, it } from 'vitest'; import { dashboardAnalysis, dashboardResultState } from '../../src/features/dashboard/DashboardPanel'; import { makeSheet } from '../../src/importers/sheet-factory'; import { purpleKnightProfile } from '../../src/profiles/purple-knight/purple-knight-profile'; import { genericProfile } from '../../src/profiles/generic/generic-profile'; import { deriveDynamicFacets } from '../../src/features/search-filter/dynamic-facets'; describe('PurpleKnight dashboard status accounting', () => { it.each([purpleKnightProfile, genericProfile])('preserves native status distinctions with the $id profile', profile => { const statuses = ['Passed', 'IOE Found', 'Not Relevant', 'Not selected', 'Canceled', 'Failed to run', 'Unknown']; const sheet = makeSheet('Indicator Results', [ ['Name', 'Status'], ...statuses.map((status, index) => [`Synthetic check ${index}`, status]) ], '', 'synthetic.csv'); expect(sheet.analysis.records.map(record => dashboardResultState(record, profile))).toEqual([ 'passed', 'deviation', 'not-applicable', 'not-run', 'not-run', 'error', 'unknown' ]); }); it.each([ { passed: 95, failed: 20, irrelevant: 4, unselected: 0, eligible: 115, gaps: 0, coverage: 100 }, { passed: 96, failed: 19, irrelevant: 3, unselected: 1, eligible: 116, gaps: 1, coverage: 99 } ])('excludes $irrelevant irrelevant controls and retains $gaps actual gaps', counts => { const statuses = [ ...Array(counts.passed).fill('Passed'), ...Array(counts.failed).fill('IOE Found'), ...Array(counts.irrelevant).fill('Not Relevant'), ...Array(counts.unselected).fill('Not selected') ]; const sheet = makeSheet('Indicator Results', [ ['Name', 'Status'], ...statuses.map((status, index) => [`Synthetic check ${index}`, status]) ], '', 'synthetic.csv'); const before = JSON.stringify(sheet); const facets = deriveDynamicFacets(sheet, null, purpleKnightProfile, {}); const result = dashboardAnalysis(sheet, purpleKnightProfile, {}, facets); expect(result.totalResult).toMatchObject({ passed: counts.passed, deviations: counts.failed, assessed: 115, eligible: counts.eligible, unassessed: counts.gaps, coverage: counts.coverage }); expect(result.statusCount('not-relevant')).toBe(counts.irrelevant); expect(result.statusCount('not-selected')).toBe(counts.unselected); expect(JSON.stringify(sheet)).toBe(before); }); });