From 6832300a4b6dd6c86a2dd8662d35cfb7f860d36f Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 19 May 2026 17:26:17 +0200 Subject: [PATCH] test(viewer): replace hardcoded German strings in PdfControls spec with m.* calls Co-Authored-By: Claude Sonnet 4.6 --- .../viewer/PdfControls.svelte.spec.ts | 58 ++++++++++++++----- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/frontend/src/lib/document/viewer/PdfControls.svelte.spec.ts b/frontend/src/lib/document/viewer/PdfControls.svelte.spec.ts index 6dadc3ac..a6a56d8d 100644 --- a/frontend/src/lib/document/viewer/PdfControls.svelte.spec.ts +++ b/frontend/src/lib/document/viewer/PdfControls.svelte.spec.ts @@ -2,6 +2,7 @@ import { vi, describe, it, expect, afterEach } from 'vitest'; import { cleanup, render } from 'vitest-browser-svelte'; import { page } from 'vitest/browser'; +import { m } from '$lib/paraglide/messages.js'; import PdfControls from './PdfControls.svelte'; afterEach(cleanup); @@ -23,28 +24,28 @@ describe('PdfControls — annotation toggle visibility', () => { it('renders annotation toggle when annotationCount is greater than zero', async () => { render(PdfControls, { ...defaultProps, annotationCount: 3 }); await expect - .element(page.getByRole('button', { name: /annotierungen anzeigen/i })) + .element(page.getByRole('button', { name: m.pdf_annotations_show() })) .toBeInTheDocument(); }); it('does not render annotation toggle when annotationCount is zero', async () => { render(PdfControls, { ...defaultProps, annotationCount: 0 }); await expect - .element(page.getByRole('button', { name: /annotierungen/i })) + .element(page.getByRole('button', { name: m.pdf_annotations_show() })) .not.toBeInTheDocument(); }); }); describe('PdfControls — annotation toggle label', () => { - it('shows "Annotierungen anzeigen" label when annotations are hidden', async () => { + it('shows show-annotations label when annotations are hidden', async () => { render(PdfControls, { ...defaultProps, annotationCount: 2, showAnnotations: false }); - const btn = page.getByRole('button', { name: /annotierungen anzeigen/i }); + const btn = page.getByRole('button', { name: m.pdf_annotations_show() }); await expect.element(btn).toBeInTheDocument(); }); - it('shows "Annotierungen verbergen" label when annotations are visible', async () => { + it('shows hide-annotations label when annotations are visible', async () => { render(PdfControls, { ...defaultProps, annotationCount: 2, showAnnotations: true }); - const btn = page.getByRole('button', { name: /annotierungen verbergen/i }); + const btn = page.getByRole('button', { name: m.pdf_annotations_hide() }); await expect.element(btn).toBeInTheDocument(); }); }); @@ -58,7 +59,9 @@ describe('PdfControls — annotation toggle contrast (WCAG 2.1 AA)', () => { }); const allButtons = container.querySelectorAll('button'); const annotationBtn = Array.from(allButtons).find((b) => - b.getAttribute('aria-label')?.toLowerCase().includes('annotierungen') + [m.pdf_annotations_show(), m.pdf_annotations_hide()].includes( + b.getAttribute('aria-label') ?? '' + ) ); expect(annotationBtn).not.toBeNull(); expect(annotationBtn!.className).toContain('text-primary'); @@ -75,7 +78,9 @@ describe('PdfControls — focus rings (WCAG 2.1 §2.4.7)', () => { }); const allButtons = container.querySelectorAll('button'); const annotationBtn = Array.from(allButtons).find((b) => - b.getAttribute('aria-label')?.toLowerCase().includes('annotierungen') + [m.pdf_annotations_show(), m.pdf_annotations_hide()].includes( + b.getAttribute('aria-label') ?? '' + ) ); expect(annotationBtn).not.toBeNull(); expect(annotationBtn!.className).toContain('focus-visible:ring-2'); @@ -86,7 +91,12 @@ describe('PdfControls — focus rings (WCAG 2.1 §2.4.7)', () => { const allButtons = container.querySelectorAll('button'); const iconOnlyButtons = Array.from(allButtons).filter((b) => { const label = b.getAttribute('aria-label') ?? ''; - return ['zurück', 'weiter', 'verkleinern', 'vergrößern'].includes(label.toLowerCase()); + return [ + m.viewer_previous_page(), + m.viewer_next_page(), + m.viewer_zoom_out(), + m.viewer_zoom_in() + ].includes(label); }); expect(iconOnlyButtons).toHaveLength(4); for (const btn of iconOnlyButtons) { @@ -104,7 +114,9 @@ describe('PdfControls — touch targets (WCAG 2.2 §2.5.8)', () => { }); const allButtons = container.querySelectorAll('button'); const annotationBtn = Array.from(allButtons).find((b) => - b.getAttribute('aria-label')?.toLowerCase().includes('annotierungen') + [m.pdf_annotations_show(), m.pdf_annotations_hide()].includes( + b.getAttribute('aria-label') ?? '' + ) ); expect(annotationBtn).not.toBeNull(); expect(annotationBtn!.className).toContain('min-h-[44px]'); @@ -118,7 +130,9 @@ describe('PdfControls — touch targets (WCAG 2.2 §2.5.8)', () => { }); const allButtons = container.querySelectorAll('button'); const annotationBtn = Array.from(allButtons).find((b) => - b.getAttribute('aria-label')?.toLowerCase().includes('annotierungen') + [m.pdf_annotations_show(), m.pdf_annotations_hide()].includes( + b.getAttribute('aria-label') ?? '' + ) ); expect(annotationBtn).not.toBeNull(); expect(annotationBtn!.className).toContain('min-w-[44px]'); @@ -131,7 +145,9 @@ describe('PdfControls — touch targets (WCAG 2.2 §2.5.8)', () => { showAnnotations: false }); const btn1 = Array.from(c1.querySelectorAll('button')).find((b) => - b.getAttribute('aria-label')?.toLowerCase().includes('annotierungen') + [m.pdf_annotations_show(), m.pdf_annotations_hide()].includes( + b.getAttribute('aria-label') ?? '' + ) ); expect(btn1!.getAttribute('aria-pressed')).toBe('false'); cleanup(); @@ -142,7 +158,9 @@ describe('PdfControls — touch targets (WCAG 2.2 §2.5.8)', () => { showAnnotations: true }); const btn2 = Array.from(c2.querySelectorAll('button')).find((b) => - b.getAttribute('aria-label')?.toLowerCase().includes('annotierungen') + [m.pdf_annotations_show(), m.pdf_annotations_hide()].includes( + b.getAttribute('aria-label') ?? '' + ) ); expect(btn2!.getAttribute('aria-pressed')).toBe('true'); }); @@ -152,7 +170,12 @@ describe('PdfControls — touch targets (WCAG 2.2 §2.5.8)', () => { const allButtons = container.querySelectorAll('button'); const iconOnlyButtons = Array.from(allButtons).filter((b) => { const label = b.getAttribute('aria-label') ?? ''; - return ['zurück', 'weiter', 'verkleinern', 'vergrößern'].includes(label.toLowerCase()); + return [ + m.viewer_previous_page(), + m.viewer_next_page(), + m.viewer_zoom_out(), + m.viewer_zoom_in() + ].includes(label); }); expect(iconOnlyButtons).toHaveLength(4); for (const btn of iconOnlyButtons) { @@ -165,7 +188,12 @@ describe('PdfControls — touch targets (WCAG 2.2 §2.5.8)', () => { const allButtons = container.querySelectorAll('button'); const iconOnlyButtons = Array.from(allButtons).filter((b) => { const label = b.getAttribute('aria-label') ?? ''; - return ['zurück', 'weiter', 'verkleinern', 'vergrößern'].includes(label.toLowerCase()); + return [ + m.viewer_previous_page(), + m.viewer_next_page(), + m.viewer_zoom_out(), + m.viewer_zoom_in() + ].includes(label); }); expect(iconOnlyButtons).toHaveLength(4); for (const btn of iconOnlyButtons) {