test(frontend): fix Geschichte component specs for GeschichteType and JourneyItem model
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -8,19 +8,9 @@ const personFactory = (id: string, displayName: string) => ({
|
|||||||
firstName: displayName.split(' ')[0],
|
firstName: displayName.split(' ')[0],
|
||||||
lastName: displayName.split(' ').slice(1).join(' ') || displayName,
|
lastName: displayName.split(' ').slice(1).join(' ') || displayName,
|
||||||
displayName,
|
displayName,
|
||||||
personType: 'PERSON' as const
|
personType: 'PERSON' as const,
|
||||||
});
|
familyMember: false,
|
||||||
|
provisional: false
|
||||||
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'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const draftFactory = (overrides: Record<string, unknown> = {}) => ({
|
const draftFactory = (overrides: Record<string, unknown> = {}) => ({
|
||||||
@@ -28,8 +18,9 @@ const draftFactory = (overrides: Record<string, unknown> = {}) => ({
|
|||||||
title: 'Existing draft',
|
title: 'Existing draft',
|
||||||
body: '<p>Hello world</p>',
|
body: '<p>Hello world</p>',
|
||||||
status: 'DRAFT' as const,
|
status: 'DRAFT' as const,
|
||||||
|
type: 'STORY' as const,
|
||||||
persons: [],
|
persons: [],
|
||||||
documents: [],
|
items: [],
|
||||||
createdAt: '2024-01-01T00:00:00',
|
createdAt: '2024-01-01T00:00:00',
|
||||||
updatedAt: '2024-01-01T00:00:00',
|
updatedAt: '2024-01-01T00:00:00',
|
||||||
...overrides
|
...overrides
|
||||||
@@ -93,14 +84,6 @@ describe('GeschichteEditor — pre-fill', () => {
|
|||||||
await expect.element(page.getByText('Franz Raddatz')).toBeInTheDocument();
|
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 () => {
|
it('populates the title input from a geschichte prop', async () => {
|
||||||
render(GeschichteEditor, {
|
render(GeschichteEditor, {
|
||||||
geschichte: draftFactory({ title: 'My existing story' }),
|
geschichte: draftFactory({ title: 'My existing story' }),
|
||||||
@@ -154,11 +137,10 @@ describe('GeschichteEditor — onSubmit payload', () => {
|
|||||||
expect(onSubmit.mock.calls[0][0].status).toBe('PUBLISHED');
|
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);
|
const onSubmit = vi.fn().mockResolvedValue(undefined);
|
||||||
render(GeschichteEditor, {
|
render(GeschichteEditor, {
|
||||||
initialPersons: [personFactory('p1', 'Franz Raddatz')],
|
initialPersons: [personFactory('p1', 'Franz Raddatz')],
|
||||||
initialDocuments: [docFactory('d1', 'Brief A')],
|
|
||||||
onSubmit
|
onSubmit
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -171,6 +153,5 @@ describe('GeschichteEditor — onSubmit payload', () => {
|
|||||||
expect(onSubmit).toHaveBeenCalledTimes(1);
|
expect(onSubmit).toHaveBeenCalledTimes(1);
|
||||||
const payload = onSubmit.mock.calls[0][0];
|
const payload = onSubmit.mock.calls[0][0];
|
||||||
expect(payload.personIds).toEqual(['p1']);
|
expect(payload.personIds).toEqual(['p1']);
|
||||||
expect(payload.documentIds).toEqual(['d1']);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,16 +3,17 @@ import { cleanup, render } from 'vitest-browser-svelte';
|
|||||||
import { page } from 'vitest/browser';
|
import { page } from 'vitest/browser';
|
||||||
import GeschichtenCard from './GeschichtenCard.svelte';
|
import GeschichtenCard from './GeschichtenCard.svelte';
|
||||||
|
|
||||||
const makeStory = (id: string, title: string, body: string | null = '<p>Body</p>') => ({
|
const makeStory = (id: string, title: string, body: string | undefined = '<p>Body</p>') => ({
|
||||||
id,
|
id,
|
||||||
title,
|
title,
|
||||||
body,
|
body,
|
||||||
status: 'PUBLISHED' as const,
|
status: 'PUBLISHED' as const,
|
||||||
|
type: 'STORY' as const,
|
||||||
publishedAt: '2024-04-01T12:00:00',
|
publishedAt: '2024-04-01T12:00:00',
|
||||||
createdAt: '2024-03-01T12:00:00',
|
createdAt: '2024-03-01T12:00:00',
|
||||||
updatedAt: '2024-04-01T12:00:00',
|
updatedAt: '2024-04-01T12:00:00',
|
||||||
persons: [],
|
persons: [],
|
||||||
documents: [],
|
items: [],
|
||||||
author: {
|
author: {
|
||||||
id: 'u1',
|
id: 'u1',
|
||||||
email: 'marcel@example.com',
|
email: 'marcel@example.com',
|
||||||
|
|||||||
@@ -2,17 +2,36 @@ import { describe, it, expect, afterEach } from 'vitest';
|
|||||||
import { cleanup, render } from 'vitest-browser-svelte';
|
import { cleanup, render } from 'vitest-browser-svelte';
|
||||||
import { page } from 'vitest/browser';
|
import { page } from 'vitest/browser';
|
||||||
import GeschichtenCard from './GeschichtenCard.svelte';
|
import GeschichtenCard from './GeschichtenCard.svelte';
|
||||||
|
import type { components } from '$lib/generated/api';
|
||||||
|
|
||||||
|
type Geschichte = components['schemas']['Geschichte'];
|
||||||
|
|
||||||
afterEach(cleanup);
|
afterEach(cleanup);
|
||||||
|
|
||||||
const makeGeschichte = (overrides: Record<string, unknown> = {}) => ({
|
const makeGeschichte = (overrides: Record<string, unknown> = {}): Geschichte =>
|
||||||
id: 'g1',
|
({
|
||||||
title: 'Reise nach Berlin',
|
id: 'g1',
|
||||||
body: '<p>Brief text</p>',
|
title: 'Reise nach Berlin',
|
||||||
publishedAt: '2026-04-15T10:00:00Z',
|
body: '<p>Brief text</p>',
|
||||||
author: { firstName: 'Anna', lastName: 'Schmidt', email: 'a@b' } as unknown,
|
status: 'PUBLISHED' as const,
|
||||||
...overrides
|
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<string, unknown> = {}) => ({
|
const baseProps = (overrides: Record<string, unknown> = {}) => ({
|
||||||
geschichten: [] as ReturnType<typeof makeGeschichte>[],
|
geschichten: [] as ReturnType<typeof makeGeschichte>[],
|
||||||
|
|||||||
Reference in New Issue
Block a user