Files
faunosteo/apps/app/e2e/shell/editor-shell-crossing.spec.ts
T
bchanot 4d2c64f57f feat(editor): creation on the drawing then the creation dialog
U2 Task 7 (A2, A4, A5, A7, A12, A15; R-3, R-4, R-12, R-13, R-14).
The work store's `creation` owns the new shape, its form, its view and
F: a click with the point tool, a closed tracing or a keyboard
« Ajouter … » opens « Nouveau point / zone / accès », a modal without
a history layer over the right column, mounted beside EditOnly so a
read-only flip keeps it (« Créer », « Replacer », « Reprendre » off).
A new zone or link is a creation from its first vertex. The ghost
takes the form's category colour; the point tool previews under a
mouse; the canvas carries data-creating (other markers dimmed,
unselectable). « Replacer le point » / « Reprendre le tracé » hide the
dialog and keep the form; the strip offers « Revenir aux propriétés »,
« Retirer le dernier sommet », « Abandonner ». « Créer »: one insert,
tool back to « Sélectionner », the new element selected, « Point
créé · Défaire », focus on its row. ✕, Échap, « Abandonner » and Back
always ask « Abandonner la création ? » (DiscardConfirm inside the
dialog; DrawingGuardDialog elsewhere); answerDrawing drops the
creation. Undo, its shortcuts and the line's « Défaire » are inactive
during a creation. missingFields replaces formProblem (MissingSummary
shared with the edit form); the C26 notice has no numbers.
CreationPanel, formProblem, withGeometry and the keys required.fields,
required.names and create_cancel are gone; GeometryGroup is imported
by RepairDialog only.

Removed or rewritten assertions:
- tab « holds a point at the frame centre »: « Centre x » = 50 ->
  the ghost circle cx = 50; plus tool back to Sélectionner, « Point
  créé », one undo step.
- tab « refuses a creation without laterality »: the general line
  « Choisissez la catégorie et la latéralité » -> only « Choisissez
  une latéralité. » and « À compléter : Latéralité. », focus on it.
- tab « applies the geometry group to a pending zone »: removed (A8,
  no coordinate field) -> « places a triangle at the centre: the ghost
  shows it, Créer inserts it »; vertex edits after Créer are the e2e
  keyboard test.
- tab C26 « proposes C »: « x = 15, y = 15 » in the notice -> the R-4
  text, the notice inside the dialog; cancel test « Centre x » = 0 ->
  ghost cx = 0.
- tab « offers the correction when the core refuses a pending point »
  (typed cx 98): removed, no typed coordinate is possible; the verdict
  path stays covered by the C26 click tests and correctionFor units.
- tab H5 « a typed radius shows the core issue »: removed (A8); the
  size refusal is the slider's (Task 4 tests).
- tab H6 « a second click moves the pending point »: -> « Replacer le
  point », then the click moves the ghost, the form kept.
- tab H7 « Centre x/y » = 30/50 -> ghost cx/cy.
- tab tracing Enter: « x du sommet 3 » -> ghost points; « drops the
  tracing on Escape » -> Escape asks first (board 32 row 3), Continuer
  keeps, Abandonner drops; new « Annuler le tracé acts at once ».
- keep-alive « a pending creation is kept and focused » and « a
  tracing … is kept and focused »: the tab now asks first (R-12) ->
  « Continuer » keeps the tracing / the form, « Abandonner » goes.
- sections « its panel takes the focus » -> its dialog's
  [data-creation-focus] takes it.
- no-loss « pending creation with its name » (hidden with the body) ->
  the dialog stays across the crossing, read-only, Créer off (R-14).
- point-edit A5 « Rayon » = 7 / 9 -> ghost r = 7 / 9.
- e2e editor-annotations keyboard test « numeric position » (cx field
  250) -> UX_TESTS Keyboard: zone added, vertex added and removed,
  moved by the move mode, validated, saved. The « Fermer le tracé »
  step runs under expectNoShift again (shortcut removed).
- e2e editor-geometry C26: the proposed x, y read from the notice
  text -> from the overlay's correction circle; the R-4 text checked
  in the dialog.
- e2e editor-deselect « Escape cancels the tracing only » -> Escape
  asks, « Abandonner » cancels it, the selection kept.
- e2e editor-shell-crossing « keeps its tool and its pending
  creation » (field hidden) -> the dialog stays read-only, Créer off,
  then editable on widening.
2026-11-17 23:32:42 +01:00

423 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,
shownNumber,
shownShape,
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)
})
// U2 Task 7 (R-14): the creation dialog is mounted outside the edit-only body. A
// crossing keeps it open, read-only, with its form; widening gives the form back.
test('the creation dialog stays across a crossing: its form kept, « Créer » off, then on', 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 dialog = page.getByRole('dialog', {
name: dict['editor.annotations.new.point'],
})
const name = dialog.getByLabel(dict['editor.annotations.name_fr'])
const create = dialog.getByRole('button', {
name: dict['editor.annotations.create'],
})
await name.fill('Futur point')
await page.setViewportSize(NARROW)
await expect(zone).toHaveCount(0)
await expect(dialog).toBeVisible()
await expect(name).toHaveValue('Futur point')
await expect(name).not.toBeEditable()
await expect(create).toBeDisabled()
await expect(page.getByTestId('overlay-ghost')).toBeAttached()
await page.setViewportSize(WIDE)
await expect(name).toHaveValue('Futur point')
await expect(name).toBeEditable()
await expect(create).toBeEnabled()
await expect(page.getByTestId('overlay-ghost')).toBeVisible()
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 before = String(await shownNumber(page, 'cx'))
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(shownShape(page)).toHaveAttribute('cx', 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)
})
})