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); + }); });