test(app): Playwright and axe browser suite on Chromium (D14)
@playwright/test 1.64.1 and @axe-core/playwright 4.14.0, dev only and pinned. pnpm e2e:ui runs a Vite server of its own on 127.0.0.1:5191 with no backend: the Dialog contract on a dev-only test page and the local tool's dialogs, desktop and 375 px, FR and EN, axe at zero serious violation outside one listed pre-existing finding. Requests outside the allowlist are aborted and fail the test.
This commit is contained in:
1 parent
6f885eccb2
commit
72ee9f9971
11 files changed
+740
-3
No files matched your search
@@ -30,6 +30,7 @@ Thumbs.db
|
||||
coverage/
|
||||
playwright-report/
|
||||
test-results/
|
||||
blob-report/
|
||||
.nyc_output/
|
||||
|
||||
# Cache
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Dialog harness</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="./dialog.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Test page for the shared Dialog in a real browser (e2e/ui/dialog.spec.ts).
|
||||
* Served by the Vite dev server only (`/e2e/harness/dialog.html`); the build
|
||||
* has a single entry, index.html, so this page never ships. Each scenario is a
|
||||
* case of the D13 contract, not a product journey: `?lang=en` picks the language.
|
||||
*/
|
||||
import { StrictMode, useState } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import '@/styles/index.css'
|
||||
import Button from '@/components/ui/Button'
|
||||
import Dialog from '@/components/ui/Dialog'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import type { Locale } from '@/i18n/types'
|
||||
|
||||
const lang: Locale =
|
||||
new URLSearchParams(location.search).get('lang') === 'en' ? 'en' : 'fr'
|
||||
useLocaleStore.setState({ locale: lang })
|
||||
document.documentElement.lang = lang
|
||||
|
||||
type Scenario = 'basic' | 'long' | 'guarded' | 'vanishing' | null
|
||||
|
||||
function Background({ onOpen }: { onOpen: (scenario: Scenario) => void }) {
|
||||
const [clicks, setClicks] = useState(0)
|
||||
return (
|
||||
<section className="space-y-3">
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Button onClick={() => onOpen('basic')}>Open basic</Button>
|
||||
<Button onClick={() => onOpen('long')}>Open long</Button>
|
||||
<Button onClick={() => onOpen('guarded')}>Open guarded</Button>
|
||||
</div>
|
||||
<Button variant="secondary" onClick={() => setClicks((n) => n + 1)}>
|
||||
Background action
|
||||
</Button>
|
||||
<p data-testid="background-clicks">{clicks}</p>
|
||||
<label className="block text-sm">
|
||||
Background field <input className="border" />
|
||||
</label>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function Harness() {
|
||||
const [scenario, setScenario] = useState<Scenario>(null)
|
||||
const [busy, setBusy] = useState(true)
|
||||
const [item, setItem] = useState(true)
|
||||
const close = () => setScenario(null)
|
||||
return (
|
||||
<main className="mx-auto max-w-2xl space-y-6 p-4">
|
||||
<h1 className="text-xl font-semibold">Dialog harness</h1>
|
||||
<Background onOpen={setScenario} />
|
||||
<section className="flex gap-2" data-testid="items">
|
||||
<Button variant="ghost" onClick={() => setItem(true)}>
|
||||
Add item
|
||||
</Button>
|
||||
{item && (
|
||||
<Button variant="danger" onClick={() => setScenario('vanishing')}>
|
||||
Remove item
|
||||
</Button>
|
||||
)}
|
||||
</section>
|
||||
{/* Taller than any viewport: the page would scroll if the dialog let it. */}
|
||||
<div className="h-[200vh]" aria-hidden="true" />
|
||||
|
||||
<Dialog
|
||||
open={scenario === 'basic'}
|
||||
onClose={close}
|
||||
title="Basic dialog"
|
||||
description={<p>Three controls follow.</p>}
|
||||
>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
<Button variant="ghost">First</Button>
|
||||
<Button variant="ghost">Second</Button>
|
||||
<Button onClick={close}>Done</Button>
|
||||
</div>
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
open={scenario === 'long'}
|
||||
onClose={close}
|
||||
title="Long dialog"
|
||||
size="lg"
|
||||
>
|
||||
{Array.from({ length: 60 }, (_, i) => (
|
||||
<p key={i} className="py-1 text-sm">
|
||||
Paragraph {i + 1}: long content that the panel scrolls on its own.
|
||||
</p>
|
||||
))}
|
||||
<Button onClick={close}>End of content</Button>
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
open={scenario === 'guarded'}
|
||||
onClose={() => !busy && close()}
|
||||
title="Guarded dialog"
|
||||
description={<p>Closing is refused while the box is checked.</p>}
|
||||
>
|
||||
<label className="mt-4 flex items-center gap-2 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={busy}
|
||||
onChange={(e) => setBusy(e.target.checked)}
|
||||
/>
|
||||
Busy
|
||||
</label>
|
||||
</Dialog>
|
||||
|
||||
<Dialog
|
||||
open={scenario === 'vanishing'}
|
||||
onClose={close}
|
||||
title="Remove the item?"
|
||||
description={<p>The button that opened this dialog disappears.</p>}
|
||||
size="sm"
|
||||
>
|
||||
<div className="mt-4 flex justify-end">
|
||||
<Button
|
||||
variant="danger"
|
||||
onClick={() => {
|
||||
setItem(false)
|
||||
close()
|
||||
}}
|
||||
>
|
||||
Confirm removal
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
createRoot(document.getElementById('root') as HTMLElement).render(
|
||||
<StrictMode>
|
||||
<Harness />
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* `pnpm e2e:ui`: Chromium against a Vite dev server with no backend, on a
|
||||
* loopback port of its own (never the owner's `pnpm dev` on 5173, never
|
||||
* reused): the Dialog test page and the local tool. docs/development/BROWSER_TESTS.md.
|
||||
*/
|
||||
import { defineConfig } from '@playwright/test'
|
||||
import type { GuardOptions } from './support/browser'
|
||||
import { PROJECTS } from './support/browser'
|
||||
|
||||
const ORIGIN = 'http://127.0.0.1:5191'
|
||||
|
||||
export default defineConfig<GuardOptions>({
|
||||
testDir: './ui',
|
||||
// The local tool runs the core: a missing or stale module stops the run (pnpm wasm:build).
|
||||
globalSetup: '../../../packages/core-wasm/tests/global-setup.ts',
|
||||
outputDir: './test-results/ui',
|
||||
fullyParallel: true,
|
||||
forbidOnly: true,
|
||||
retries: 0,
|
||||
reporter: [
|
||||
['list'],
|
||||
['html', { outputFolder: './playwright-report/ui', open: 'never' }],
|
||||
],
|
||||
use: {
|
||||
baseURL: ORIGIN,
|
||||
allowedOrigins: [ORIGIN],
|
||||
trace: 'retain-on-failure',
|
||||
screenshot: 'only-on-failure',
|
||||
},
|
||||
projects: PROJECTS,
|
||||
webServer: {
|
||||
command: 'node_modules/.bin/vite --host 127.0.0.1 --port 5191 --strictPort',
|
||||
cwd: '..',
|
||||
url: `${ORIGIN}/`,
|
||||
reuseExistingServer: false,
|
||||
timeout: 120_000,
|
||||
// No backend: an empty connection keeps any .env value out of this server.
|
||||
env: { VITE_SUPABASE_URL: '', VITE_SUPABASE_ANON_KEY: '' },
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* Shared pieces of the Playwright suites (docs/development/BROWSER_TESTS.md):
|
||||
* the two Chromium projects, the request guard every test runs under, the axe
|
||||
* gate, and the focus and layout probes.
|
||||
*/
|
||||
import AxeBuilder from '@axe-core/playwright'
|
||||
import {
|
||||
devices,
|
||||
expect,
|
||||
test as base,
|
||||
type Page,
|
||||
type Project,
|
||||
} from '@playwright/test'
|
||||
|
||||
/** Desktop and the 375 × 667 phone of the V1-1 contract (§12.5); Chromium only until V1-5. */
|
||||
export const PROJECTS: Project[] = [
|
||||
{
|
||||
name: 'chromium-desktop',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
viewport: { width: 1280, height: 800 },
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'chromium-375',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
viewport: { width: 375, height: 667 },
|
||||
deviceScaleFactor: 2,
|
||||
isMobile: true,
|
||||
hasTouch: true,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
export interface GuardOptions {
|
||||
/** Origins the page may reach; every other request is aborted and fails the test. */
|
||||
allowedOrigins: string[]
|
||||
/** Strings no request URL may carry (fixture names, emails, search terms). */
|
||||
forbiddenInUrls: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Every test runs under a request guard: a request to an origin outside the
|
||||
* allowlist (the DEV stack, a CDN, anything) is aborted, and the test fails
|
||||
* listing it, as it fails on a URL holding a fixture value.
|
||||
*/
|
||||
export const test = base.extend<GuardOptions & { requestGuard: void }>({
|
||||
allowedOrigins: [[], { option: true }],
|
||||
forbiddenInUrls: [[], { option: true }],
|
||||
requestGuard: [
|
||||
async ({ context, allowedOrigins, forbiddenInUrls }, use) => {
|
||||
const refused: string[] = []
|
||||
const leaking: string[] = []
|
||||
await context.route(
|
||||
(url) => !allowedOrigins.includes(url.origin),
|
||||
(route) => {
|
||||
refused.push(route.request().url())
|
||||
return route.abort('blockedbyclient')
|
||||
},
|
||||
)
|
||||
context.on('request', (request) => {
|
||||
const url = decodeURIComponent(request.url())
|
||||
if (forbiddenInUrls.some((value) => value && url.includes(value)))
|
||||
leaking.push(url)
|
||||
})
|
||||
await use()
|
||||
expect(refused, 'requests outside the allowed origins').toEqual([])
|
||||
expect(leaking, 'request URLs carrying a fixture value').toEqual([])
|
||||
},
|
||||
{ auto: true },
|
||||
],
|
||||
})
|
||||
|
||||
export { expect }
|
||||
|
||||
/**
|
||||
* Serious violations found before V1-1.3, outside its code, listed in TODO RR-7
|
||||
* until their own fix: the scan lets these exact nodes through and fails on any
|
||||
* other. The language switcher's buttons show « FR » / « EN » but are named
|
||||
* « Passer en français » / « Switch to English » (WCAG 2.5.3 label in name).
|
||||
*/
|
||||
const KNOWN_VIOLATIONS: { id: string; target: RegExp }[] = [
|
||||
{
|
||||
id: 'label-content-name-mismatch',
|
||||
target: /^button\[aria-label="(Passer en français|Switch to English)"\]$/,
|
||||
},
|
||||
]
|
||||
|
||||
const isKnown = (id: string, target: string) =>
|
||||
KNOWN_VIOLATIONS.some((known) => known.id === id && known.target.test(target))
|
||||
|
||||
/**
|
||||
* Zero serious or critical axe violation on the page as it stands (WCAG 2.0 to
|
||||
* 2.2 A and AA rules plus axe best practices), known ones aside; the failure
|
||||
* message lists them.
|
||||
*/
|
||||
export async function expectAccessible(
|
||||
page: Page,
|
||||
state: string,
|
||||
): Promise<void> {
|
||||
// Colours are measured at rest: an entrance animation still running would blend them.
|
||||
await page.waitForFunction(() =>
|
||||
document
|
||||
.getAnimations()
|
||||
.every((animation) => animation.playState !== 'running'),
|
||||
)
|
||||
const { violations } = await new AxeBuilder({ page })
|
||||
.withTags([
|
||||
'wcag2a',
|
||||
'wcag2aa',
|
||||
'wcag21a',
|
||||
'wcag21aa',
|
||||
'wcag22aa',
|
||||
'best-practice',
|
||||
])
|
||||
.analyze()
|
||||
const blocking = violations
|
||||
.filter((v) => v.impact === 'serious' || v.impact === 'critical')
|
||||
.flatMap((v) =>
|
||||
v.nodes
|
||||
.map((node) => node.target.join(' '))
|
||||
.filter((target) => !isKnown(v.id, target))
|
||||
.map((target) => `${v.impact} ${v.id}: ${v.help} → ${target}`),
|
||||
)
|
||||
expect(blocking, `axe on ${state}`).toEqual([])
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the focus is: in the open modal dialog, in the browser's own interface
|
||||
* (the document lost focus, as Tab past a modal dialog's last control does), or
|
||||
* on something else of the page.
|
||||
*/
|
||||
export function focusOwner(page: Page): Promise<string> {
|
||||
return page.evaluate(() => {
|
||||
const active = document.activeElement
|
||||
if (!document.hasFocus()) return 'browser'
|
||||
if (!active || active === document.body) return 'body'
|
||||
if (active.closest('dialog:modal')) return 'dialog'
|
||||
return `outside:${active.tagName.toLowerCase()}:${active.textContent?.trim().slice(0, 40)}`
|
||||
})
|
||||
}
|
||||
|
||||
/** Accessible name of the focused element (aria-label, else its text). */
|
||||
export function focusedName(page: Page): Promise<string> {
|
||||
return page.evaluate(() => {
|
||||
const active = document.activeElement as HTMLElement | null
|
||||
return (
|
||||
active?.getAttribute('aria-label') ?? active?.textContent?.trim() ?? ''
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/** No horizontal page scroll: the document is no wider than the viewport. */
|
||||
export async function expectNoHorizontalOverflow(
|
||||
page: Page,
|
||||
state: string,
|
||||
): Promise<void> {
|
||||
const { scrollWidth, clientWidth } = await page.evaluate(() => ({
|
||||
scrollWidth: document.documentElement.scrollWidth,
|
||||
clientWidth: document.documentElement.clientWidth,
|
||||
}))
|
||||
expect(scrollWidth, `horizontal overflow on ${state}`).toBeLessThanOrEqual(
|
||||
clientWidth,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": ["node", "vite/client"],
|
||||
"baseUrl": "..",
|
||||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["."]
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
import { en } from '@/i18n/en'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import {
|
||||
expect,
|
||||
expectAccessible,
|
||||
expectNoHorizontalOverflow,
|
||||
focusOwner,
|
||||
focusedName,
|
||||
test,
|
||||
} from '../support/browser'
|
||||
import type { Page } from '@playwright/test'
|
||||
|
||||
// The D13 contract of components/ui/Dialog on its test page (e2e/harness/dialog.tsx).
|
||||
|
||||
async function openScenario(page: Page, opener: string, title: string) {
|
||||
await page.getByRole('button', { name: opener }).focus()
|
||||
await page.keyboard.press('Enter')
|
||||
const dialog = page.getByRole('dialog', { name: title })
|
||||
await expect(dialog).toBeVisible()
|
||||
return dialog
|
||||
}
|
||||
|
||||
/** Names of the elements the focus visits over `count` presses of `key`. */
|
||||
async function focusWalk(page: Page, key: 'Tab' | 'Shift+Tab', count: number) {
|
||||
const visited: { owner: string; name: string }[] = []
|
||||
for (let i = 0; i < count; i++) {
|
||||
await page.keyboard.press(key)
|
||||
visited.push({
|
||||
owner: await focusOwner(page),
|
||||
name: await focusedName(page),
|
||||
})
|
||||
}
|
||||
return visited
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/e2e/harness/dialog.html')
|
||||
await expect(
|
||||
page.getByRole('heading', { name: 'Dialog harness' }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
test('is a named, described modal dialog and moves focus into it', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Open basic', 'Basic dialog')
|
||||
await expect(dialog).toHaveAccessibleDescription('Three controls follow.')
|
||||
expect(
|
||||
await dialog.evaluate((d) => d.tagName === 'DIALOG' && d.matches(':modal')),
|
||||
).toBe(true)
|
||||
expect(await focusOwner(page)).toBe('dialog')
|
||||
expect(await focusedName(page)).toBe(fr['common.close'])
|
||||
})
|
||||
|
||||
// Past either end the focus visits the browser's interface (one step, the page
|
||||
// holds no focus) and comes back into the dialog; it never reaches the page.
|
||||
test('Tab and Shift+Tab cycle through the dialog, never the page', async ({
|
||||
page,
|
||||
}) => {
|
||||
await openScenario(page, 'Open basic', 'Basic dialog')
|
||||
const step = (f: { owner: string; name: string }) =>
|
||||
f.owner === 'dialog' ? f.name : f.owner
|
||||
const forward = await focusWalk(page, 'Tab', 10)
|
||||
expect(forward.map(step)).toEqual([
|
||||
'First',
|
||||
'Second',
|
||||
'Done',
|
||||
'browser',
|
||||
fr['common.close'],
|
||||
'First',
|
||||
'Second',
|
||||
'Done',
|
||||
'browser',
|
||||
fr['common.close'],
|
||||
])
|
||||
const backward = await focusWalk(page, 'Shift+Tab', 10)
|
||||
expect(backward.map(step)).toEqual([
|
||||
'browser',
|
||||
'Done',
|
||||
'Second',
|
||||
'First',
|
||||
fr['common.close'],
|
||||
'browser',
|
||||
'Done',
|
||||
'Second',
|
||||
'First',
|
||||
fr['common.close'],
|
||||
])
|
||||
})
|
||||
|
||||
test('the page behind is inert: no focus, no click, no scroll', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Open guarded', 'Guarded dialog')
|
||||
const background = page.getByRole('button', {
|
||||
name: 'Background action',
|
||||
includeHidden: true,
|
||||
})
|
||||
const box = await background.boundingBox()
|
||||
if (!box) throw new Error('background button not laid out')
|
||||
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2)
|
||||
await background.evaluate((b) => (b as HTMLElement).focus())
|
||||
expect(await focusOwner(page)).toBe('dialog')
|
||||
await page.mouse.move(box.x + 5, box.y + 5)
|
||||
await page.mouse.wheel(0, 800)
|
||||
await page.waitForTimeout(200)
|
||||
expect(await page.evaluate(() => window.scrollY)).toBe(0)
|
||||
await expect(dialog).toBeVisible()
|
||||
await expect(page.getByTestId('background-clicks')).toHaveText('0')
|
||||
})
|
||||
|
||||
test('Escape closes when allowed and focus returns to the opener', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Open basic', 'Basic dialog')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toBeHidden()
|
||||
expect(await focusedName(page)).toBe('Open basic')
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Background action' }),
|
||||
).toBeEnabled()
|
||||
})
|
||||
|
||||
test('Escape is only a request: refused twice, the dialog stays open', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Open guarded', 'Guarded dialog')
|
||||
await page.keyboard.press('Escape')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toBeVisible()
|
||||
expect(await dialog.evaluate((d) => (d as HTMLDialogElement).open)).toBe(true)
|
||||
expect(await focusOwner(page)).toBe('dialog')
|
||||
await page.getByRole('checkbox', { name: 'Busy' }).uncheck()
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toBeHidden()
|
||||
expect(await focusedName(page)).toBe('Open guarded')
|
||||
})
|
||||
|
||||
test('the close button closes from the keyboard and restores focus', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Open basic', 'Basic dialog')
|
||||
expect(await focusedName(page)).toBe(fr['common.close'])
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(dialog).toBeHidden()
|
||||
expect(await focusedName(page)).toBe('Open basic')
|
||||
})
|
||||
|
||||
test('an opener gone on close hands focus to its container’s first control', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Remove item', 'Remove the item?')
|
||||
await page.getByRole('button', { name: 'Confirm removal' }).click()
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(page.getByRole('button', { name: 'Remove item' })).toHaveCount(0)
|
||||
expect(await focusedName(page)).toBe('Add item')
|
||||
})
|
||||
|
||||
test('long content scrolls inside the panel, the page stays put', async ({
|
||||
page,
|
||||
}) => {
|
||||
const dialog = await openScenario(page, 'Open long', 'Long dialog')
|
||||
const panel = dialog.locator('header').locator('..')
|
||||
const { scrollHeight, clientHeight } = await panel.evaluate((p) => ({
|
||||
scrollHeight: p.scrollHeight,
|
||||
clientHeight: p.clientHeight,
|
||||
}))
|
||||
expect(scrollHeight).toBeGreaterThan(clientHeight)
|
||||
expect(await focusedName(page)).toBe(fr['common.close'])
|
||||
await page.keyboard.press('Tab')
|
||||
const end = page.getByRole('button', { name: 'End of content' })
|
||||
await expect(end).toBeFocused()
|
||||
await expect(end).toBeInViewport()
|
||||
expect(await page.evaluate(() => window.scrollY)).toBe(0)
|
||||
const box = await panel.boundingBox()
|
||||
const viewport = page.viewportSize()
|
||||
expect(
|
||||
box && viewport && box.y >= 0 && box.y + box.height <= viewport.height,
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
test('fits the viewport without horizontal page scroll', async ({ page }) => {
|
||||
await expectNoHorizontalOverflow(page, 'the page')
|
||||
for (const [opener, title] of [
|
||||
['Open basic', 'Basic dialog'],
|
||||
['Open long', 'Long dialog'],
|
||||
]) {
|
||||
const dialog = await openScenario(page, opener, title)
|
||||
const box = await dialog.locator('header').locator('..').boundingBox()
|
||||
const width = page.viewportSize()?.width ?? 0
|
||||
expect(
|
||||
box && box.x >= 0 && box.x + box.width <= width,
|
||||
`${title} inside the viewport`,
|
||||
).toBe(true)
|
||||
await expectNoHorizontalOverflow(page, title)
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(dialog).toBeHidden()
|
||||
}
|
||||
})
|
||||
|
||||
for (const [lang, dict] of [
|
||||
['fr', fr],
|
||||
['en', en],
|
||||
] as const) {
|
||||
test(`axe finds no serious violation, close control named in ${lang}`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(`/e2e/harness/dialog.html?lang=${lang}`)
|
||||
await expectAccessible(page, `the harness (${lang})`)
|
||||
await openScenario(page, 'Open basic', 'Basic dialog')
|
||||
await expect(
|
||||
page.getByRole('button', { name: dict['common.close'] }),
|
||||
).toBeFocused()
|
||||
await expectAccessible(page, `the open dialog (${lang})`)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { en } from '@/i18n/en'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import {
|
||||
expect,
|
||||
expectAccessible,
|
||||
expectNoHorizontalOverflow,
|
||||
focusOwner,
|
||||
focusedName,
|
||||
test,
|
||||
} from '../support/browser'
|
||||
import type { Page } from '@playwright/test'
|
||||
import type { Dict } from '@/i18n/types'
|
||||
|
||||
// The shared Dialog where the local tool uses it, on the real routes with no
|
||||
// backend: the sheet disclaimer, the edit dialog and the replace confirmation.
|
||||
// Fictitious names only.
|
||||
|
||||
const ANIMAL = 'Fictif Alezan'
|
||||
|
||||
/** Required label text without the trailing « * » marker. */
|
||||
const label = (dict: Dict, key: string) => dict[key].replace(/\s*\*$/, '')
|
||||
|
||||
async function startReport(page: Page, dict: Dict) {
|
||||
await page
|
||||
.getByLabel(label(dict, 'form.practitioner.name'))
|
||||
.fill('Praticien Fictif')
|
||||
await page.getByLabel(label(dict, 'form.animal.name')).fill(ANIMAL)
|
||||
await page
|
||||
.getByLabel(label(dict, 'form.owner.name'))
|
||||
.fill('Propriétaire Fictif')
|
||||
await page.getByRole('button', { name: dict['new_report.submit'] }).click()
|
||||
}
|
||||
|
||||
for (const [locale, dict] of [
|
||||
['fr-FR', fr],
|
||||
['en-GB', en],
|
||||
] as const) {
|
||||
test.describe(`local tool (${locale})`, () => {
|
||||
test.use({ locale, forbiddenInUrls: [ANIMAL, 'Fictif'] })
|
||||
|
||||
test('editor dialogs: disclaimer, edit, replace confirmation', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto('/')
|
||||
// Scanned once the sheet is loaded: the import button fades in from disabled.
|
||||
await expect(
|
||||
page.getByRole('button', { name: dict['home.import.cta'] }),
|
||||
).toBeEnabled()
|
||||
await expectAccessible(page, 'home')
|
||||
await page
|
||||
.getByRole('button', { name: dict['home.new_report.cta'] })
|
||||
.click()
|
||||
await expect(page).toHaveURL(/\/new$/)
|
||||
await expectNoHorizontalOverflow(page, 'new report')
|
||||
await startReport(page, dict)
|
||||
|
||||
await expect(page).toHaveURL(/\/editor$/)
|
||||
const disclaimer = page.getByRole('dialog', {
|
||||
name: dict['editor.disclaimer_title'],
|
||||
})
|
||||
await expect(disclaimer).toBeVisible()
|
||||
expect(await disclaimer.getAttribute('aria-describedby')).toBeTruthy()
|
||||
expect(await focusOwner(page)).toBe('dialog')
|
||||
expect(await focusedName(page)).toBe(dict['common.close'])
|
||||
await page.keyboard.press('Tab')
|
||||
expect(await focusedName(page)).toBe(dict['common.understood'])
|
||||
await expectAccessible(page, 'editor with the disclaimer')
|
||||
await expectNoHorizontalOverflow(page, 'editor with the disclaimer')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(disclaimer).toBeHidden()
|
||||
|
||||
const edit = page.getByRole('button', { name: dict['editor.edit_infos'] })
|
||||
await edit.focus()
|
||||
await page.keyboard.press('Enter')
|
||||
const editDialog = page.getByRole('dialog', {
|
||||
name: dict['editor.edit_dialog_title'],
|
||||
})
|
||||
await expect(editDialog).toBeVisible()
|
||||
expect(await focusOwner(page)).toBe('dialog')
|
||||
await expectNoHorizontalOverflow(page, 'edit dialog')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(editDialog).toBeHidden()
|
||||
await expect(edit).toBeFocused()
|
||||
|
||||
// A reload: the bilan stays in the tab, not yet in the store (the « unloaded » message).
|
||||
await page.goto('/new')
|
||||
await startReport(page, dict)
|
||||
const replace = page.getByRole('dialog', {
|
||||
name: dict['session.replace.title'],
|
||||
})
|
||||
await expect(replace).toBeVisible()
|
||||
await expect(replace).toHaveAccessibleDescription(
|
||||
dict['session.replace.body_unloaded'],
|
||||
)
|
||||
await expectAccessible(page, 'replace confirmation')
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(replace).toBeHidden()
|
||||
await expect(page).toHaveURL(/\/new$/)
|
||||
await expect(
|
||||
page.getByRole('button', { name: dict['new_report.submit'] }),
|
||||
).toBeFocused()
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -8,10 +8,11 @@
|
||||
"dev": "vite",
|
||||
"build": "tsc -p tsconfig.json --noEmit && vite build",
|
||||
"preview": "vite preview",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p e2e/tsconfig.json --noEmit",
|
||||
"test": "vitest",
|
||||
"test:run": "vitest run",
|
||||
"lint": "eslint . --max-warnings 0"
|
||||
"lint": "eslint . --max-warnings 0",
|
||||
"e2e:ui": "playwright test -c e2e/playwright.ui.config.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@faunosteo/core-wasm": "workspace:*",
|
||||
@@ -24,6 +25,8 @@
|
||||
"zustand": "^5.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@axe-core/playwright": "4.14.0",
|
||||
"@playwright/test": "1.64.1",
|
||||
"@tailwindcss/vite": "^4.3.0",
|
||||
"@testing-library/jest-dom": "^6.6.3",
|
||||
"@testing-library/react": "^16.1.0",
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@
|
||||
"wasm:build:docker": "bash docker/rust-run.sh bash scripts/wasm-build.sh",
|
||||
"worker:test": "docker build -f crates/worker/Dockerfile --target test -t faunosteo_worker:test .",
|
||||
"worker:image": "docker build -f crates/worker/Dockerfile -t faunosteo_worker:dev .",
|
||||
"e2e:avatar": "bash scripts/avatar-e2e.sh"
|
||||
"e2e:avatar": "bash scripts/avatar-e2e.sh",
|
||||
"e2e:ui": "pnpm --filter @faunosteo/app e2e:ui"
|
||||
},
|
||||
"devDependencies": {
|
||||
"pnpm": "10.13.1",
|
||||
|
||||
Generated
+49
@@ -45,6 +45,12 @@ importers:
|
||||
specifier: ^5.0.2
|
||||
version: 5.0.13(@types/react@19.2.14)(react@19.2.6)
|
||||
devDependencies:
|
||||
'@axe-core/playwright':
|
||||
specifier: 4.14.0
|
||||
version: 4.14.0(playwright-core@1.64.1)
|
||||
'@playwright/test':
|
||||
specifier: 1.64.1
|
||||
version: 1.64.1
|
||||
'@tailwindcss/vite':
|
||||
specifier: ^4.3.0
|
||||
version: 4.3.0(vite@7.3.6(@types/node@20.19.41)(jiti@2.7.0)(lightningcss@1.32.0)(tsx@4.23.15))
|
||||
@@ -161,6 +167,12 @@ packages:
|
||||
'@adobe/css-tools@4.4.4':
|
||||
resolution: {integrity: sha512-Elp+iwUx5rN5+Y8xLt5/GRoG20WGoDCQ/1Fb+1LiGtvwbDavuSk0jhD/eZdckHAuzcDzccnkv+rEjyWfRx18gg==}
|
||||
|
||||
'@axe-core/playwright@4.14.0':
|
||||
resolution: {integrity: sha512-SGUhG5PIHd2eMdpgBF2PyQLOhX+qyDR2PT4cmoS4Qk2ak+jX/rrSvst9l0PGv5WTHolKpUMvVmoHpr4cZgf1RQ==}
|
||||
engines: {node: '>=22.12.0'}
|
||||
peerDependencies:
|
||||
playwright-core: '>= 1.0.0'
|
||||
|
||||
'@babel/code-frame@7.29.0':
|
||||
resolution: {integrity: sha512-9NhCeYjq9+3uxgdtp20LSiJXJvN0FeCtNGpJxuMFZ1Kv3cWUNb6DOhJwUvcVCzKGR66cw4njwM6hrJLqgOwbcw==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
@@ -424,6 +436,11 @@ packages:
|
||||
resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==}
|
||||
engines: {node: ^14.21.3 || >=16}
|
||||
|
||||
'@playwright/test@1.64.1':
|
||||
resolution: {integrity: sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg==}
|
||||
engines: {node: '>=20'}
|
||||
hasBin: true
|
||||
|
||||
'@rolldown/pluginutils@1.0.0-beta.27':
|
||||
resolution: {integrity: sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==}
|
||||
|
||||
@@ -1033,6 +1050,10 @@ packages:
|
||||
resolution: {integrity: sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
axe-core@4.14.0:
|
||||
resolution: {integrity: sha512-9WTZxEjsZ7b13TH8JPmbV2z8CHbl80/2hm3XPEG4JgNdQLK81IBRXmSxHfMAOkSqQeRxT/0dwNDz2GOm3zzpcQ==}
|
||||
engines: {node: '>=4'}
|
||||
|
||||
balanced-match@1.0.2:
|
||||
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
|
||||
|
||||
@@ -1252,6 +1273,7 @@ packages:
|
||||
eslint@9.39.4:
|
||||
resolution: {integrity: sha512-XoMjdBOwe/esVgEvLmNsD3IRHkm7fbKIUGvrleloJXUZgDHig2IPWNniv+GwjyJXzuNqVjlr5+4yVUZjycJwfQ==}
|
||||
engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0}
|
||||
deprecated: This version is no longer supported. Please see https://eslint.org/version-support for other options.
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
jiti: '*'
|
||||
@@ -1807,6 +1829,16 @@ packages:
|
||||
resolution: {integrity: sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
playwright-core@1.64.1:
|
||||
resolution: {integrity: sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==}
|
||||
engines: {node: '>=20'}
|
||||
hasBin: true
|
||||
|
||||
playwright@1.64.1:
|
||||
resolution: {integrity: sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==}
|
||||
engines: {node: '>=20'}
|
||||
hasBin: true
|
||||
|
||||
pnpm@10.13.1:
|
||||
resolution: {integrity: sha512-N+vxpcejDV+r4MXfRO6NpMllygxa89urKMOhaBtwolYhjQXIHJwNz3Z+9rhVHrW5YAQrntQwDFkkIzY3fgHPrQ==}
|
||||
engines: {node: '>=18.12'}
|
||||
@@ -2253,6 +2285,11 @@ snapshots:
|
||||
|
||||
'@adobe/css-tools@4.4.4': {}
|
||||
|
||||
'@axe-core/playwright@4.14.0(playwright-core@1.64.1)':
|
||||
dependencies:
|
||||
axe-core: 4.14.0
|
||||
playwright-core: 1.64.1
|
||||
|
||||
'@babel/code-frame@7.29.0':
|
||||
dependencies:
|
||||
'@babel/helper-validator-identifier': 7.28.5
|
||||
@@ -2436,6 +2473,10 @@ snapshots:
|
||||
|
||||
'@noble/hashes@1.8.0': {}
|
||||
|
||||
'@playwright/test@1.64.1':
|
||||
dependencies:
|
||||
playwright: 1.64.1
|
||||
|
||||
'@rolldown/pluginutils@1.0.0-beta.27': {}
|
||||
|
||||
'@rollup/rollup-android-arm-eabi@4.60.4':
|
||||
@@ -2999,6 +3040,8 @@ snapshots:
|
||||
dependencies:
|
||||
possible-typed-array-names: 1.1.0
|
||||
|
||||
axe-core@4.14.0: {}
|
||||
|
||||
balanced-match@1.0.2: {}
|
||||
|
||||
balanced-match@4.0.4: {}
|
||||
@@ -3868,6 +3911,12 @@ snapshots:
|
||||
|
||||
picomatch@4.0.4: {}
|
||||
|
||||
playwright-core@1.64.1: {}
|
||||
|
||||
playwright@1.64.1:
|
||||
dependencies:
|
||||
playwright-core: 1.64.1
|
||||
|
||||
pnpm@10.13.1: {}
|
||||
|
||||
possible-typed-array-names@1.1.0: {}
|
||||
|
||||
Reference in new issue
Block a user