test(documents): cover ocr-status RUNNING path + various doc-prop branches
ocr-status returning RUNNING + jobId triggers pollOcrJob, full OCR-relevant doc fields, geschichten undefined fallback. 3 new tests covering ~10 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user