test(admin/ocr): cover index and per-person page branches

admin/ocr index: heading, sender-models heading, global-history link,
defensive defaults for missing trainingInfo fields.

admin/ocr/[personId]: person name from personNames lookup, Unknown
fallback when not found, back-link href, missing-personNames defensive
handling.

8 tests across two pages.

Refs #496.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-10 00:54:48 +02:00
parent a1a7138ce1
commit 34f2c1d13e
2 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import AdminOcrPersonPage from './+page.svelte';
afterEach(cleanup);
describe('admin/ocr/[personId] page', () => {
it('renders the person name from personNames lookup', async () => {
render(AdminOcrPersonPage, {
props: {
data: {
personId: 'p-1',
history: {
runs: [],
personNames: { 'p-1': 'Anna Schmidt' }
}
}
}
});
await expect.element(page.getByRole('heading', { name: /anna schmidt/i })).toBeVisible();
});
it('falls back to "Unknown" when the personNames lookup misses', async () => {
render(AdminOcrPersonPage, {
props: {
data: {
personId: 'p-1',
history: {
runs: [],
personNames: {}
}
}
}
});
await expect.element(page.getByRole('heading', { name: /unknown/i })).toBeVisible();
});
it('renders the back link to /admin/ocr', async () => {
render(AdminOcrPersonPage, {
props: {
data: {
personId: 'p-1',
history: { runs: [], personNames: { 'p-1': 'Anna Schmidt' } }
}
}
});
await expect
.element(page.getByRole('link', { name: /^ocr$/i }))
.toHaveAttribute('href', '/admin/ocr');
});
it('handles missing personNames object gracefully', async () => {
render(AdminOcrPersonPage, {
props: {
data: {
personId: 'p-1',
history: { runs: undefined, personNames: undefined }
}
}
});
await expect.element(page.getByRole('heading', { name: /unknown/i })).toBeVisible();
});
});

View File

@@ -0,0 +1,52 @@
import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import AdminOcrPage from './+page.svelte';
afterEach(cleanup);
const baseTrainingInfo = (overrides: Record<string, unknown> = {}) => ({
ocrServiceAvailable: true,
availableBlocks: 100,
totalOcrBlocks: 200,
availableDocuments: 50,
availableSegBlocks: 30,
senderModels: [],
personNames: {},
runs: [],
...overrides
});
describe('admin/ocr index page', () => {
it('renders the OCR heading', async () => {
render(AdminOcrPage, { props: { data: { trainingInfo: baseTrainingInfo() } } });
await expect.element(page.getByRole('heading', { level: 1, name: /^ocr$/i })).toBeVisible();
});
it('renders the sender-models heading', async () => {
render(AdminOcrPage, { props: { data: { trainingInfo: baseTrainingInfo() } } });
await expect.element(page.getByRole('heading', { name: /sender-modelle/i })).toBeVisible();
});
it('renders the global-history link to /admin/ocr/global', async () => {
render(AdminOcrPage, { props: { data: { trainingInfo: baseTrainingInfo() } } });
await expect
.element(page.getByRole('link', { name: /globaler verlauf/i }))
.toHaveAttribute('href', '/admin/ocr/global');
});
it('handles missing trainingInfo fields with defaults', async () => {
render(AdminOcrPage, {
props: {
data: {
trainingInfo: { ocrServiceAvailable: false }
}
}
});
await expect.element(page.getByRole('heading', { level: 1, name: /^ocr$/i })).toBeVisible();
});
});