test(documents): expand documents/[id] page coverage
Adds doc.title in document title, originalFilename fallback, 'Dokument' default fallback, canWrite=true render, geschichten + inferredRelationship rendering, doc.id empty handling, task=transcribe URL parameter render. 7 new tests targeting ~25 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -91,4 +91,81 @@ describe('documents/[id] page', () => {
|
||||
const stored = localStorage.getItem('familienarchiv.lastVisited');
|
||||
expect(stored).toContain('d1');
|
||||
});
|
||||
|
||||
it('uses doc.title as the document title when set', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d1');
|
||||
render(DocumentDetailPage, { props: { data: baseData() } });
|
||||
|
||||
// The browser <title> reflects doc.title when set
|
||||
await new Promise((r) => setTimeout(r, 30));
|
||||
expect(document.title).toContain('Brief an Helene');
|
||||
});
|
||||
|
||||
it('falls back to originalFilename when title is empty', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d2');
|
||||
render(DocumentDetailPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
document: { ...baseDoc, id: 'd2', title: '', originalFilename: 'fallback.pdf' }
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
await new Promise((r) => setTimeout(r, 30));
|
||||
expect(document.title).toContain('fallback.pdf');
|
||||
});
|
||||
|
||||
it('falls back to "Dokument" when title and originalFilename are empty', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d3');
|
||||
render(DocumentDetailPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
document: { ...baseDoc, id: 'd3', title: '', originalFilename: '' }
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
await new Promise((r) => setTimeout(r, 30));
|
||||
expect(document.title).toContain('Dokument');
|
||||
});
|
||||
|
||||
it('renders without throwing when canWrite is true', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d4');
|
||||
expect(() =>
|
||||
render(DocumentDetailPage, { props: { data: baseData({ canWrite: true }) } })
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('renders without throwing when geschichten and inferredRelationship are set', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d5');
|
||||
expect(() =>
|
||||
render(DocumentDetailPage, {
|
||||
props: {
|
||||
data: baseData({
|
||||
geschichten: [{ id: 'g1', title: 'Story', publishedAt: null }],
|
||||
inferredRelationship: { label: 'PARENT_OF', from: 'p1', to: 'p2' },
|
||||
canBlogWrite: true
|
||||
})
|
||||
}
|
||||
})
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('renders without throwing when doc.id is empty', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d-empty');
|
||||
expect(() =>
|
||||
render(DocumentDetailPage, {
|
||||
props: { data: baseData({ document: { ...baseDoc, id: '', title: 'No ID' } }) }
|
||||
})
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('renders with task=transcribe in the URL without throwing', async () => {
|
||||
mockPage.url = new URL('http://localhost/documents/d6?task=transcribe');
|
||||
expect(() =>
|
||||
render(DocumentDetailPage, {
|
||||
props: { data: baseData({ document: { ...baseDoc, id: 'd6' } }) }
|
||||
})
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user