From 6d45aaadf8763700f19e5860a438315bad036364 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 10 May 2026 03:56:08 +0200 Subject: [PATCH] test(persons): expand persons/[id] page coverage Co-correspondents derived from received-document senders, self-skip branch when sender == current person, GeschichtenCard rendered when geschichten array is non-empty, 5-entry cap on co-correspondents. 4 new tests covering ~10 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 --- .../routes/persons/[id]/page.svelte.test.ts | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/frontend/src/routes/persons/[id]/page.svelte.test.ts b/frontend/src/routes/persons/[id]/page.svelte.test.ts index ec8bf773..36d4575a 100644 --- a/frontend/src/routes/persons/[id]/page.svelte.test.ts +++ b/frontend/src/routes/persons/[id]/page.svelte.test.ts @@ -101,4 +101,77 @@ describe('persons/[id] page', () => { .element(page.getByRole('link', { name: /bearbeiten/i })) .toHaveAttribute('href', '/persons/p-1/edit'); }); + + it('renders co-correspondents derived from received documents senders', async () => { + const data = baseData({ + receivedDocuments: [ + { + id: 'd-r1', + title: 'R1', + status: 'UPLOADED', + sender: { id: 's1', displayName: 'Carl Brandt' } + }, + { + id: 'd-r2', + title: 'R2', + status: 'UPLOADED', + sender: { id: 's1', displayName: 'Carl Brandt' } + } + ] + }); + render(PersonDetailPage, { props: { data } }); + + expect(document.body.textContent).toContain('Carl Brandt'); + }); + + it('skips the sender when sender id equals the current person id (loops cleanly)', async () => { + const data = baseData({ + receivedDocuments: [ + { + id: 'd-self', + title: 'Self-letter', + status: 'UPLOADED', + sender: { id: 'p-1', displayName: 'Anna Schmidt' } + } + ] + }); + // Just verify the page renders without error — the self-skip branch is exercised + expect(() => render(PersonDetailPage, { props: { data } })).not.toThrow(); + }); + + it('renders the GeschichtenCard when geschichten array has items', async () => { + render(PersonDetailPage, { + props: { + data: baseData({ + geschichten: [ + { + id: 'g1', + title: 'Reise', + body: '

...

', + publishedAt: '2026-04-15T10:00:00Z' + } + ] + }) + } + }); + + expect(document.body.textContent).toContain('Reise'); + }); + + it('caps the co-correspondents list at 5 entries', async () => { + const sent = Array.from({ length: 8 }, (_, i) => ({ + id: `d-${i}`, + title: `Brief ${i}`, + status: 'UPLOADED', + receivers: [{ id: `r-${i}`, displayName: `Person ${i}` }] + })); + render(PersonDetailPage, { props: { data: baseData({ sentDocuments: sent }) } }); + + const correspondentsCard = Array.from(document.querySelectorAll('h2')).find((h) => + /korrespondenten/i.test(h.textContent ?? '') + )?.parentElement; + const links = correspondentsCard?.querySelectorAll('a[href^="/persons/"]') ?? []; + // At most 5 person links inside the card + expect(links.length).toBeLessThanOrEqual(5); + }); });