test(coverage): drive browser tests to 80% on all metrics (#496) #505

Merged
marcel merged 189 commits from feat/issue-496-browser-coverage-tests into main 2026-05-11 21:50:39 +02:00
Showing only changes of commit eb2b246dd6 - Show all commits

View File

@@ -142,4 +142,106 @@ describe('PdfViewer — loaded state', () => {
})
).not.toThrow();
});
it('shows the outdated-annotation notice when annotations have non-matching fileHash', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
new Response(
JSON.stringify([
{
id: 'a1',
documentId: 'test',
pageNumber: 1,
x: 0.1,
y: 0.1,
width: 0.1,
height: 0.1,
color: '#000',
createdAt: '2026-01-01T00:00:00Z',
fileHash: 'old-hash'
}
]),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
);
try {
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test',
documentFileHash: 'new-hash'
});
await new Promise((r) => setTimeout(r, 100));
const notice = document.querySelector('[data-testid="annotation-outdated-notice"]');
expect(notice).not.toBeNull();
} finally {
fetchSpy.mockRestore();
}
});
it('does not show outdated-annotation notice when all annotations match', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue(
new Response(
JSON.stringify([
{
id: 'a1',
documentId: 'test',
pageNumber: 1,
x: 0.1,
y: 0.1,
width: 0.1,
height: 0.1,
color: '#000',
createdAt: '2026-01-01T00:00:00Z',
fileHash: 'matching-hash'
}
]),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
);
try {
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test',
documentFileHash: 'matching-hash'
});
await new Promise((r) => setTimeout(r, 100));
const notice = document.querySelector('[data-testid="annotation-outdated-notice"]');
expect(notice).toBeNull();
} finally {
fetchSpy.mockRestore();
}
});
it('handles fetch error when loading annotations gracefully', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('network'));
try {
expect(() =>
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test'
})
).not.toThrow();
await new Promise((r) => setTimeout(r, 50));
} finally {
fetchSpy.mockRestore();
}
});
it('handles non-OK fetch response when loading annotations', async () => {
const fetchSpy = vi
.spyOn(globalThis, 'fetch')
.mockResolvedValue(new Response('error', { status: 500 }));
try {
expect(() =>
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test'
})
).not.toThrow();
await new Promise((r) => setTimeout(r, 50));
} finally {
fetchSpy.mockRestore();
}
});
});