feat(editor): vertex handles, insert and remove, zone move, redraw

U2 Task 5. A selected polygon gets its vertex, « + » and « − » handles
(R-9, hidden « + » under two hit radii, R-18 zoom hint in the strip),
the handle cap at 40 (R-7), vertex drag and keys, the move mode on the
zone or the chosen vertex, « Redessiner » as a redraw mode kept in step
with its tracing (R-12 guard, R-13 drop), close radius in CSS px
(R-11). The numeric group leaves the properties panel (D1).

Removed or rewritten assertions (numeric group -> replacement):
- tab « shows its exact stored numbers » (Centre x field) -> the overlay
  selection circle's cx attribute, same exact value.
- tab « a numeric edit » x3 -> « an edit on the drawing »: Enter on the
  handle without a step commits nothing, a step + Enter commits once;
  a refused handle drag keeps the stored shape then a drag inside the
  frame repairs it (issues gone); Escape drops a pending series.
- tab C26 « Centre x 15 » -> overlay cx 15.
- tab C32 unmeasured « Centre x as text » -> no handle, no field.
- tab « adds and removes a vertex as part of the whole group » -> « + »
  then « − » on the drawing; « never offers to remove below three » ->
  « − » aria-disabled at 3.
- tab H8 « refused Remplacer drops the tracing » -> keeps it open with
  « Fermeture refusée » (board 33 A); « refused vertex add/remove stay
  non appliqué » -> a refused vertex drag restores the shape exactly.
- tab Désélectionner and D6b (typed Centre x committed, refused, undone)
  x6 and strip « a new commit replaces the message » -> the same with
  the Nom (FR) field (a blank name is the refused value).
- focus-request « Centre x 20 » -> overlay cx 20.
- escape « strip commands keep their Escape » -> a redraw: Escape on the
  strip or the box cancels it (R-12 row 4); kept for a new zone tracing.
- keep-alive « Remplacer tracing kept across Aller à » -> ended by a tab
  when empty, asked once a vertex is placed (R-12).
- e2e annotations: numeric cx edit + undo/redo -> handle keys + undo/
  redo; jitter/drag and Task 4 point reads -> overlay attributes (the
  stored place during the mode -> overlay-old-place); keyboard-only cy
  and vertex x typed -> handle and vertex keys.
- e2e deselect: Centre x typed/refused/committed -> Nom (FR).
- e2e geometry, shell-crossing: Centre x/cy reads -> overlay attributes.
- e2e journey: cx +3 and vertex x +4 typed -> 3 and 4 arrow steps + Enter;
  a far typed value + revert -> a far handle drag refused.
- e2e equine latency: typed cx rounds -> handle arrow + Enter rounds.
This commit is contained in:
bchanot committed 2026-11-17 20:24:49 +01:00
1 parent ba8e766fe8
commit 6211046537
44 files changed
+3790 -1050

No files matched your search

@@ -61,8 +61,28 @@ const props = {
const named = (id: string, cx: number, cy: number, r: number) =>
point(id, cx, cy, r)
const annotations = () => store.getState().previewState!.document.annotations
const nameOf = (id: string) =>
annotations().find((a: Annotation) => a.id === id)?.name?.fr
const geometryOf = (id: string) =>
annotations().find((a: Annotation) => a.id === id)?.geometry
/** The selection as the overlay draws it (U2 Task 5: no coordinate field in the panel). */
const shownCircle = () =>
screen.getByTestId('overlay-selection').querySelector('circle')!
/** A mouse drag of `el` from `from` to `to`, past the 4 px slop. */
function mouseDrag(el: Element, from: [number, number], to: [number, number]) {
const at = ([x, y]: [number, number], buttons = 1) => ({
clientX: x,
clientY: y,
pointerId: 1,
isPrimary: true,
button: 0,
buttons,
pointerType: 'mouse',
})
fireEvent.pointerDown(el, at(from))
fireEvent.pointerMove(el, at(to))
fireEvent.pointerUp(el, at(to, 0))
}
/** Screen = drawing: the overlay's inverse CTM is the identity in the page under test. */
function stubCtm(): void {
@@ -105,14 +125,12 @@ async function selectFromList(name: RegExp | string = /N/) {
}
describe('selection and the list', () => {
it('lists the view annotations, selects one and shows its exact stored numbers', async () => {
it('lists the view annotations, selects one and draws its exact stored numbers', async () => {
await mount({
text: insert(drawnText(), named('anno-a', 743.0451049804688, 50, 5)),
})
const panel = await selectFromList()
expect(within(panel).getByLabelText('Centre x')).toHaveValue(
'743.0451049804688',
)
await selectFromList()
expect(shownCircle()).toHaveAttribute('cx', '743.0451049804688')
expect(screen.getByTestId('edit-strip-detail')).toHaveTextContent('Point')
})
@@ -126,52 +144,37 @@ describe('selection and the list', () => {
})
})
describe('a numeric edit', () => {
it('commits only when the typed number differs from the stored one', async () => {
describe('an edit on the drawing (U2 Task 5: the numeric group left the panel)', () => {
it('commits only when the shape changes', async () => {
await mount()
const panel = await selectFromList()
const user = userEvent.setup()
await selectFromList()
const version = store.getState().handleVersion
const cx = within(panel).getByLabelText('Centre x')
await user.click(cx)
await user.keyboard('{Enter}')
const handle = screen.getByTestId('point-handle')
fireEvent.keyDown(handle, { key: 'Enter' })
expect(store.getState().handleVersion).toBe(version)
await user.clear(cx)
await user.type(cx, '60{Enter}')
fireEvent.keyDown(handle, { key: 'ArrowRight' })
fireEvent.keyDown(handle, { key: 'Enter' })
expect(geometryOf('anno-a')).toEqual({
type: 'circle',
cx: 60,
cx: 50.5,
cy: 50,
r: 5,
})
expect(store.getState().handleVersion).toBe(version + 1)
})
it('keeps a refused value as « non appliqué » with the document unchanged, then applies a coherent set', async () => {
it('a refused place keeps the stored shape, then a place inside the frame repairs it', async () => {
await mount({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
const panel = await selectFromList()
const user = userEvent.setup()
const before = store.getState().documentText
expect(
within(panel).getByTestId('annotation-geometry-issues'),
).toBeInTheDocument()
const cx = within(panel).getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '50{Enter}')
mouseDrag(pointHandle(), [150, 150], [50, 150])
expect(store.getState().documentText).toBe(before)
expect(within(panel).getByText('non appliqué')).toBeInTheDocument()
expect(
within(panel).getByText(/Valeurs non appliquées/),
).toBeInTheDocument()
expect(
within(panel).getByRole('button', {
name: 'Revenir aux valeurs enregistrées',
}),
).toBeInTheDocument()
expect(within(panel).getByLabelText('Centre x')).toHaveValue('50')
const cy = within(panel).getByLabelText('Centre y')
await user.clear(cy)
await user.type(cy, '50{Enter}')
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
expect(shownCircle()).toHaveAttribute('cx', '150')
mouseDrag(pointHandle(), [150, 150], [50, 50])
expect(geometryOf('anno-a')).toEqual({
type: 'circle',
cx: 50,
@@ -181,19 +184,17 @@ describe('a numeric edit', () => {
expect(screen.queryByTestId('annotation-geometry-issues')).toBeNull()
})
it('reverts the group to the saved values', async () => {
await mount({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
const panel = await selectFromList()
const user = userEvent.setup()
const cx = within(panel).getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '50{Enter}')
await user.click(
within(panel).getByRole('button', {
name: 'Revenir aux valeurs enregistrées',
}),
)
expect(within(panel).getByLabelText('Centre x')).toHaveValue('150')
it('Escape drops a pending series: the stored shape shows again', async () => {
await mount({ text: insert(drawnText(), named('anno-a', 50, 50, 5)) })
await selectFromList()
const before = store.getState().documentText
const handle = screen.getByTestId('point-handle')
fireEvent.keyDown(handle, { key: 'ArrowRight' })
expect(shownCircle()).toHaveAttribute('cx', '50.5')
// This mount has no workspace wrapper: Escape is pressed with nothing focused.
fireEvent.keyDown(document.body, { key: 'Escape' })
expect(shownCircle()).toHaveAttribute('cx', '50')
expect(store.getState().documentText).toBe(before)
})
})
@@ -307,8 +308,8 @@ describe('the point tool and the corrected position (C26)', () => {
})
expect(panel).not.toBeInTheDocument()
expect(screen.queryByTestId('overlay-click-cross')).toBeNull()
const props = await screen.findByTestId('annotation-properties')
expect(within(props).getByLabelText('Centre x')).toHaveValue('15')
await screen.findByTestId('annotation-properties')
expect(shownCircle()).toHaveAttribute('cx', '15')
})
it('keeps the pending point at the click when the correction is cancelled', async () => {
@@ -495,12 +496,9 @@ describe('an unmeasured view (C32)', () => {
screen.getAllByText(/Ce dessin n'est pas mesurable/).length,
).toBeGreaterThan(0)
const panel = await selectFromList()
expect(
within(panel).queryByRole('textbox', { name: 'Centre x' }),
).toBeNull()
expect(
within(panel).getByText('Centre x', { exact: false }),
).toBeInTheDocument()
// Nothing edits the geometry of an unmeasured view: no handle, no field.
expect(screen.queryByTestId('point-handle')).toBeNull()
expect(within(panel).queryByRole('textbox', { name: /^Centre/ })).toBeNull()
expect(
within(panel).getByText(/Ce dessin n'est pas mesurable/),
).toBeInTheDocument()
@@ -657,14 +655,13 @@ describe('polygons and paths', () => {
const zoneText = (geometry: object) =>
insert(drawnText(), { kind: 'annotation', value: zoneAnnotation(geometry) })
it('adds and removes a vertex as part of the whole group', async () => {
const handleHit = (name: string) =>
screen.getByRole('button', { name }).querySelector('[data-handle]')!
it('« + » adds a vertex on the drawing and « − » removes it', async () => {
await mount({ text: zoneText({ type: 'polygon', points: triangle }) })
const panel = await selectFromList()
const user = userEvent.setup()
await user.click(within(panel).getByLabelText('x du sommet 1'))
await user.click(
within(panel).getByRole('button', { name: 'Ajouter un sommet' }),
)
await selectFromList()
pressAt(handleHit('Ajouter un sommet après le sommet 1'), 50, 20)
expect(geometryOf('zone-a')).toMatchObject({
points: [
[20, 20],
@@ -673,18 +670,17 @@ describe('polygons and paths', () => {
[50, 80],
],
})
await user.click(within(panel).getByRole('button', { name: 'Retirer' }))
expect(geometryOf('zone-a')).toMatchObject({
points: triangle.slice(0, 3).map((p, i) => (i === 0 ? [50, 20] : p)),
})
pressAt(handleHit('Retirer le sommet 2'), 50, 10)
expect(geometryOf('zone-a')).toMatchObject({ points: triangle })
})
it('never offers to remove a vertex below three', async () => {
it('never removes a vertex below three: « − » is greyed', async () => {
await mount({ text: zoneText({ type: 'polygon', points: triangle }) })
const panel = await selectFromList()
await selectFromList()
pressAt(handleHit('Sommet 1'), 20, 20)
expect(
within(panel).getByRole('button', { name: 'Retirer' }),
).toBeDisabled()
screen.getByRole('button', { name: 'Retirer le sommet 1' }),
).toHaveAttribute('aria-disabled', 'true')
})
it('moves a selected polygon as a block', async () => {
@@ -857,7 +853,7 @@ describe('refusals through the tab (H8)', () => {
const zoneText = (geometry: object) =>
insert(drawnText(), { kind: 'annotation', value: zoneAnnotation(geometry) })
it('a refused « Remplacer par un polygone » drops the tracing, shows the core message', async () => {
it('a refused « Remplacer par un polygone » keeps the tracing open, with the core message', async () => {
const path = { type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' }
await mount({ text: zoneText(path) })
const panel = await selectFromList()
@@ -874,35 +870,31 @@ describe('refusals through the tab (H8)', () => {
].forEach(([x, y]) => pressAt(canvas, x, y))
fireEvent.keyDown(canvas, { key: 'Enter' })
expect(await screen.findByRole('alert')).toBeInTheDocument()
// Board 33 A: the tracing stays open with its commands (it was dropped before Task 5).
expect(
screen.queryByRole('button', { name: 'Annuler le tracé' }),
).toBeNull()
screen.getByRole('button', { name: 'Annuler le tracé' }),
).toBeInTheDocument()
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
'Fermeture refusée',
)
expect(geometryOf('zone-a')).toEqual(path)
})
it('a refused vertex add and a refused remove stay « non appliqué », document unchanged', async () => {
it('a refused vertex move restores the shape exactly, document unchanged', async () => {
await mount({
text: zoneText({ type: 'polygon', points: [...triangle, [20, 60]] }),
})
const panel = await selectFromList()
const user = userEvent.setup()
await selectFromList()
const before = store.getState().documentText
const x = within(panel).getByLabelText('x du sommet 1')
await user.clear(x)
await user.type(x, '500{Enter}')
await user.click(
within(panel).getByRole('button', { name: 'Ajouter un sommet' }),
const vertex = screen
.getByRole('button', { name: 'Sommet 1' })
.querySelector('[data-handle]')!
mouseDrag(vertex, [20, 20], [500, 20])
expect(store.getState().documentText).toBe(before)
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
expect(screen.getByTestId('gesture-line')).toHaveTextContent(
'Déplacement refusé',
)
expect(store.getState().documentText).toBe(before)
expect(within(panel).getAllByLabelText(/^x du sommet/)).toHaveLength(5)
expect(
within(panel).getByText(/Valeurs non appliquées/),
).toBeInTheDocument()
await user.click(within(panel).getByRole('button', { name: 'Retirer' }))
expect(store.getState().documentText).toBe(before)
expect(
within(panel).getByText(/Valeurs non appliquées/),
).toBeInTheDocument()
})
})
@@ -1038,12 +1030,12 @@ describe('« Désélectionner » (R1, A6)', () => {
await mountSpy()
const panel = await selectFromList()
const user = userEvent.setup()
await user.clear(within(panel).getByLabelText('Centre x'))
await user.type(within(panel).getByLabelText('Centre x'), '60{Enter}')
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
await user.clear(within(panel).getByLabelText('Nom (FR)'))
await user.type(within(panel).getByLabelText('Nom (FR)'), 'Nuque{Enter}')
expect(nameOf('anno-a')).toBe('Nuque')
await user.click(button(panel))
act(() => void store.getState().undoStep())
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
expect(nameOf('anno-a')).toBe('N')
})
it('read-only: no « Supprimer », it deselects and focuses the ro- row', async () => {
@@ -1065,23 +1057,22 @@ describe('« Désélectionner » (R1, A6)', () => {
await mountSpy()
const panel = await selectFromList()
const user = userEvent.setup()
const cx = within(panel).getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '60')
const name = within(panel).getByLabelText('Nom (FR)')
await user.clear(name)
await user.type(name, 'Nuque')
const depth = store.getState().undo.length
await user.click(button(panel))
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
expect(nameOf('anno-a')).toBe('Nuque')
expect(store.getState().undo.length).toBe(depth + 1)
})
it('a refused typed value: the panel closes, the document is unchanged', async () => {
await mountSpy({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
await mountSpy()
const panel = await selectFromList()
const user = userEvent.setup()
const before = store.getState().documentText
const cx = within(panel).getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '1000000')
// A blank name is refused (both names are required).
await user.clear(within(panel).getByLabelText('Nom (FR)'))
await user.click(button(panel))
expect(screen.queryByTestId('annotation-properties')).toBeNull()
expect(store.getState().documentText).toBe(before)
@@ -1585,40 +1576,39 @@ describe('a tap on the drawing (D6b)', () => {
it('undo after a tap deselect undoes the earlier edit, redo restores it', async () => {
await selected()
const user = userEvent.setup()
const cx = screen.getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '60{Enter}')
const name = screen.getByLabelText('Nom (FR)')
await user.clear(name)
await user.type(name, 'Nuque{Enter}')
tap(rect())
act(() => void store.getState().undoStep())
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
expect(nameOf('anno-a')).toBe('N')
act(() => void store.getState().redoStep())
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
expect(nameOf('anno-a')).toBe('Nuque')
})
it('commits a typed valid value once and deselects when the press blurs the field', async () => {
await selected()
const user = userEvent.setup()
const cx = screen.getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '60')
const name = screen.getByLabelText('Nom (FR)')
await user.clear(name)
await user.type(name, 'Nuque')
const depth = store.getState().undo.length
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
// What mousedown does: the focus moves to the box, the field commits, the drawing rebuilds.
act(() => box().focus())
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
fireEvent.click(rect())
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
expect(nameOf('anno-a')).toBe('Nuque')
expect(store.getState().undo.length).toBe(depth + 1)
expect(isDeselected()).toBe(true)
})
it('a refused typed value: the panel closes, the document is unchanged', async () => {
await selected({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
await selected()
const user = userEvent.setup()
const before = store.getState().documentText
const cx = screen.getByLabelText('Centre x')
await user.clear(cx)
await user.type(cx, '1000000')
// A blank name is refused (both names are required).
await user.clear(screen.getByLabelText('Nom (FR)'))
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
act(() => box().focus())
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
@@ -1815,10 +1805,10 @@ describe('the strip', () => {
await selectFromList()
drag(marker('anno-a'), [60, 40])
expect(line()).toHaveTextContent('Point déplacé')
const cx = screen.getByLabelText('Centre x')
const name = screen.getByLabelText('Nom (FR)')
const user = userEvent.setup()
await user.clear(cx)
await user.type(cx, '30{Enter}')
await user.clear(name)
await user.type(name, 'Nuque{Enter}')
expect(line()).not.toHaveTextContent('Point déplacé')
drag(marker('anno-a'), [40, 40])
expect(line()).toHaveTextContent('Point déplacé')