From ccdf358b406a63bcf40958ce9f21d9b15a280caf Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 8 Jun 2026 12:40:17 +0200 Subject: [PATCH] test(frontend): fix Geschichte component specs for GeschichteType and JourneyItem model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GeschichteEditor.svelte.spec.ts: remove docFactory + initialDocuments test; rename documentIds test to personIds-only; add familyMember+provisional to personFactory (were pre-existing omissions) - GeschichtenCard.svelte.spec.ts: add type:'STORY', replace documents:[] with items:[], change body null→undefined to match Geschichte schema - GeschichtenCard.svelte.test.ts: add status/type/createdAt/updatedAt to factory; cast result as Geschichte to avoid spread-widening type inference Co-Authored-By: Claude Sonnet 4.6 --- .../GeschichteEditor.svelte.spec.ts | 31 ++++------------ .../geschichte/GeschichtenCard.svelte.spec.ts | 5 +-- .../geschichte/GeschichtenCard.svelte.test.ts | 35 ++++++++++++++----- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/frontend/src/lib/geschichte/GeschichteEditor.svelte.spec.ts b/frontend/src/lib/geschichte/GeschichteEditor.svelte.spec.ts index 3593af8e..e40a6b31 100644 --- a/frontend/src/lib/geschichte/GeschichteEditor.svelte.spec.ts +++ b/frontend/src/lib/geschichte/GeschichteEditor.svelte.spec.ts @@ -8,19 +8,9 @@ const personFactory = (id: string, displayName: string) => ({ firstName: displayName.split(' ')[0], lastName: displayName.split(' ').slice(1).join(' ') || displayName, displayName, - personType: 'PERSON' as const -}); - -const docFactory = (id: string, title: string, date = '1882-01-01') => ({ - id, - title, - documentDate: date, - originalFilename: `${title}.pdf`, - status: 'UPLOADED' as const, - metadataComplete: false, - scriptType: 'UNKNOWN' as const, - createdAt: '2024-01-01T00:00:00', - updatedAt: '2024-01-01T00:00:00' + personType: 'PERSON' as const, + familyMember: false, + provisional: false }); const draftFactory = (overrides: Record = {}) => ({ @@ -28,8 +18,9 @@ const draftFactory = (overrides: Record = {}) => ({ title: 'Existing draft', body: '

Hello world

', status: 'DRAFT' as const, + type: 'STORY' as const, persons: [], - documents: [], + items: [], createdAt: '2024-01-01T00:00:00', updatedAt: '2024-01-01T00:00:00', ...overrides @@ -93,14 +84,6 @@ describe('GeschichteEditor — pre-fill', () => { await expect.element(page.getByText('Franz Raddatz')).toBeInTheDocument(); }); - it('renders initial documents as chips', async () => { - render(GeschichteEditor, { - initialDocuments: [docFactory('d1', 'Brief von Eugenie')], - onSubmit: vi.fn() - }); - await expect.element(page.getByText(/Brief von Eugenie/)).toBeInTheDocument(); - }); - it('populates the title input from a geschichte prop', async () => { render(GeschichteEditor, { geschichte: draftFactory({ title: 'My existing story' }), @@ -154,11 +137,10 @@ describe('GeschichteEditor — onSubmit payload', () => { expect(onSubmit.mock.calls[0][0].status).toBe('PUBLISHED'); }); - it('passes the personIds and documentIds from initial props through onSubmit', async () => { + it('passes personIds from initial props through onSubmit', async () => { const onSubmit = vi.fn().mockResolvedValue(undefined); render(GeschichteEditor, { initialPersons: [personFactory('p1', 'Franz Raddatz')], - initialDocuments: [docFactory('d1', 'Brief A')], onSubmit }); @@ -171,6 +153,5 @@ describe('GeschichteEditor — onSubmit payload', () => { expect(onSubmit).toHaveBeenCalledTimes(1); const payload = onSubmit.mock.calls[0][0]; expect(payload.personIds).toEqual(['p1']); - expect(payload.documentIds).toEqual(['d1']); }); }); diff --git a/frontend/src/lib/geschichte/GeschichtenCard.svelte.spec.ts b/frontend/src/lib/geschichte/GeschichtenCard.svelte.spec.ts index c73f66d9..90e3bdb7 100644 --- a/frontend/src/lib/geschichte/GeschichtenCard.svelte.spec.ts +++ b/frontend/src/lib/geschichte/GeschichtenCard.svelte.spec.ts @@ -3,16 +3,17 @@ import { cleanup, render } from 'vitest-browser-svelte'; import { page } from 'vitest/browser'; import GeschichtenCard from './GeschichtenCard.svelte'; -const makeStory = (id: string, title: string, body: string | null = '

Body

') => ({ +const makeStory = (id: string, title: string, body: string | undefined = '

Body

') => ({ id, title, body, status: 'PUBLISHED' as const, + type: 'STORY' as const, publishedAt: '2024-04-01T12:00:00', createdAt: '2024-03-01T12:00:00', updatedAt: '2024-04-01T12:00:00', persons: [], - documents: [], + items: [], author: { id: 'u1', email: 'marcel@example.com', diff --git a/frontend/src/lib/geschichte/GeschichtenCard.svelte.test.ts b/frontend/src/lib/geschichte/GeschichtenCard.svelte.test.ts index e3212cbf..f61b4156 100644 --- a/frontend/src/lib/geschichte/GeschichtenCard.svelte.test.ts +++ b/frontend/src/lib/geschichte/GeschichtenCard.svelte.test.ts @@ -2,17 +2,36 @@ import { describe, it, expect, afterEach } from 'vitest'; import { cleanup, render } from 'vitest-browser-svelte'; import { page } from 'vitest/browser'; import GeschichtenCard from './GeschichtenCard.svelte'; +import type { components } from '$lib/generated/api'; + +type Geschichte = components['schemas']['Geschichte']; afterEach(cleanup); -const makeGeschichte = (overrides: Record = {}) => ({ - id: 'g1', - title: 'Reise nach Berlin', - body: '

Brief text

', - publishedAt: '2026-04-15T10:00:00Z', - author: { firstName: 'Anna', lastName: 'Schmidt', email: 'a@b' } as unknown, - ...overrides -}); +const makeGeschichte = (overrides: Record = {}): Geschichte => + ({ + id: 'g1', + title: 'Reise nach Berlin', + body: '

Brief text

', + status: 'PUBLISHED' as const, + type: 'STORY' as const, + publishedAt: '2026-04-15T10:00:00Z', + createdAt: '2026-04-01T00:00:00Z', + updatedAt: '2026-04-15T10:00:00Z', + author: { + id: 'u1', + email: 'a@b', + firstName: 'Anna', + lastName: 'Schmidt', + color: '#ccc', + enabled: true, + notifyOnReply: false, + notifyOnMention: false, + groups: [], + createdAt: '2024-01-01T00:00:00' + }, + ...overrides + }) as Geschichte; const baseProps = (overrides: Record = {}) => ({ geschichten: [] as ReturnType[],