test(routes): expand documents page coverage
Adds canWrite=false hides bulk-edit and new-doc CTAs, no-results empty state, populated document list, q from server, render-without- throwing for date / tag / sender filters preselected. 7 new tests targeting ~15 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -112,4 +112,95 @@ describe('documents/+ page', () => {
|
|||||||
.element(page.getByRole('button', { name: /alle .* editieren/i }))
|
.element(page.getByRole('button', { name: /alle .* editieren/i }))
|
||||||
.not.toBeInTheDocument();
|
.not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('hides the bulk-edit-all and new-doc CTAs when canWrite is false', async () => {
|
||||||
|
render(DocumentsListPage, {
|
||||||
|
props: { data: baseData({ canWrite: false, totalElements: 12 }) }
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect
|
||||||
|
.element(page.getByRole('link', { name: /neues dokument/i }))
|
||||||
|
.not.toBeInTheDocument();
|
||||||
|
await expect.element(page.getByRole('button', { name: /alle 12/i })).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('displays the no-results state when items is empty (via DocumentList)', async () => {
|
||||||
|
render(DocumentsListPage, { props: { data: baseData({ items: [], totalElements: 0 }) } });
|
||||||
|
|
||||||
|
// DocumentList renders the empty placeholder
|
||||||
|
expect(document.body.textContent).toMatch(/keine|noch|empty/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the document list when items are present', async () => {
|
||||||
|
render(DocumentsListPage, {
|
||||||
|
props: {
|
||||||
|
data: baseData({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
document: {
|
||||||
|
id: 'd1',
|
||||||
|
title: 'Brief 1899',
|
||||||
|
status: 'TRANSCRIBED',
|
||||||
|
documentDate: '1899-04-14',
|
||||||
|
summary: '',
|
||||||
|
originalFilename: 'b1.pdf',
|
||||||
|
receivers: []
|
||||||
|
},
|
||||||
|
matchData: {
|
||||||
|
titleOffsets: [],
|
||||||
|
senderMatched: false,
|
||||||
|
matchedReceiverIds: [],
|
||||||
|
matchedTagIds: [],
|
||||||
|
snippetOffsets: [],
|
||||||
|
summaryOffsets: []
|
||||||
|
},
|
||||||
|
completionPercentage: 80,
|
||||||
|
contributors: []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
totalElements: 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(document.body.textContent).toContain('Brief 1899');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('preselects the search input from data.q', async () => {
|
||||||
|
render(DocumentsListPage, { props: { data: baseData({ q: 'kurrent' }) } });
|
||||||
|
|
||||||
|
const input = document.querySelector('input[type="text"]') as HTMLInputElement;
|
||||||
|
expect(input?.value).toBe('kurrent');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders without throwing when from/to date filters are preselected', async () => {
|
||||||
|
expect(() =>
|
||||||
|
render(DocumentsListPage, {
|
||||||
|
props: { data: baseData({ from: '1899-01-01', to: '1950-12-31' }) }
|
||||||
|
})
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders without throwing when tag filters are preselected', async () => {
|
||||||
|
expect(() =>
|
||||||
|
render(DocumentsListPage, {
|
||||||
|
props: { data: baseData({ tags: ['Kurrent', 'Familie'] }) }
|
||||||
|
})
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders without throwing when sender/receiver filters are set', async () => {
|
||||||
|
expect(() =>
|
||||||
|
render(DocumentsListPage, {
|
||||||
|
props: {
|
||||||
|
data: baseData({
|
||||||
|
senderId: 'p-1',
|
||||||
|
initialSenderName: 'Anna Schmidt',
|
||||||
|
receiverId: 'p-2',
|
||||||
|
initialReceiverName: 'Bert Meier'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user