@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.
135 lines
4.2 KiB
TypeScript
135 lines
4.2 KiB
TypeScript
/**
|
|
* 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>,
|
|
)
|