import { describe, it, expect } from 'vitest'; import { statusLabel, detailRows, TYPE_LABELS } from './beoordeling-view'; import { BeoordelingView } from './beoordeling'; const base: Omit = { id: '1', type: 'herregistratie', owner: '*****2333', submittedAt: '2024-05-12', documenten: [], canBesluiten: true, }; describe('statusLabel', () => { it('labels every tag distinctly', () => { const labels = [ statusLabel({ tag: 'Ingediend', referentie: 'R1' }), statusLabel({ tag: 'InBehandeling', referentie: 'R1', manual: false }), statusLabel({ tag: 'InBehandeling', referentie: 'R1', manual: true }), statusLabel({ tag: 'MeerInfoGevraagd', referentie: 'R1', reden: 'x' }), statusLabel({ tag: 'Goedgekeurd', referentie: 'R1' }), statusLabel({ tag: 'Afgewezen', referentie: 'R1', reden: 'x' }), ]; expect(new Set(labels).size).toBe(labels.length); }); }); describe('detailRows', () => { it('lists soort/status/referentie/eigenaar/ingediend', () => { // Given a case InBehandeling. // When its detail rows are derived... const rows = detailRows({ ...base, status: { tag: 'InBehandeling', referentie: 'R1', manual: false }, }); const values = rows.map((r) => r.value); // Then the type label (via TYPE_LABELS, not a literal), the reference, and the // owner all appear as rows. expect(values).toContain(TYPE_LABELS.herregistratie); expect(values).toContain('R1'); expect(values).toContain(base.owner); expect(rows.length).toBe(5); }); // One behaviour ("a reden row is added exactly for the two statuses that carry a // reden") checked as a truth table over three statuses — kept together per // bdd.mdx's "truth-table of one rule" exception, rather than split apart. // // `reden` itself is raw domain data (a free-text field on the status union, not an // enum), passed through `detailRows` unchanged and never wrapped by `$localize` — // there is no reason-code/tag to assert on instead; the value under test IS the // string the Given supplied, so checking it reappears in the Then is a // pass-through check, not a translated-copy assertion. it('a reden row is present only for Afgewezen and MeerInfoGevraagd', () => { // Given three cases: rejected, more-info-requested, and approved. // When their detail rows are derived... const afgewezen = detailRows({ ...base, status: { tag: 'Afgewezen', referentie: 'R1', reden: 'Onvoldoende uren' }, }); const meerInfo = detailRows({ ...base, status: { tag: 'MeerInfoGevraagd', referentie: 'R1', reden: 'Diploma ontbreekt' }, }); const goedgekeurd = detailRows({ ...base, status: { tag: 'Goedgekeurd', referentie: 'R1' } }); // Then only the rejected and more-info-requested cases gain a reden row (carrying // the reason through unchanged); the approved case does not. expect(afgewezen.length).toBe(6); expect(afgewezen.map((r) => r.value)).toContain('Onvoldoende uren'); expect(meerInfo.length).toBe(6); expect(goedgekeurd.length).toBe(5); }); });