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:
68
frontend/src/routes/admin/ocr/[personId]/page.svelte.test.ts
Normal file
68
frontend/src/routes/admin/ocr/[personId]/page.svelte.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user