Files
EventSnap/e2e/specs/09-mobile/focus-trap.spec.ts
fabi bbdfae09a0 chore(e2e): add ESLint + Prettier; fix real findings; dedupe BASE
The Playwright suite had no linter and no formatter — only tsc. Add flat-config ESLint
(typescript-eslint, type-aware) and Prettier (2-space, matching the suite's style).

Rules keep the ones that catch real TEST bugs and drop the noise:
  - no-floating-promises KEPT — an un-awaited request/assertion can let a test end before it runs,
    passing vacuously. It caught one: the SSE reader loop in sse-listener is now explicitly `void`.
  - no-unused-vars KEPT — caught three dead bindings (an unused adminToken fixture arg, an unused
    `api` arg, an unused JPEG_MAGIC import), all removed.
  - no-explicit-any OFF — all test code; `any` is the honest type for an untyped res.json() body or
    a page.evaluate() return.
  - no-empty-pattern OFF — Playwright's dependency-free fixtures are `async ({}, use) => {}`.

Refactor: `const BASE = process.env.E2E_FRONTEND_URL ?? '...'` was redeclared verbatim in 23
files — extracted to helpers/env.ts and imported, so a port/scheme change is one edit not a sweep.

Then `prettier --write`. Verified: eslint clean, tsc clean, prettier clean, desktop suite 210
passed / 1 skipped. (One mobile spec flaked once under retries:0 — a pre-existing cross-test
reflow-timing vector from the flakiness audit, not this change: the each-key edit is stable across
16 isolated runs and a clean full mobile re-run.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 20:45:59 +02:00

62 lines
2.2 KiB
TypeScript

/**
* Critical a11y fix — the focusTrap action keeps Tab within open modals
* and lets Escape dismiss them, then restores focus to the originating
* element. This spec covers the LightboxModal, which is the most-used
* focus-trap consumer in the app.
*/
import { test, expect } from '../../fixtures/test';
import { uploadRaw } from '../../helpers/upload-client';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
const SAMPLE_JPG = join(process.cwd(), 'fixtures', 'media', 'sample.jpg');
async function seedUpload(token: string): Promise<{ id: string }> {
const res = await uploadRaw(token, readFileSync(SAMPLE_JPG), {
filename: 'ft.jpg',
contentType: 'image/jpeg',
caption: 'Focus-trap fixture',
});
if (res.status !== 201) throw new Error(`Upload seed failed (${res.status})`);
return (await res.json()) as { id: string };
}
test.describe('Mobile a11y — focus trap on LightboxModal', () => {
test('Escape closes the lightbox and Tab cycles inside', async ({ page, guest, signIn }) => {
const g = await guest('FocusTrap');
await seedUpload(g.jwt);
await signIn(page, g);
await page.goto('/feed');
const card = page.locator('article').filter({ hasText: g.displayName }).first();
const trigger = card.getByRole('button', { name: 'Bild vergrößern' });
await expect(trigger).toBeVisible({ timeout: 10_000 });
await trigger.click();
// Lightbox is role="dialog" aria-modal="true".
const lightbox = page
.locator('[role="dialog"][aria-modal="true"]')
.filter({ has: page.locator('img, video') });
await expect(lightbox).toBeVisible();
// After opening, focus should be inside the lightbox (trap autoFocus moves
// focus to the first focusable). Verify by checking activeElement is
// contained.
await expect
.poll(
async () => {
return await page.evaluate(() => {
const dlg = document.querySelector('[role="dialog"][aria-modal="true"]');
return !!dlg && dlg.contains(document.activeElement);
});
},
{ timeout: 2_000 }
)
.toBe(true);
// Escape dismisses the lightbox.
await page.keyboard.press('Escape');
await expect(lightbox).not.toBeVisible({ timeout: 2_000 });
});
});