Files
familienarchiv/frontend/src/routes/hilfe/transkription/page.svelte.spec.ts
Marcel 6ab7abb9df
Some checks failed
CI / Unit & Component Tests (push) Failing after 3m41s
CI / OCR Service Tests (push) Successful in 43s
CI / Backend Unit Tests (push) Failing after 3m30s
CI / Unit & Component Tests (pull_request) Failing after 3m32s
CI / OCR Service Tests (pull_request) Successful in 40s
CI / Backend Unit Tests (pull_request) Failing after 3m17s
fix(tests): fix 3 pre-existing vitest-browser spec failures
Three distinct root causes:

1. hilfe/transkription: Wikipedia link test was checking .textContent but
   the accessible text had moved to aria-label in a prior commit.

2. documents/[id]/edit: vi.spyOn on a Svelte 5 compiled .svelte.ts service
   object does not reliably track calls in vitest-browser mode; replaced
   with a plain closure-based mock.

3. GeschichteEditor: TipTap's onMount steals focus and its ProseMirror
   view interferes with Playwright CDP event dispatch. Three workarounds:
   - blur: dispatchEvent(new FocusEvent('blur')) bypasses focus-state check
   - save buttons: dispatchEvent(new MouseEvent('click')) from in-browser JS
     context reliably triggers Svelte 5 onclick vs. Playwright CDP click
   - trailing-space fill: input.value + dispatchEvent('input') works where
     userEvent.fill('value ') silently fails to update bind:value

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 11:27:24 +02:00

73 lines
2.8 KiB
TypeScript

import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import Page from './+page.svelte';
afterEach(cleanup);
describe('Richtlinien page — structure', () => {
it('renders h1 with richtlinien title', async () => {
render(Page);
await expect
.element(page.getByRole('heading', { level: 1 }))
.toHaveTextContent('Transkriptions-Richtlinien');
});
it('renders intro paragraph', async () => {
render(Page);
await expect.element(page.getByText(/Damit alle Briefe einheitlich/)).toBeInTheDocument();
});
it('renders Wikipedia external link with security attributes and new-tab annotation', async () => {
render(Page);
const wikiLink = page.getByRole('link', { name: /Wikipedia/ });
await expect.element(wikiLink).toBeInTheDocument();
await expect.element(wikiLink).toHaveAttribute('target', '_blank');
await expect.element(wikiLink).toHaveAttribute('rel', 'noopener noreferrer');
await expect.element(wikiLink).toHaveAttribute('referrerpolicy', 'no-referrer');
// icon communicates "opens new tab" visually; aria-label carries the text for a11y
const link = document.querySelector('a[href*="wikipedia"]') as HTMLAnchorElement;
expect(link.getAttribute('aria-label')).toContain('öffnet in neuem Tab');
});
it('renders Regeln h2 section', async () => {
render(Page);
await expect
.element(page.getByRole('heading', { level: 2, name: /Regeln für die Transkription/ }))
.toBeInTheDocument();
});
it('renders Noch in Klärung h2 section', async () => {
render(Page);
await expect
.element(page.getByRole('heading', { level: 2, name: /Noch in Klärung/ }))
.toBeInTheDocument();
});
it('renders closing invitation card', async () => {
render(Page);
await expect.element(page.getByText(/Fehlt eine Regel/)).toBeInTheDocument();
});
});
describe('Richtlinien page — rule cards', () => {
it('renders five rule card titles', async () => {
render(Page);
await expect.element(page.getByText('Nicht lesbare Wörter')).toBeInTheDocument();
await expect.element(page.getByText('Durchgestrichene Wörter')).toBeInTheDocument();
await expect.element(page.getByText(/Das lange s/)).toBeInTheDocument();
await expect.element(page.getByText('Unsichere Namen')).toBeInTheDocument();
await expect.element(page.getByText(/Dialekt/)).toBeInTheDocument();
});
});
describe('Richtlinien page — Noch in Klärung chips', () => {
it('renders four clarification chips', async () => {
render(Page);
await expect.element(page.getByText('Abkürzungen')).toBeInTheDocument();
await expect.element(page.getByText('Datumsformate')).toBeInTheDocument();
await expect.element(page.getByText(/Zeilenumbrüche/)).toBeInTheDocument();
await expect.element(page.getByText(/Groß-\/Kleinschreibung/)).toBeInTheDocument();
});
});