diff --git a/frontend/src/routes/documents/[id]/page.svelte.test.ts b/frontend/src/routes/documents/[id]/page.svelte.test.ts index f0251c02..66b30b81 100644 --- a/frontend/src/routes/documents/[id]/page.svelte.test.ts +++ b/frontend/src/routes/documents/[id]/page.svelte.test.ts @@ -379,4 +379,71 @@ describe('documents/[id] page', () => { fetchSpy.mockRestore(); } }); + + it('renders ocr-status RUNNING and starts polling without throwing', async () => { + const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url) => { + const u = url.toString(); + if (u.includes('ocr-status')) { + return new Response(JSON.stringify({ status: 'RUNNING', jobId: 'job-1' }), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }); + } + if (u.includes('/ocr/jobs/')) { + return new Response(JSON.stringify({ status: 'RUNNING', progressMessage: 'WORKING' }), { + status: 200, + headers: { 'Content-Type': 'application/json' } + }); + } + return new Response('[]', { status: 200, headers: { 'Content-Type': 'application/json' } }); + }); + try { + mockPage.url = new URL('http://localhost/documents/d-ocr-run?task=transcribe'); + render(DocumentDetailPage, { + props: { data: baseData({ document: { ...baseDoc, id: 'd-ocr-run' } }) } + }); + await new Promise((r) => setTimeout(r, 100)); + // Page renders; the ocrRunning state is on but we don't assert specific UI + // because that requires deep DOM access into TranscriptionEditView. + expect(document.body.firstElementChild).not.toBeNull(); + } finally { + fetchSpy.mockRestore(); + } + }); + + it('renders without throwing when document has all OCR-relevant fields populated', async () => { + mockPage.url = new URL('http://localhost/documents/d-ocr-meta?task=transcribe'); + expect(() => + render(DocumentDetailPage, { + props: { + data: baseData({ + document: { + ...baseDoc, + id: 'd-ocr-meta', + scriptType: 'KURRENT', + trainingLabels: ['KURRENT_RECOGNITION'], + filePath: 's3://bucket/file.pdf', + fileHash: 'hash-abc' + }, + canWrite: true, + user: { id: 'u1', firstName: 'Anna' } + }) + } + }) + ).not.toThrow(); + }); + + it('handles empty geschichten array as falsy (geschichten ?? []) branch', async () => { + mockPage.url = new URL('http://localhost/documents/d-no-stories'); + expect(() => + render(DocumentDetailPage, { + props: { + data: baseData({ + document: { ...baseDoc, id: 'd-no-stories' }, + geschichten: undefined + }) + } + }) + ).not.toThrow(); + }); });