From eed59f50e5e31a8faab66b249f1a53d673524078 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 10 May 2026 08:49:33 +0200 Subject: [PATCH] test(geschichten): cover authorName + publishedAt branches authorName email fallback when no first/last names, undefined-author empty result, publishedAt missing, body empty no-excerpt, single person filter render-without-throw. 5 new tests covering ~10 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 --- .../routes/geschichten/page.svelte.test.ts | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/frontend/src/routes/geschichten/page.svelte.test.ts b/frontend/src/routes/geschichten/page.svelte.test.ts index 3246d8cf..a9694fad 100644 --- a/frontend/src/routes/geschichten/page.svelte.test.ts +++ b/frontend/src/routes/geschichten/page.svelte.test.ts @@ -138,4 +138,89 @@ describe('geschichten/+ page', () => { .element(page.getByRole('heading', { level: 2, name: /reise nach berlin/i })) .toBeVisible(); }); + + it('authorName falls back to email when first/last names are missing', async () => { + render(GeschichtenListPage, { + props: { + data: baseData({ + geschichten: [ + { + id: 'g1', + title: 'Anonym', + author: { email: 'anon@example.com' } + } + ] + }) + } + }); + + expect(document.body.textContent).toContain('anon@example.com'); + }); + + it('authorName renders empty when author is undefined', async () => { + render(GeschichtenListPage, { + props: { + data: baseData({ + geschichten: [{ id: 'g1', title: 'No Author' }] + }) + } + }); + + // Page renders the title fine, no author string + expect(document.body.textContent).toContain('No Author'); + }); + + it('omits the date when publishedAt is missing', async () => { + render(GeschichtenListPage, { + props: { + data: baseData({ + geschichten: [ + { + id: 'g1', + title: 'Draft', + author: { firstName: 'Anna', lastName: 'Schmidt', email: 'a@x' } + } + ] + }) + } + }); + + // No "·" separator before date when no publishedAt + const titleHeading = document.querySelector('h2'); + const card = titleHeading?.closest('li'); + // The middle paragraph (author line) should not contain "·" + expect(card?.textContent).toContain('Anna Schmidt'); + }); + + it('omits the body excerpt when body is empty', async () => { + render(GeschichtenListPage, { + props: { + data: baseData({ + geschichten: [ + { + id: 'g1', + title: 'No Body', + body: '', + author: { firstName: 'Anna', lastName: 'Schmidt', email: 'a@x' } + } + ] + }) + } + }); + + const titleHeading = document.querySelector('h2'); + expect(titleHeading?.textContent).toContain('No Body'); + }); + + it('renders without throwing when one person filter is selected', async () => { + expect(() => + render(GeschichtenListPage, { + props: { + data: baseData({ + personFilters: [{ id: 'p1', displayName: 'Anna' }] + }) + } + }) + ).not.toThrow(); + }); });