feat(editor): resumed trace edits the closed shape with its handles

« Reprendre le tracé » keeps the pending shape closed; the zone handles
(vertex, « + », « − », vertex keys) edit it through the same press path
and useZoneEdit, the target generalised to points + drop. A drop on
PENDING_ID patches creation.pending only: document, history and unsaved
count untouched, message without « Défaire ». Strip: « Tracé repris,
saisie gardée » with « Revenir aux propriétés » and « Abandonner ».
Handle names fall back to « la nouvelle zone » / « le nouvel accès ».

Removed (resumed branch of popVertex, backToProperties -> closeTrace,
CreationCommands tracedCount and its « Retirer le dernier sommet »).

Removed assertions, editor-creation-dialog.test.tsx, « keeps the
vertices and the form; a new vertex, then the dialog again »:
- strip « Tracé repris, saisie gardée » -> kept in « keeps the shape
  closed and the form, shows its handles; two strip commands »
- « Retirer le dernier sommet » enabled -> absent; commands are exactly
  « Revenir aux propriétés », « Abandonner » (same test)
- a click on the drawing adds a 4th vertex -> « a click off the handles
  adds and selects nothing; a double « + » inserts once »
- dialog again with Nom (FR) « Tibia » -> « « Revenir aux propriétés »
  shows the edited shape; « Créer » inserts it »
- « Zone tracée, 4 sommets » -> « Zone tracée, 5 sommets » after « + »
  (same test)
This commit is contained in:
bchanot committed 2026-11-19 09:42:58 +01:00
1 parent 816d0f4f9a
commit a5896710e5
17 files changed
+679 -118

No files matched your search

@@ -10,12 +10,17 @@ import {
within,
} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { Point } from '@faunosteo/core-wasm/types'
import HistoryButtons from '@/components/editor/HistoryButtons'
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
import {
PENDING_ID,
resetWork,
useAnnotationWork,
} from '@/editor/annotations/workStore'
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
import { emptyForm } from '@/editor/annotations/creation'
import { placePending } from '@/editor/annotations/creationWork'
import { dropCreation, placePending } from '@/editor/annotations/creationWork'
import { guardDrawing } from '@/editor/annotations/drawingGuard'
import { useLocaleStore } from '@/state/localeStore'
import { drawnText, insert, point } from '../helpers/editorFixtures'
@@ -223,36 +228,220 @@ describe('placing and the form (A4, A5)', () => {
})
})
describe('« Reprendre le tracé » and « Revenir aux propriétés » (board 04 C)', () => {
it('keeps the vertices and the form; a new vertex, then the dialog again', async () => {
describe('« Reprendre le tracé » edits the closed shape with its handles (board 04 C)', () => {
const SQUARE: Point[] = [
[20, 20],
[80, 20],
[80, 80],
[20, 80],
]
const mouse = {
pointerId: 1,
isPrimary: true,
button: 0,
buttons: 1,
pointerType: 'mouse',
}
const hitOf = (name: string) =>
screen.getByRole('button', { name }).querySelector('[data-handle]')!
const clickHandle = (name: string, [x, y]: [number, number]) =>
pressAt(hitOf(name), x, y)
const shape = () => {
const geometry = creation()!.pending.geometry
return geometry.type === 'polygon' ? geometry.points : null
}
/** What a pending change must leave alone: the document, both histories (unsaved count). */
const untouched = () => {
const { documentText, undo, redo } = store.getState()
return { documentText, undo: undo.length, redo: redo.length }
}
const line = () => screen.getByTestId('gesture-line')
const strip = () => screen.getByTestId('edit-strip')
/** A traced square, its dialog, the name typed (unless empty), then « Reprendre le tracé ». */
async function resumed(name = 'Tibia', points = SQUARE) {
const user = await mount()
await user.click(screen.getByRole('button', { name: 'Zone' }))
;[
[20, 20],
[80, 20],
[50, 80],
].forEach(([x, y]) => pressAt(canvas(), x, y))
points.forEach(([x, y]) => pressAt(canvas(), x, y))
await user.click(screen.getByRole('button', { name: 'Fermer le tracé' }))
let shown = await dialog('Nouvelle zone')
await user.type(within(shown).getByLabelText('Nom (FR)'), 'Tibia')
const shown = await dialog('Nouvelle zone')
if (name) await user.type(within(shown).getByLabelText('Nom (FR)'), name)
await user.click(
within(shown).getByRole('button', { name: 'Reprendre le tracé' }),
)
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
const strip = screen.getByTestId('edit-strip')
expect(strip).toHaveTextContent('Tracé repris, saisie gardée')
return user
}
it('keeps the shape closed and the form, shows its handles; two strip commands', async () => {
await resumed()
expect(creation()).toMatchObject({ closed: true, dialog: false })
expect(shape()).toEqual(SQUARE)
expect(ghost()).toBeInTheDocument()
expect(
within(strip).getByRole('button', { name: 'Retirer le dernier sommet' }),
).toBeEnabled()
pressAt(canvas(), 30, 60)
screen.getByRole('group', { name: 'Sommets de Tibia' }),
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Sommet 4 de Tibia' }),
).toBeInTheDocument()
expect(
screen.getByRole('button', {
name: 'Ajouter un sommet après le sommet 1 de Tibia',
}),
).toBeInTheDocument()
expect(strip()).toHaveTextContent('Nouvelle zone')
expect(strip()).toHaveTextContent('Tracé repris, saisie gardée')
const commands = within(screen.getByTestId('creation-commands'))
.getAllByRole('button')
.map((b) => b.textContent)
expect(commands).toEqual(['Revenir aux propriétés', 'Abandonner'])
expect(
screen.queryByRole('button', { name: 'Retirer le dernier sommet' }),
).toBeNull()
})
it('a vertex drag changes the pending shape only, said without « Défaire »', async () => {
await resumed()
const before = untouched()
const el = hitOf('Sommet 2 de Tibia')
fireEvent.pointerDown(el, { ...mouse, clientX: 80, clientY: 20 })
fireEvent.pointerMove(el, { ...mouse, clientX: 90, clientY: 10 })
fireEvent.pointerUp(el, { ...mouse, buttons: 0, clientX: 90, clientY: 10 })
expect(shape()![1]).toEqual([90, 10])
expect(useAnnotationWork.getState().chosen).toMatchObject({
annotationId: PENDING_ID,
vertex: 1,
})
expect(line()).toHaveTextContent('Sommet déplacé')
expect(within(line()).queryByRole('button', { name: 'Défaire' })).toBeNull()
expect(untouched()).toEqual(before)
})
it('« + » and « − » change the pending shape only', async () => {
await resumed()
const before = untouched()
clickHandle('Ajouter un sommet après le sommet 1 de Tibia', [50, 20])
expect(shape()).toEqual([[20, 20], [50, 20], ...SQUARE.slice(1)])
expect(useAnnotationWork.getState().chosen).toMatchObject({ vertex: 1 })
expect(line()).toHaveTextContent('Sommet ajouté')
clickHandle('Retirer le sommet 2 de Tibia', [50, 10])
expect(shape()).toEqual(SQUARE)
expect(line()).toHaveTextContent('Sommet retiré')
expect(within(line()).queryByRole('button', { name: 'Défaire' })).toBeNull()
expect(untouched()).toEqual(before)
})
it('vertex keys: arrows move at once, Insert adds, Delete removes; nothing held', async () => {
await resumed()
const before = untouched()
const vertex = (n: number) =>
screen.getByRole('button', { name: `Sommet ${n} de Tibia` })
vertex(1).focus()
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
expect(shape()![0]).toEqual([20.5, 20])
expect(useAnnotationWork.getState().preview).toBeNull()
fireEvent.keyDown(vertex(1), { key: 'Insert' })
expect(shape()).toHaveLength(5)
expect(shape()![1]).toEqual([50.25, 20])
fireEvent.keyDown(vertex(2), { key: 'Delete' })
expect(shape()).toHaveLength(4)
expect(untouched()).toEqual(before)
})
it('« − » at three vertices is refused with its reason', async () => {
await resumed('Tibia', SQUARE.slice(0, 3))
clickHandle('Sommet 1 de Tibia', [20, 20])
expect(
screen.getByRole('button', { name: 'Retirer le sommet 1 de Tibia' }),
).toHaveAttribute('aria-disabled', 'true')
clickHandle('Retirer le sommet 1 de Tibia', [20, 10])
expect(shape()).toEqual(SQUARE.slice(0, 3))
expect(line()).toHaveTextContent('Une zone garde au moins 3 sommets')
})
it('a click off the handles adds and selects nothing; a double « + » inserts once', async () => {
await resumed()
pressAt(canvas(), 50, 50)
pressAt(canvas(), 5, 5)
expect(shape()).toEqual(SQUARE)
expect(creation()!.form.fr).toBe('Tibia')
expect(screen.queryByRole('dialog')).toBeNull()
const plus = hitOf('Ajouter un sommet après le sommet 1 de Tibia')
pressAt(plus, 50, 20)
pressAt(plus, 50, 20)
expect(shape()).toHaveLength(5)
})
it('Escape on a vertex asks « Abandonner la création ? »', async () => {
await resumed()
// The tab sits in the editor's workspace, where the page's Escape applies.
view.container.setAttribute('data-editor-workspace', '')
const vertex = screen.getByRole('button', { name: 'Sommet 1 de Tibia' })
act(() => vertex.focus())
fireEvent.keyDown(vertex, { key: 'Escape' })
expect(useAnnotationWork.getState().question?.work).toBe('creation')
expect(creation()).not.toBeNull()
})
it('« Revenir aux propriétés » shows the edited shape; « Créer » inserts it', async () => {
const user = await resumed()
clickHandle('Ajouter un sommet après le sommet 1 de Tibia', [50, 20])
await user.click(
within(strip).getByRole('button', { name: 'Revenir aux propriétés' }),
within(strip()).getByRole('button', { name: 'Revenir aux propriétés' }),
)
shown = await dialog('Nouvelle zone')
const shown = await dialog('Nouvelle zone')
expect(within(shown).getByLabelText('Nom (FR)')).toHaveValue('Tibia')
expect(
within(shown).getByText('Zone tracée, 4 sommets'),
within(shown).getByText('Zone tracée, 5 sommets'),
).toBeInTheDocument()
await user.type(within(shown).getByLabelText('Nom (EN)'), 'Tibia')
await user.selectOptions(within(shown).getByLabelText('Latéralité'), 'left')
const before = store.getState().undo.length
await user.click(within(shown).getByRole('button', { name: 'Créer' }))
expect(store.getState().undo).toHaveLength(before + 1)
const created = annotations().find((a) => a.kind === 'zone')!
expect(created.geometry).toEqual({
type: 'polygon',
points: [[20, 20], [50, 20], ...SQUARE.slice(1)],
})
expect(useAnnotationWork.getState().chosen).toBeNull()
})
it('the chosen vertex ends with the creation when it is dropped', async () => {
await resumed()
clickHandle('Sommet 2 de Tibia', [80, 20])
expect(useAnnotationWork.getState().chosen).not.toBeNull()
act(() => dropCreation())
expect(useAnnotationWork.getState().chosen).toBeNull()
})
it('names: « la nouvelle zone » while the name is empty; English: « the new zone »', async () => {
await resumed('')
expect(
screen.getByRole('group', { name: 'Sommets de la nouvelle zone' }),
).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Sommet 1 de la nouvelle zone' }),
).toBeInTheDocument()
act(() => useLocaleStore.setState({ locale: 'en' }))
expect(
await screen.findByRole('group', { name: 'Vertices of the new zone' }),
).toBeInTheDocument()
})
it('a keyboard link resumes with handles, « le nouvel accès » while unnamed', async () => {
const user = await mount(withDetail())
await user.click(screen.getByRole('button', { name: 'Ajouter un accès' }))
const shown = await dialog('Nouvel accès')
await user.click(
within(shown).getByRole('button', { name: 'Reprendre le tracé' }),
)
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(strip()).toHaveTextContent('Nouvel accès')
expect(
screen.getByRole('group', { name: 'Sommets de le nouvel accès' }),
).toBeInTheDocument()
expect(creation()).toMatchObject({ closed: true, dialog: false })
})
})