Files
faunosteo/apps/app/e2e/shell/editor-shell-journeys.spec.ts
T
bchanot 606f7ba268 fix(app): crossing focus for any element in a hidden part
Focus held by any element that a crossing hides or unmounts (button, tool,
canvas, link) goes to the shown tab, decided by the element leaving the page,
not by tag; a field still commits first; visible focus stays.
History pair: remembered field must be connected, and a pointer-down off a
field keeps it. TextField.commit compares with the latest committed value.
Open-panel axe settles and checks dialogs like the other places.

R-24: no assertion rewritten or deleted; one Chromium case and three unit
tests added.
2026-11-08 20:43:27 +01:00

273 lines
9.1 KiB
TypeScript

import { fr } from '@/i18n/fr'
import type { Page, TestInfo } from '@playwright/test'
import { expect, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
TABS,
closeReferences,
draftTitle,
editorActor,
historyButton,
openEditor,
place,
pointOf,
pressAtBox,
saveLine,
seedDraft,
selectTab,
shapeWith,
standardShape,
UNSAVED_LINE,
} from '../support/editor'
// V1-2.6 U1 H (AC1, AC5, AC12, AC13, AC17): the journeys of the four-tab shell in a real
// browser. Every query is scoped to the visible place (`place()`) or goes by role, so a
// hidden, kept-mounted copy never answers.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const active = (page: Page) => page.locator(':focus')
const nameField = (page: Page) => page.locator('#general-name-fr')
const ghost = 'absent'
/** A document that carries one issue of each kind « Aller à » can reach. */
function issueShape(document: Record<string, unknown>) {
standardShape(document)
const text = (value: string) => ({ fr: value, en: value })
const views = document.views as unknown[]
views.push({
id: 'detail-b',
kind: 'detail',
name: text('Détail B'),
svg_asset_id: null,
view_box: { min_x: 0, min_y: 0, width: 100, height: 80 },
parent_view_id: ghost,
})
const categories = document.categories as unknown[]
categories.push({ id: 'cat-a', name: text('Catégorie bis'), color: null })
document.vertebral_config = {
regions: [
{
code: 'T',
name: text('Thoracique'),
count: 5,
count_range: { min: 9, max: 3 },
},
],
}
const reference = (citation: string) => ({
id: 'ref-a',
type: 'book',
citation,
url: null,
doi: null,
})
document.references = [reference('Barone, Ostéologie'), reference('Bis')]
const point = pointOf(
'anno-free',
'main',
{ cx: 120, cy: 120, r: 6 },
'Point libre',
)
document.annotations = [
{ ...point, category_id: ghost, finding_zone_id: null },
]
const zones = document.finding_zones as {
categories: { children: { reference_ids: string[] }[] }[]
}[]
zones[0].categories[0].children[0].reference_ids = [ghost]
}
async function open(page: Page, shape = shapeWith()) {
const actor = await editorActor('fr')
const seed = await seedDraft(actor, { shape })
await openEditor(page, dict, actor, seed.sheetId)
return { ...seed, actor }
}
async function commitName(page: Page, value: string) {
await selectTab(page, dict, 'general')
await nameField(page).fill(value)
await nameField(page).press('Enter')
}
const unsaved = (page: Page, count: number) =>
expect(saveLine(page)).toHaveText(
dict[
count === 1
? 'editor.draft.status.unsaved_count_one'
: 'editor.draft.status.unsaved_count_other'
].replace('{count}', String(count)),
)
test.describe('editor shell journeys (H)', () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
test.beforeEach(async ({ context }, info) => {
test.skip(isPhone(info), 'editing needs 1 024 px') // 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('four tabs and no tab of the old layout', async ({ page }) => {
await open(page)
const tabs = page.getByRole('tablist').getByRole('tab')
await expect(tabs).toHaveCount(4)
for (const [index, tab] of TABS.entries()) {
await expect(tabs.nth(index)).toHaveText(
new RegExp(`^${dict[`editor.tab.${tab}`]}`),
)
}
for (const old of ['Vues et illustrations', 'Références', 'Vertèbres']) {
await expect(page.getByRole('tab', { name: old })).toHaveCount(0)
}
})
test('undo from another tab reverts the change, redo brings it back', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'general')
const original = await nameField(page).inputValue()
await commitName(page, 'Nom depuis Général')
await unsaved(page, 1)
await selectTab(page, dict, 'findings')
await historyButton(page, dict, 'undo').click()
await selectTab(page, dict, 'general')
await expect(nameField(page)).toHaveValue(original)
await historyButton(page, dict, 'redo').click()
await expect(nameField(page)).toHaveValue('Nom depuis Général')
await unsaved(page, 1)
})
test('text typed without a blur is committed by the header undo, which then reverts it', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'general')
const original = await nameField(page).inputValue()
await nameField(page).fill('Saisi, jamais validé')
// « Annuler » is aria-disabled until the typed text is committed: press at its box.
await pressAtBox(page, historyButton(page, dict, 'undo'))
await expect(nameField(page)).toHaveValue(original)
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
await historyButton(page, dict, 'redo').click()
await expect(nameField(page)).toHaveValue('Saisi, jamais validé')
})
test('a field left empty keeps its error: Tab to « Annuler », Enter, nothing undone, focus back', async ({
page,
}) => {
await open(page)
await commitName(page, 'Premier nom')
await nameField(page).fill('')
const undo = historyButton(page, dict, 'undo')
for (let step = 0; step < 40; step++) {
await page.keyboard.press('Shift+Tab')
if (await undo.evaluate((button) => button === document.activeElement))
break
}
await expect(undo).toBeFocused()
await expect(nameField(page)).toHaveAttribute('aria-invalid', 'true')
await page.keyboard.press('Enter')
await expect(nameField(page)).toBeFocused()
await unsaved(page, 1)
await expect(undo).toHaveAttribute('aria-disabled', 'false')
await expect(historyButton(page, dict, 'redo')).toHaveAttribute(
'aria-disabled',
'true',
)
})
test('Ctrl+Z outside a field undoes, inside a field it leaves the history alone', async ({
page,
}) => {
await open(page)
await commitName(page, 'Nom un')
await commitName(page, 'Nom deux')
await unsaved(page, 2)
await page
.getByRole('heading', { level: 1, name: draftTitle(dict) })
.click()
await page.keyboard.press('Control+z')
await unsaved(page, 1)
await expect(nameField(page)).toHaveValue('Nom un')
await nameField(page).click()
await nameField(page).pressSequentially(' suite')
await page.keyboard.press('Control+z')
// The field's own undo ran; the document history did not (a second step would show 0).
await unsaved(page, 1)
})
test('« Aller à » reaches the place and the element of each issue kind', async ({
page,
}) => {
await open(page, issueShape)
const goTo = (name: string) =>
place(page, 'verification')
.getByRole('button', { name: `Aller à ${name}`, exact: true })
.first()
.click()
const focusKey = (id: string) =>
expect(active(page)).toHaveAttribute('data-focus-key', new RegExp(id))
await selectTab(page, dict, 'verification')
await goTo('Détail B')
await expect(place(page, 'annotations.views')).toBeVisible()
await focusKey('detail-b')
await selectTab(page, dict, 'verification')
await goTo('Catégorie A')
await expect(place(page, 'annotations.categories')).toBeVisible()
await focusKey('cat-a')
await selectTab(page, dict, 'verification')
await goTo('Thoracique')
await expect(place(page, 'annotations.regions')).toBeVisible()
await focusKey('"T"')
await selectTab(page, dict, 'verification')
await goTo('Point libre')
await expect(place(page, 'annotations.drawing')).toBeVisible()
await expect(active(page)).toHaveAttribute(
'data-properties-heading',
'true',
)
await selectTab(page, dict, 'verification')
await goTo('Constat A')
await expect(place(page, 'findings')).toBeVisible()
await expect(place(page, 'findings').locator(':focus')).toHaveCount(1)
await selectTab(page, dict, 'verification')
await goTo('Barone, Ostéologie')
await expect(place(page, 'references')).toBeVisible()
await focusKey('ref-a')
await closeReferences(page, dict)
})
test('the save line goes from the count to « Enregistrement… » to the time and the revision', async ({
page,
context,
}) => {
const seed = await open(page)
await context.route('**/rest/v1/rpc/save_sheet_draft', async (route) => {
await new Promise((done) => setTimeout(done, 1500))
await route.fallback()
})
await commitName(page, 'Nom à enregistrer')
await unsaved(page, 1)
await page
.getByRole('button', { name: dict['common.save'], exact: true })
.click()
await expect(saveLine(page)).toHaveText(dict['editor.draft.status.saving'])
const timed = dict['editor.draft.status.saved_at']
.replace('{time}', '\\d\\d:\\d\\d')
.replace('{revision}', String(seed.revision + 1))
await expect(saveLine(page)).toHaveText(new RegExp(`^${timed}$`))
})
})