test(lesereisen): TDD red — tighten factories, add journey/selector/ssr tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,23 +3,26 @@ import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page } from 'vitest/browser';
|
||||
|
||||
import { createConfirmService, CONFIRM_KEY } from '$lib/shared/services/confirm.svelte.js';
|
||||
import type { components } from '$lib/generated/api';
|
||||
|
||||
const { default: GeschichtePage } = await import('./+page.svelte');
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
const baseGeschichte = (overrides: Record<string, unknown> = {}) => ({
|
||||
type GeschichteView = components['schemas']['GeschichteView'];
|
||||
|
||||
const baseGeschichte = (overrides: Partial<GeschichteView> = {}): GeschichteView => ({
|
||||
id: 'g1',
|
||||
title: 'Die Reise nach Berlin',
|
||||
body: '<p>Im Jahr 1923 fuhr Helene...</p>',
|
||||
publishedAt: '2026-04-15T10:00:00Z' as string | null,
|
||||
author: { firstName: 'Anna', lastName: 'Schmidt', email: 'anna@example.com' } as {
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
email: string;
|
||||
} | null,
|
||||
persons: [] as { id: string; displayName: string }[],
|
||||
items: [] as { id: string; documentId?: string; position: number; note?: string }[],
|
||||
type: 'STORY',
|
||||
status: 'PUBLISHED',
|
||||
author: { id: 'u1', displayName: 'Anna Schmidt' },
|
||||
persons: [],
|
||||
items: [],
|
||||
createdAt: '2026-01-01T00:00:00Z',
|
||||
updatedAt: '2026-01-01T00:00:00Z',
|
||||
publishedAt: '2026-04-15T10:00:00Z',
|
||||
...overrides
|
||||
});
|
||||
|
||||
@@ -55,9 +58,7 @@ describe('geschichten/[id] page', () => {
|
||||
context: new Map([[CONFIRM_KEY, createConfirmService()]]),
|
||||
props: {
|
||||
data: baseData({
|
||||
geschichte: baseGeschichte({
|
||||
author: { firstName: undefined, lastName: undefined, email: 'fallback@example.com' }
|
||||
})
|
||||
geschichte: baseGeschichte({ author: { id: 'u2', displayName: 'fallback@example.com' } })
|
||||
})
|
||||
}
|
||||
});
|
||||
@@ -65,10 +66,10 @@ describe('geschichten/[id] page', () => {
|
||||
await expect.element(page.getByText(/fallback@example.com/)).toBeVisible();
|
||||
});
|
||||
|
||||
it('renders an empty author when author is null', async () => {
|
||||
it('renders an empty author when author is absent', async () => {
|
||||
render(GeschichtePage, {
|
||||
context: new Map([[CONFIRM_KEY, createConfirmService()]]),
|
||||
props: { data: baseData({ geschichte: baseGeschichte({ author: null }) }) }
|
||||
props: { data: baseData({ geschichte: baseGeschichte({ author: undefined }) }) }
|
||||
});
|
||||
|
||||
await expect.element(page.getByRole('heading', { level: 1 })).toBeVisible();
|
||||
@@ -86,7 +87,9 @@ describe('geschichten/[id] page', () => {
|
||||
it('omits the publishedAt suffix when publishedAt is null', async () => {
|
||||
render(GeschichtePage, {
|
||||
context: new Map([[CONFIRM_KEY, createConfirmService()]]),
|
||||
props: { data: baseData({ geschichte: baseGeschichte({ publishedAt: null }) }) }
|
||||
props: {
|
||||
data: baseData({ geschichte: baseGeschichte({ publishedAt: undefined }) })
|
||||
}
|
||||
});
|
||||
|
||||
await expect.element(page.getByText(/veröffentlicht am/i)).not.toBeInTheDocument();
|
||||
@@ -108,8 +111,8 @@ describe('geschichten/[id] page', () => {
|
||||
data: baseData({
|
||||
geschichte: baseGeschichte({
|
||||
persons: [
|
||||
{ id: 'p1', displayName: 'Helene Schmidt' },
|
||||
{ id: 'p2', displayName: 'Karl Müller' }
|
||||
{ id: 'p1', firstName: 'Helene', lastName: 'Schmidt' },
|
||||
{ id: 'p2', firstName: 'Karl', lastName: 'Müller' }
|
||||
]
|
||||
})
|
||||
})
|
||||
@@ -136,7 +139,14 @@ describe('geschichten/[id] page', () => {
|
||||
props: {
|
||||
data: baseData({
|
||||
geschichte: baseGeschichte({
|
||||
items: [{ id: 'item1', documentId: 'd1', position: 0, note: 'Brief aus 1923' }]
|
||||
items: [
|
||||
{
|
||||
id: 'item1',
|
||||
position: 0,
|
||||
document: { id: 'd1', title: 'Brief 1923', datePrecision: 'FULL' },
|
||||
note: 'Brief aus 1923'
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -168,4 +178,31 @@ describe('geschichten/[id] page', () => {
|
||||
await expect.element(page.getByRole('link', { name: /bearbeiten/i })).not.toBeInTheDocument();
|
||||
await expect.element(page.getByRole('button', { name: /löschen/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('STORY with items:[] renders rich-text body and no empty-state message', async () => {
|
||||
render(GeschichtePage, {
|
||||
context: new Map([[CONFIRM_KEY, createConfirmService()]]),
|
||||
props: { data: baseData({ geschichte: baseGeschichte({ type: 'STORY', items: [] }) }) }
|
||||
});
|
||||
|
||||
await expect.element(page.getByText(/Im Jahr 1923/)).toBeVisible();
|
||||
await expect.element(page.getByText(/Diese Lesereise ist noch leer/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('type:undefined + non-empty body renders StoryReader and no empty-state', async () => {
|
||||
render(GeschichtePage, {
|
||||
context: new Map([[CONFIRM_KEY, createConfirmService()]]),
|
||||
props: {
|
||||
data: baseData({
|
||||
geschichte: baseGeschichte({
|
||||
type: undefined as unknown as 'STORY' | 'JOURNEY',
|
||||
items: []
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
await expect.element(page.getByText(/Im Jahr 1923/)).toBeVisible();
|
||||
await expect.element(page.getByText(/Diese Lesereise ist noch leer/)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user