Files
faunosteo/apps/app/e2e/shell/editor-shell-crossing.spec.ts
T
bchanot 2c4c771269 test(editor): e2e on the references dialog instead of the sheet
Helpers citationsDialog, closeCitations by the dialog's ✕. Owner journey
with tap at 375, keyboard and axe; geometry checks now dialog in viewport
with focus inside; refused « Tout afficher » over a dirty form.
2026-11-15 16:15:43 +01:00

410 lines
14 KiB
TypeScript

import { fr } from '@/i18n/fr'
import type { Locator, Page, TestInfo } from '@playwright/test'
import { expect, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
clientOf,
closeCitations,
closeFinding,
copyKeyOf,
editorActor,
expectNoDialog,
geometryField,
historyButton,
openEditor,
openCitations,
openTab,
openSection,
pickAnnotation,
place,
pointOf,
saveLine,
seedDraft,
selectTab,
shapeWith,
standardShape,
startReference,
storedCopy,
UNSAVED_LINE,
} from '../support/editor'
// V1-2.6 U1 H (AC11, AC21): a width change across 1 024 px in a real browser. Every
// edit-only part keeps what was typed, nothing is editable or focused below the threshold,
// the unsaved work stays, dialogs that confirm an edit close, a drag in flight commits
// nothing. Queries go to the visible place or by role; hidden parts stay in the DOM.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const active = (page: Page) => page.locator(':focus')
const dialogs = (page: Page) => page.locator('dialog[open]')
const NARROW = { width: 800, height: 900 }
const WIDE = { width: 1280, height: 900 }
const spareCategory = (document: Record<string, unknown>) => {
standardShape(document)
;(document.categories as unknown[]).push({
id: 'cat-spare',
name: { fr: 'Libre', en: 'Free' },
color: null,
})
}
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 page.locator('#general-name-fr').fill(value)
await page.locator('#general-name-fr').press('Enter')
}
/** The editor is read-only in this page: no save, no text field, no edit toolbar. */
async function expectReadOnly(page: Page) {
await expect(
page.getByRole('button', { name: dict['common.save'], exact: true }),
).toHaveCount(0)
await expect(page.getByRole('textbox')).toHaveCount(0)
await expect(
page.getByRole('toolbar', { name: dict['editor.annotations.tools'] }),
).toHaveCount(0)
for (const kind of ['undo', 'redo'] as const) {
await expect(historyButton(page, dict, kind)).toHaveAttribute(
'aria-disabled',
'true',
)
}
}
/** A real crossing: the dialogs are gone and nothing is left to animate before the checks. */
async function cross(page: Page, size: { width: number; height: number }) {
await page.setViewportSize(size)
await expect(dialogs(page)).toHaveCount(0)
}
/**
* Types in `field` with no blur, crosses below 1 024 px, checks the part left the page and
* the focus sits on a named tab, widens, and checks the typed value is back untouched.
*/
async function keepsTypedValue(
page: Page,
field: Locator,
addButton: string,
tab: string,
) {
await field.fill('Saisie')
await cross(page, NARROW)
await expect(field).toBeHidden()
await expect(
page.getByRole('button', { name: addButton, exact: true }),
).toHaveCount(0)
await expectReadOnly(page)
await expect(active(page)).toHaveAttribute('id', `editor-tab-${tab}`)
await cross(page, WIDE)
await expect(field).toBeVisible()
await expect(field).toHaveValue('Saisie')
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
}
test.describe('editor shell, width crossing (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('the category, region and detail view forms keep their typed text', async ({
page,
}) => {
await open(page)
await openSection(page, dict, 'categories')
await keepsTypedValue(
page,
page.locator('#category-new-fr'),
dict['editor.general.category_add'],
'annotations',
)
await openSection(page, dict, 'regions')
await keepsTypedValue(
page,
page.locator('#region-new-code'),
dict['editor.vertebra.add'],
'annotations',
)
await openSection(page, dict, 'views')
await keepsTypedValue(
page,
page.locator('#view-new-fr'),
dict['editor.views.add'],
'annotations',
)
})
test('the crop group editor keeps its typed numbers, its read-only twin has its own ids', async ({
page,
}) => {
await open(page)
await openSection(page, dict, 'views')
await place(page, 'annotations.views')
.getByRole('button', { name: dict['editor.views.crop.toggle'] })
.first()
.click()
const field = page.locator('#view-detail-a-crop-min_x')
await field.fill('7x')
await cross(page, NARROW)
await expect(field).toBeHidden()
await expect(page.locator('#ro-view-detail-a-crop-min_x')).toBeVisible()
await cross(page, WIDE)
await expect(field).toHaveValue('7x')
const ids = await page.evaluate(() => {
const all = [...document.querySelectorAll('[id]')].map((e) => e.id)
return all.filter((id, i) => all.indexOf(id) !== i)
})
expect(ids).toEqual([])
})
test('the findings creation form stays in its dialog while narrow: draft, focus and a notice kept', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'findings')
await page
.getByRole('button', { name: dict['editor.findings.add_zone'] })
.click()
const field = page.locator('#finding-new-name-fr')
await field.fill('Saisie')
await expect(field).toBeFocused()
// The dialog is a part the flip keeps: no edit control leaves, nothing is written.
await page.setViewportSize(NARROW)
await expect(field).toBeVisible()
await expect(field).toHaveAttribute('readonly', '')
await expect(field).toHaveAttribute('aria-readonly', 'true')
await expect(field).toHaveValue('Saisie')
await expect(field).toBeFocused()
await expect(
page.getByText(dict['editor.findings.flip_narrow']),
).toBeVisible()
await expect(
page.getByRole('button', { name: dict['editor.findings.create'] }),
).toBeDisabled()
await page.setViewportSize(WIDE)
await expect(field).not.toHaveAttribute('readonly', '')
await expect(field).toHaveValue('Saisie')
await expect(field).toBeFocused()
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
await page.keyboard.press('Escape')
await page
.locator('dialog[open]')
.getByRole('button', { name: dict['editor.findings.discard'] })
.click()
await expect(dialogs(page)).toHaveCount(0)
})
test('the submission note keeps its typed text', async ({ page }) => {
await open(page)
await selectTab(page, dict, 'verification')
await keepsTypedValue(
page,
page.locator('#verification-note'),
dict['editor.verification.submit'],
'verification',
)
})
test('the reference dialog stays while narrow: draft, focus and a notice kept (R2F-5)', async ({
page,
}) => {
await open(page)
await openTab(page, dict, 'references')
await startReference(page, dict)
const field = page.locator('#reference-form-citation')
await field.fill('Saisie')
await expect(field).toBeFocused()
await page.setViewportSize(NARROW)
await expect(field).toBeVisible()
await expect(field).toHaveAttribute('readonly', '')
await expect(field).toHaveValue('Saisie')
await expect(field).toBeFocused()
await expect(
page.getByText(dict['editor.findings.flip_narrow']),
).toBeVisible()
await expect(
page.getByRole('button', { name: dict['editor.reference.add'] }),
).toBeDisabled()
await page.setViewportSize(WIDE)
await expect(field).not.toHaveAttribute('readonly', '')
await expect(field).toHaveValue('Saisie')
await expect(field).toBeFocused()
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
await page.keyboard.press('Escape')
await page
.locator('dialog[open]')
.getByRole('button', { name: dict['editor.findings.discard'] })
.click()
await expectNoDialog(page)
})
test('the annotation edit body keeps its tool and its pending creation', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'annotations')
const zone = page.getByRole('button', {
name: dict['editor.annotations.tool.zone'],
exact: true,
})
await expect(zone).toBeEnabled()
await zone.click()
await page
.getByRole('button', { name: dict['editor.annotations.add.point'] })
.click()
const name = page.getByLabel(dict['editor.annotations.name_fr'])
await name.fill('Futur point')
await cross(page, NARROW)
await expect(name).toBeHidden()
await expect(zone).toHaveCount(0)
await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations')
await cross(page, WIDE)
await expect(name).toHaveValue('Futur point')
await expect(zone).toHaveAttribute('aria-pressed', 'true')
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
})
test('a section open: read-only below the threshold, unsaved work kept, edit back on widening', async ({
page,
}) => {
const { actor, draftId } = await open(page)
await commitName(page, 'Nom conservé')
await openSection(page, dict, 'categories')
await page.locator('#category-new-fr').fill('Brouillon')
await cross(page, NARROW)
await expectReadOnly(page)
await expect(place(page, 'annotations.categories')).toBeVisible()
await expect(saveLine(page)).toHaveText(
dict['editor.draft.status.unsaved_count_one'].replace('{count}', '1'),
)
expect(
await storedCopy(page, copyKeyOf(actor.account.id, draftId)),
).not.toBeNull()
await cross(page, WIDE)
await expect(
page.getByRole('button', { name: dict['common.save'], exact: true }),
).toBeEnabled()
await expect(historyButton(page, dict, 'undo')).toHaveAttribute(
'aria-disabled',
'false',
)
await expect(page.locator('#category-new-fr')).toHaveValue('Brouillon')
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
})
test('the references dialog open: read-only below the threshold, unsaved work kept, edit back on widening', async ({
page,
}) => {
await open(page)
await commitName(page, 'Nom conservé')
await openCitations(page, dict, 'Constat A')
await page.setViewportSize(NARROW)
await expect(place(page, 'citations')).toBeVisible()
await expect(page.locator('dialog[open]')).toHaveCount(2)
await page.setViewportSize(WIDE)
await closeCitations(page, dict)
await closeFinding(page, dict)
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
await expect(
page.getByRole('button', { name: dict['common.save'], exact: true }),
).toBeEnabled()
})
test('text typed without a blur is unsaved after the crossing and the copy is written', async ({
page,
}) => {
const { actor, draftId } = await open(page)
await selectTab(page, dict, 'general')
await page.locator('#general-name-fr').fill('Sans quitter le champ')
await cross(page, NARROW)
await expect(saveLine(page)).toHaveText(
dict['editor.draft.status.unsaved_count_one'].replace('{count}', '1'),
)
await expect
.poll(() => storedCopy(page, copyKeyOf(actor.account.id, draftId)))
.not.toBeNull()
})
test('a focused drawing tool hands its focus to the shown tab on a crossing', async ({
page,
}) => {
await open(page)
await selectTab(page, dict, 'annotations')
const zone = page.getByRole('button', {
name: dict['editor.annotations.tool.zone'],
exact: true,
})
await expect(zone).toBeEnabled()
await zone.focus()
await cross(page, NARROW)
await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations')
})
test('a drag across the crossing commits nothing', async ({ page }) => {
await open(
page,
shapeWith(
pointOf('anno-free', 'main', { cx: 120, cy: 120, r: 6 }, 'Point libre'),
),
)
await selectTab(page, dict, 'annotations')
await pickAnnotation(page, dict, 'Point libre')
const cx = geometryField(page, dict, 'cx')
const before = await cx.inputValue()
const from = await clientOf(page, 120, 120)
const to = await clientOf(page, 200, 160)
await page.mouse.move(from.x, from.y)
await page.mouse.down()
await page.mouse.move(to.x, to.y, { steps: 6 })
await cross(page, NARROW)
await page.mouse.up()
await cross(page, WIDE)
await expect(geometryField(page, dict, 'cx')).toHaveValue(before)
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
await expect(historyButton(page, dict, 'undo')).toHaveAttribute(
'aria-disabled',
'true',
)
})
test('a delete confirmation and the discard confirmation close when the editor turns read-only', async ({
page,
}) => {
await open(page, spareCategory)
await openSection(page, dict, 'categories')
await page
.getByRole('listitem')
.filter({ has: page.locator('#category-cat-spare-name-fr') })
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(dialogs(page)).toHaveCount(1)
await cross(page, NARROW)
await cross(page, WIDE)
await expect(dialogs(page)).toHaveCount(0)
await expect(page.locator('#category-cat-spare-name-fr')).toHaveCount(1)
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
await commitName(page, 'Nom à abandonner')
await page
.getByRole('button', { name: dict['editor.draft.discard'], exact: true })
.click()
await expect(dialogs(page)).toHaveCount(1)
await cross(page, NARROW)
await cross(page, WIDE)
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
})
})