test(routes): cover bulk-edit-all success path + hasAdvancedFilters branches

bulk-edit-all populates the selection store on 200 response,
senderId/from/to truthy paths trigger showAdvanced.

4 new tests covering ~8 branches.

Refs #496.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-10 09:23:30 +02:00
committed by marcel
parent 108dc3104d
commit 961727c3f2

View File

@@ -368,4 +368,48 @@ describe('documents/+ page', () => {
render(DocumentsListPage, { props: { data: baseData({ canWrite: true }) } })
).not.toThrow();
});
it('bulk-edit-all populates the selection store on success', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
new Response(JSON.stringify(['d-a', 'd-b', 'd-c']), {
status: 200,
headers: { 'Content-Type': 'application/json' }
})
);
try {
render(DocumentsListPage, {
props: { data: baseData({ canWrite: true, totalElements: 3 }) }
});
const btn = (await page
.getByRole('button', { name: /alle 3 editieren/i })
.element()) as HTMLButtonElement;
btn.click();
await new Promise((r) => setTimeout(r, 100));
expect(bulkSelectionStore.size).toBe(3);
} finally {
fetchSpy.mockRestore();
}
});
it('hasAdvancedFilters truthy on senderId triggers showAdvanced=true on mount', async () => {
expect(() =>
render(DocumentsListPage, {
props: { data: baseData({ senderId: 'p-1', initialSenderName: 'Anna' }) }
})
).not.toThrow();
});
it('hasAdvancedFilters truthy on from-date triggers showAdvanced=true', async () => {
expect(() =>
render(DocumentsListPage, { props: { data: baseData({ from: '1899-01-01' }) } })
).not.toThrow();
});
it('hasAdvancedFilters truthy on to-date triggers showAdvanced=true', async () => {
expect(() =>
render(DocumentsListPage, { props: { data: baseData({ to: '1950-12-31' }) } })
).not.toThrow();
});
});