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 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-10 08:49:33 +02:00
parent 9571e4a0bf
commit eed59f50e5

View File

@@ -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();
});
});