Files
faunosteo/apps/app/e2e/shell/editor-shell-layout.spec.ts
T
bchanot 7dda61d2ae feat(app): history reads Défaire / Refaire (R1, D5)
FR names Défaire / Refaire; title = name + shortcut (Ctrl+Z ou ⌘Z /
Ctrl+Maj+Z ou ⇧⌘Z), aria-label = name, aria-keyshortcuts adds Meta forms.
New keys editor.history.{undo,redo}_shortcut (fr, en). FR prose use_parent_body
and repair.body_one/_other say Défaire. Dialog Annuler unchanged.

Assertion map (R-24):
- editor-history-buttons.test.tsx UNDO/REDO constants 'Annuler la dernière
  modification' / 'Rétablir la dernière modification annulée' → 'Défaire la
  dernière modification' / 'Refaire la dernière modification défaite'
- :80-81 title === UNDO/REDO → title `${UNDO} (Ctrl+Z ou ⌘Z)` / `${REDO}
  (Ctrl+Maj+Z ou ⇧⌘Z)`
- :82-83 aria-keyshortcuts 'Control+Z' / 'Control+Shift+Z' → 'Control+Z
  Meta+Z' / 'Control+Shift+Z Meta+Shift+Z'
- visible labels ['Annuler','Rétablir'] → ['Défaire','Refaire']
- tool column absence /Annuler|Rétablir/ → /Défaire|Refaire/ (also
  editor-annotations-tab.test.tsx:514)
- Rétablir button lookup by literal name → REDO constant
- added: EN names unchanged with title '(Ctrl+Z or ⌘Z)'; FR prose contains
  Défaire while use_parent_cancel stays 'Annuler'
- e2e titles/comments only: Annuler/Rétablir → Défaire/Refaire
2026-11-12 12:39:01 +01:00

314 lines
10 KiB
TypeScript

import { fr } from '@/i18n/fr'
import type { Page, TestInfo } from '@playwright/test'
import { stepUpAdmin } from '../support/admin'
import {
expect,
expectAccessible,
expectNoHorizontalOverflow,
test,
} from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
SECTIONS,
TABS,
closeReferences,
draftPath,
draftTitle,
editorActor,
historyButton,
openEditor,
openReferences,
openSection,
pickAnnotation,
pointOf,
seedDraft,
selectTab,
shapeWith,
showDrawing,
} from '../support/editor'
import { signIn } from '../support/shell'
// V1-2.6 U1 H (AC10, AC11, AC17): the layout of the four-tab shell at every width, the
// keyboard order of the editor, and axe on every place, edit and narrow read-only.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const WIDTHS = [1024, 1180, 1279, 1280]
const NARROW_WIDTHS = [320, 375, 768]
const point = pointOf(
'anno-free',
'main',
{ cx: 120, cy: 120, r: 6 },
'Point libre',
)
async function open(page: Page) {
const actor = await editorActor('fr')
const seed = await seedDraft(actor, { shape: shapeWith(point) })
await openEditor(page, dict, actor, seed.sheetId)
return { ...seed, actor }
}
/** Opens the tab, through « Plus » when the width keeps it out of the row. */
async function goToTab(page: Page, tab: (typeof TABS)[number]) {
const direct = page.locator(`#editor-tab-${tab}`)
if ((await direct.count()) === 0) {
await page.getByRole('button', { name: dict['editor.tab.more'] }).click()
}
await direct.click()
await expect(
page.locator(`[data-place^="${tab}"]:visible`).first(),
).toBeVisible()
}
async function settle(page: Page) {
await page.evaluate(
() =>
new Promise((done) =>
requestAnimationFrame(() => requestAnimationFrame(done)),
),
)
}
test.describe('editor shell layout (H)', () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
test.beforeEach(async ({ context }, info) => {
test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
test('no horizontal scroll from 1 024 to 1 280 px on the four tabs, the three sections and the open panel', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
for (const width of WIDTHS) {
await page.setViewportSize({ width, height: 800 })
for (const tab of TABS) {
await selectTab(page, dict, tab)
await expectNoHorizontalOverflow(page, `${tab} at ${width} px`)
}
for (const section of SECTIONS) {
await openSection(page, dict, section)
await expectNoHorizontalOverflow(page, `${section} at ${width} px`)
}
await showDrawing(page, dict)
await openReferences(page, dict)
await expectNoHorizontalOverflow(page, `the panel at ${width} px`)
await closeReferences(page, dict)
}
})
test('read-only at 320, 375 and 768 px: the four tabs fit and pass axe', async ({
page,
requests,
}) => {
test.setTimeout(150_000)
const actor = await editorActor('fr')
requests.forbid(actor.account.email, actor.account.password)
const seed = await seedDraft(actor, { shape: shapeWith(point) })
await signIn(page, actor.account, dict)
await page.goto('/app/admin')
await stepUpAdmin(page, dict, actor.secret)
for (const width of NARROW_WIDTHS) {
await page.setViewportSize({ width, height: 800 })
await page.goto(draftPath(seed.sheetId))
await expect(
page.getByRole('heading', { level: 1, name: draftTitle(dict) }),
).toBeVisible()
for (const tab of TABS) {
await goToTab(page, tab)
await expectNoHorizontalOverflow(page, `${tab} at ${width} px`)
await expect(
page.getByRole('button', { name: dict['common.save'], exact: true }),
).toHaveCount(0)
if (width !== 320) await expectAccessible(page, `${tab} at ${width} px`)
}
for (const kind of ['undo', 'redo'] as const) {
await expect(historyButton(page, dict, kind)).toHaveAttribute(
'aria-disabled',
'true',
)
}
}
})
test('the canvas width, the same measure without and with the references panel', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
for (const panel of [false, true]) {
for (const width of WIDTHS) {
await page.setViewportSize({ width, height: 800 })
await showDrawing(page, dict)
await pickAnnotation(page, dict, 'Point libre')
if (panel) await openReferences(page, dict)
const canvas = await page.getByTestId('annotation-canvas').boundingBox()
test.info().annotations.push({
type: panel ? 'canvas-width-panel' : 'canvas-width',
description: `${canvas?.width}px at ${width}px`,
})
if (panel) await closeReferences(page, dict)
}
}
})
test('axe from the top on the four tabs, each section and the open panel', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
for (const width of [1024, 1280]) {
await page.setViewportSize({ width, height: 800 })
const places: (readonly [string, () => Promise<void>])[] = [
...TABS.map((tab) => [tab, () => selectTab(page, dict, tab)] as const),
...SECTIONS.map(
(section) =>
[section, () => openSection(page, dict, section)] as const,
),
]
for (const [name, show] of places) {
await show()
await settle(page)
await page.evaluate(() => window.scrollTo(0, 0))
await expect(page.locator('dialog[open]')).toHaveCount(0)
await expectAccessible(page, `${name} at ${width} px`)
}
await showDrawing(page, dict)
await openReferences(page, dict)
await settle(page)
await page.evaluate(() => window.scrollTo(0, 0))
await expect(page.locator('dialog[open]')).toHaveCount(0)
await expectAccessible(page, `the open panel at ${width} px`)
await closeReferences(page, dict)
}
})
for (const width of WIDTHS) {
test(`the history buttons stay reachable at the top of the page at ${width} px`, async ({
page,
}) => {
await open(page)
await page.setViewportSize({ width, height: 800 })
await page.evaluate(() => window.scrollTo(0, 0))
for (const kind of ['undo', 'redo'] as const) {
const hit = await historyButton(page, dict, kind).evaluate((button) => {
const box = button.getBoundingClientRect()
const at = document.elementFromPoint(
box.x + box.width / 2,
box.y + box.height / 2,
)
return { top: box.y, covered: !at || !button.contains(at) }
})
test.info().annotations.push({
type: 'history-button-top',
description: `${kind} y=${hit.top} at ${width}px covered=${hit.covered}`,
})
expect(hit.covered, `${kind} at ${width} px`).toBe(false)
}
})
}
})
type Kind =
| 'header'
| 'tab'
| 'undo'
| 'redo'
| 'panel'
| 'tools'
| 'canvas'
| 'side'
| 'other'
/** What the focused element is, in the words of the keyboard order of AC17. */
function focusKind(page: Page): Promise<Kind> {
return page.evaluate((undoName) => {
const el = document.activeElement
if (!el) return 'other'
if (el.closest('[data-place="references"]')) return 'panel'
if (el.getAttribute('role') === 'tab') return 'tab'
if (el.closest('[data-testid="history-buttons"]')) {
return el.getAttribute('aria-label') === undoName ? 'undo' : 'redo'
}
if (el.closest('main header')) return 'header'
if (el.closest('[role="toolbar"]')) return 'tools'
if (el.closest('[data-testid="annotation-canvas"]')) return 'canvas'
if (el.closest('[data-testid="annotation-overview"]')) return 'side'
if (el.closest('[data-testid="annotation-properties"]')) return 'side'
return 'other'
}, dict['editor.history.undo_title'])
}
/** Tabs forward from the page heading until `stop` is reached; the kinds met, without repeats. */
async function walk(page: Page, stop: Kind): Promise<Kind[]> {
await page.getByRole('heading', { level: 1, name: draftTitle(dict) }).focus()
const seen: Kind[] = []
for (let step = 0; step < 60; step++) {
await page.keyboard.press('Tab')
const kind = await focusKind(page)
if (kind !== 'other' && seen[seen.length - 1] !== kind) seen.push(kind)
if (kind === stop) break
}
return seen
}
test.describe('editor shell keyboard order (H)', () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
test.beforeEach(async ({ context }, info) => {
test.skip(isPhone(info), 'keyboard order is checked at one width') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
test('header, tab list, Défaire, Refaire, then the tools, the canvas and the side column', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'annotations')
await expect(page.getByTestId('annotation-canvas')).toBeVisible()
const order = await walk(page, 'side')
test.info().annotations.push({
type: 'keyboard-order',
description: order.join(' > '),
})
expect(order).toEqual([
'header',
'tab',
'undo',
'redo',
'tools',
'canvas',
'side',
])
})
test('with the panel open: header, tab list, Défaire, Refaire, the panel, then the page content', async ({
page,
}) => {
await open(page)
await openReferences(page, dict)
const order = await walk(page, 'panel')
test.info().annotations.push({
type: 'keyboard-order-panel',
description: order.join(' > '),
})
expect(order).toEqual(['header', 'tab', 'undo', 'redo', 'panel'])
await page.keyboard.press('Escape')
await expect(page.locator('[data-place="references"]:visible')).toHaveCount(
0,
)
const after = await walk(page, 'side')
expect(after.slice(0, 4)).toEqual(['header', 'tab', 'undo', 'redo'])
expect(after).not.toContain('panel')
expect(after.at(-1)).toBe('side')
})
})