Files
faunosteo/apps/app/e2e/shell/editor-shell-layout.spec.ts
T
bchanot 0467885527 fix(editor): final review fixes (touch undo guard, focus, save line)
Important 1: a touch press fires pointer leave between up and click; only a
mouse leave (or a pointer cancel) forgets the refused field, so Annuler no
longer undoes an unrelated change. Important 2: the LAN spec reads the
revision before the attach, through shownRevision, which throws instead of NaN
(spec stays not run). Minor 1: refocusIfHidden refocuses a still shown element
the commit blurred (references search on a 1 024 px crossing). Minor 2:
discardChanges keeps lastSave (reload path still drops it). Minor 3: the
overview filter term lives in UiState / the read-only twin, not the card.
Minor 4: categories section drops its inner h3 and the unused
editor.general.categories keys. AC8: badge test.

Assertions rewritten or added (R-24):
- editor-tabs-general « Général no longer holds the categories editor »:
  queryByText of the deleted heading (now vacuous) -> queryByLabelText of the
  category name fields.
- editor-focus-request « Annotations: selects the annotation »: findAllByText
  /anno-b|Sélection/ -> the properties panel holds Centre x = 20 (anno-b) and
  owns the focused heading.
- editor-shell-layout panel walk: added after.at(-1) === 'side'.
- editor-recovery title « Annuler les modifications » -> « Abandonner ».
- new: touch/cancel/mouse press, references search crossing, discard keeps
  lastSave, filter kept, one categories heading, badge 1/2/0, shownRevision.
2026-11-09 12:19:32 +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, Annuler, Rétablir, 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, Annuler, Rétablir, 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')
})
})