Files
familienarchiv/frontend/src/lib/document/DashboardNeedsMetadata.svelte.spec.ts
Marcel d5441d3e55
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 6m5s
CI / OCR Service Tests (pull_request) Successful in 22s
CI / Backend Unit Tests (pull_request) Successful in 3m55s
CI / fail2ban Regex (pull_request) Successful in 45s
CI / Semgrep Security Scan (pull_request) Successful in 23s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m4s
fix(tests): resolve 10 failing browser-mode tests
- Import layout.css in test-setup so Tailwind utilities (text-xs,
  min-h-[44px]) apply in vitest-browser — fixes computed-style assertions
  for badge font-size and touch-target height
- radioGroupNav: write aria-checked directly on radio buttons on arrow-key
  navigation, not only via the optional onChangeFn callback
- DashboardNeedsMetadata spec: tighten footer-link matcher from /50/ to
  /Alle 50/ — avoids strict-mode collision with row link whose relative
  time text also contains "50" (uploadedAt is exactly 50 days ago today)
- geschichten/[id] page spec: add missing await on userEvent.click before
  confirmService.settle() in both delete tests
- TypeSelector spec: replace storyCard.focus() (not on vitest-browser
  Locator) with userEvent.click(); force-dispatch aria-disabled Weiter
  click via element.click() to bypass Playwright actionability check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-09 10:36:56 +02:00

58 lines
2.4 KiB
TypeScript

import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import DashboardNeedsMetadata from './DashboardNeedsMetadata.svelte';
afterEach(cleanup);
type IncompleteDoc = { id: string; title: string; uploadedAt: string };
function makeDoc(id: string, title: string, uploadedAt = '2026-04-20T12:00:00'): IncompleteDoc {
return { id, title, uploadedAt };
}
describe('DashboardNeedsMetadata', () => {
it('renders nothing when topDocs is empty', async () => {
render(DashboardNeedsMetadata, { topDocs: [], totalCount: 0 });
const widget = page.getByTestId('dashboard-needs-metadata');
await expect.element(widget).not.toBeInTheDocument();
});
it('shows the widget when topDocs is present', async () => {
render(DashboardNeedsMetadata, { topDocs: [makeDoc('d1', 'Taufschein')], totalCount: 1 });
await expect.element(page.getByTestId('dashboard-needs-metadata')).toBeInTheDocument();
});
it('renders one link per row pointing at /enrich/{id}', async () => {
const docs = [makeDoc('d1', 'Taufschein'), makeDoc('d2', 'Heiratsurkunde')];
render(DashboardNeedsMetadata, { topDocs: docs, totalCount: 2 });
await expect
.element(page.getByRole('link', { name: /Taufschein/ }))
.toHaveAttribute('href', '/enrich/d1');
await expect
.element(page.getByRole('link', { name: /Heiratsurkunde/ }))
.toHaveAttribute('href', '/enrich/d2');
});
it('hides the footer link when totalCount is 5 or fewer', async () => {
const docs = Array.from({ length: 5 }, (_, i) => makeDoc(`d${i}`, `Dok ${i}`));
render(DashboardNeedsMetadata, { topDocs: docs, totalCount: 5 });
const footer = page.getByRole('link', { name: /Alle/i });
await expect.element(footer).not.toBeInTheDocument();
});
it('shows the footer link with totalCount when totalCount > 5', async () => {
const docs = Array.from({ length: 5 }, (_, i) => makeDoc(`d${i}`, `Dok ${i}`));
render(DashboardNeedsMetadata, { topDocs: docs, totalCount: 12 });
const footer = page.getByRole('link', { name: /12/ });
await expect.element(footer).toHaveAttribute('href', '/enrich');
});
it('uses totalCount in the footer even when topDocs has fewer items', async () => {
const docs = [makeDoc('d1', 'Only one')];
render(DashboardNeedsMetadata, { topDocs: docs, totalCount: 50 });
await expect.element(page.getByRole('link', { name: /Alle 50/ })).toBeInTheDocument();
});
});