test(tests): working-copy dialog checks independent of the shared slot

admin.spec opened the working-copy dialog on the historical sheet, whose
single slot was taken by a copy the sandbox suite leaked. The dialog checks
move to an e2e:ui page on the real component; the suite archives its own copies.
This commit is contained in:
bchanot committed 2026-11-12 17:06:42 +01:00
1 parent da298cfab1
commit 2cdee42fe1
9 files changed
+304 -25

No files matched your search

+12
View File
@@ -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>Working copy harness</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./working-copy.tsx"></script>
</body>
</html>
+60
View File
@@ -0,0 +1,60 @@
/**
* Test page for the real « Créer une copie de travail » action in a real
* browser (e2e/ui/working-copy.spec.ts). Served by the Vite dev server only
* (`/e2e/harness/working-copy.html`); the build has a single entry, index.html,
* so this page never ships. The action is the application's own component,
* rendered with the slot free and with the slot taken (the two states the
* historical sheet page shows); no request is made unless the form is
* submitted, which the spec never does. `?lang=en` picks the language.
*/
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { MemoryRouter } from 'react-router-dom'
import '@/styles/index.css'
import WorkingCopyAction from '@/components/admin/WorkingCopyAction'
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
const SLUG = 'faunosteo-cheval'
const SOURCE_VERSION_ID = '00000000-0000-4000-8000-000000000001'
function Harness() {
return (
<main className="mx-auto max-w-2xl space-y-6 p-4">
<h1 className="text-xl font-semibold">Working copy harness</h1>
<section aria-labelledby="slot-free" className="space-y-2">
<h2 id="slot-free" className="text-lg font-semibold">
Slot free
</h2>
<WorkingCopyAction
slug={SLUG}
sourceVersionId={SOURCE_VERSION_ID}
copyActive={false}
/>
</section>
<section aria-labelledby="slot-taken" className="space-y-2">
<h2 id="slot-taken" className="text-lg font-semibold">
Slot taken
</h2>
<WorkingCopyAction
slug={SLUG}
sourceVersionId={SOURCE_VERSION_ID}
copyActive={true}
/>
</section>
</main>
)
}
createRoot(document.getElementById('root') as HTMLElement).render(
<StrictMode>
<MemoryRouter>
<Harness />
</MemoryRouter>
</StrictMode>,
)
+1 -1
View File
@@ -1,7 +1,7 @@
/**
* `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, the local tool and the canvas click proof (also on
* reused): the Dialog and working-copy test pages, the local tool and the canvas click proof (also on
* Firefox and WebKit when installed). docs/development/BROWSER_TESTS.md.
*/
import { defineConfig } from '@playwright/test'
+16 -12
View File
@@ -750,20 +750,24 @@ for (const [locale, dict] of LANGUAGES) {
await expectAccessible(page, `${path} at ${width} px`)
await expectNoHorizontalOverflow(page, `${path} at ${width} px`)
}
// The working copy dialog on the historical sheet (W1 start), opened only.
await page
.getByRole('button', { name: dict['admin.working_copy.create'] })
.first()
.click()
const copy = page.getByRole('dialog', {
// The historical page is left on the page loop's last entry. Its working
// copy button follows the single slot, shared database state: disabled
// exactly when the reason is shown and linked to it. The dialog itself is
// checked on the real component in e2e/ui/working-copy.spec.ts.
const action = main(page).getByRole('button', {
name: dict['admin.working_copy.create'],
})
await expect(copy).toBeVisible()
await expectAccessible(page, `the working copy dialog at ${width} px`)
await expectNoHorizontalOverflow(
page,
`the working copy dialog at ${width} px`,
)
await expect(action).toBeVisible()
const reason = main(page).getByText(dict['admin.working_copy.active'])
if ((await reason.count()) > 0) {
await expect(action).toBeDisabled()
await expect(action).toHaveAccessibleDescription(
dict['admin.working_copy.active'],
)
} else {
await expect(action).toBeEnabled()
await expect(action).not.toHaveAttribute('aria-describedby')
}
})
})
}
+158
View File
@@ -0,0 +1,158 @@
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 real WorkingCopyAction (components/admin) on its test page
// (e2e/harness/working-copy.tsx): the dialog's accessibility, layout and
// keyboard checks that e2e/shell/admin.spec.ts cannot make on the historical
// sheet, where the single working-copy slot is shared, mutable database state.
const SLUG_FIELD = 'working-copy-slug'
for (const [lang, dict] of [
['fr', fr],
['en', en],
] as const) {
const create = dict['admin.working_copy.create']
const free = (page: Page) => page.getByRole('region', { name: 'Slot free' })
const taken = (page: Page) => page.getByRole('region', { name: 'Slot taken' })
/** Opens the dialog from the keyboard, as the spec's own opener. */
async function openDialog(page: Page) {
await free(page).getByRole('button', { name: create }).focus()
await page.keyboard.press('Enter')
const dialog = page.getByRole('dialog', { name: create })
await expect(dialog).toBeVisible()
return dialog
}
/** What the focus is on: the slug field by its id, else its accessible name. */
async function focusStep(page: Page) {
const owner = await focusOwner(page)
if (owner !== 'dialog') return owner
const onField = await page.evaluate(
(id) => document.activeElement?.id === id,
SLUG_FIELD,
)
return onField ? SLUG_FIELD : await focusedName(page)
}
async function walk(page: Page, key: 'Tab' | 'Shift+Tab', count: number) {
const visited: string[] = []
for (let i = 0; i < count; i++) {
await page.keyboard.press(key)
visited.push(await focusStep(page))
}
return visited
}
test.describe(lang, () => {
test.beforeEach(async ({ page }) => {
await page.goto(`/e2e/harness/working-copy.html?lang=${lang}`)
await expect(
page.getByRole('heading', { name: 'Working copy harness' }),
).toBeVisible()
})
test('the page passes axe with both states, no sideways scroll', async ({
page,
}) => {
await expectAccessible(page, `the working copy page (${lang})`)
await expectNoHorizontalOverflow(page, `the working copy page (${lang})`)
})
test('slot taken: the button is disabled and gives its reason', async ({
page,
}) => {
const button = taken(page).getByRole('button', { name: create })
await expect(button).toBeDisabled()
await expect(button).toHaveAccessibleDescription(
dict['admin.working_copy.active'],
)
await expect(free(page).getByRole('button')).toBeEnabled()
})
test('opens from the keyboard, named, described, slug proposed', async ({
page,
}) => {
const dialog = await openDialog(page)
await expect(dialog).toHaveAccessibleDescription(
dict['admin.working_copy.body'],
)
await expect(dialog.locator(`#${SLUG_FIELD}`)).toHaveValue(
'faunosteo-cheval-copie-de-travail',
)
expect(await focusOwner(page)).toBe('dialog')
expect(await focusedName(page)).toBe(dict['common.close'])
})
// Past either end the focus visits the browser's interface (one step) and
// comes back into the dialog; it never reaches the page behind.
test('Tab and Shift+Tab cycle through the dialog, never the page', async ({
page,
}) => {
await openDialog(page)
const order = [
SLUG_FIELD,
dict['common.cancel'],
dict['admin.working_copy.confirm'],
'browser',
dict['common.close'],
]
expect(await walk(page, 'Tab', 10)).toEqual([...order, ...order])
const back = [
'browser',
dict['admin.working_copy.confirm'],
dict['common.cancel'],
SLUG_FIELD,
dict['common.close'],
]
expect(await walk(page, 'Shift+Tab', 10)).toEqual([...back, ...back])
})
test('the open dialog passes axe and fits the viewport', async ({
page,
}) => {
const dialog = await openDialog(page)
await expectAccessible(page, `the working copy dialog (${lang})`)
await expectNoHorizontalOverflow(
page,
`the working copy dialog (${lang})`,
)
const panel = dialog.locator('header').locator('..')
const box = await panel.boundingBox()
const viewport = page.viewportSize()
expect(
box &&
viewport &&
box.x >= 0 &&
box.x + box.width <= viewport.width &&
box.y >= 0 &&
box.y + box.height <= viewport.height,
'the panel inside the viewport',
).toBe(true)
const { scrollWidth, clientWidth } = await panel.evaluate((p) => ({
scrollWidth: p.scrollWidth,
clientWidth: p.clientWidth,
}))
expect(scrollWidth, 'the panel scrolls sideways').toBeLessThanOrEqual(
clientWidth,
)
})
test('Escape closes and focus returns to the opener', async ({ page }) => {
const dialog = await openDialog(page)
await page.keyboard.press('Escape')
await expect(dialog).toBeHidden()
expect(await focusedName(page)).toBe(create)
})
})
}