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 54d8252499 - Show all commits

View File

@@ -0,0 +1,93 @@
import { describe, it, expect, vi, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
vi.mock('pdfjs-dist', () => {
function TextLayerMock() {}
TextLayerMock.prototype.render = () => Promise.resolve();
TextLayerMock.prototype.cancel = () => {};
return {
GlobalWorkerOptions: { workerSrc: '' },
getDocument: vi.fn().mockReturnValue({
promise: Promise.resolve({
numPages: 2,
getPage: vi.fn().mockResolvedValue({
getViewport: vi.fn().mockReturnValue({ width: 595, height: 842 }),
render: vi.fn().mockReturnValue({ promise: Promise.resolve() }),
streamTextContent: vi.fn().mockReturnValue(new ReadableStream())
})
})
}),
TextLayer: TextLayerMock
};
});
vi.mock('pdfjs-dist/build/pdf.worker.min.mjs?url', () => ({ default: '' }));
const { default: PdfViewer } = await import('./PdfViewer.svelte');
afterEach(cleanup);
describe('PdfViewer — empty / error states', () => {
it('renders the no-file placeholder when url is empty', async () => {
render(PdfViewer, { url: '' });
await expect.element(page.getByText('Keine Datei vorhanden')).toBeVisible();
});
it('does not render the controls when url is empty', async () => {
render(PdfViewer, { url: '' });
const buttons = document.querySelectorAll('button');
// Empty state has no nav buttons
expect(buttons.length).toBe(0);
});
});
describe('PdfViewer — loaded state', () => {
it('renders annotation toggle controls', async () => {
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test',
annotationReloadKey: 0
});
// The PdfControls component renders the toggle button
await new Promise((r) => setTimeout(r, 50));
const buttons = document.querySelectorAll('button');
expect(buttons.length).toBeGreaterThan(0);
});
it('passes annotationsDimmed=true to the AnnotationLayer wrapper', async () => {
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test',
annotationsDimmed: true
});
await new Promise((r) => setTimeout(r, 50));
// just confirm no throw in the dimmed code path
expect(document.querySelector('.bg-pdf-bg')).not.toBeNull();
});
it('renders without throwing in transcribeMode', async () => {
expect(() =>
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test',
transcribeMode: true
})
).not.toThrow();
});
it('renders without throwing with a documentFileHash and matching annotations', async () => {
expect(() =>
render(PdfViewer, {
url: '/api/documents/test/file',
documentId: 'test',
documentFileHash: 'abc123'
})
).not.toThrow();
});
});