fix(editor): no lost series, tap click absorbed, focus kept on handles

Task 5 review fix round 1.
- I-1: Insert and Delete on a vertex commit pending arrow steps first,
  then act on the stored polygon (read from the store, not the render).
- I-2: deselect commits a handle's pending series before the handle
  unmounts (commitFocusedSeries, no reliance on blur at removal).
- I-3: a touch or pen tap absorbs the click the browser synthesises at
  its place, once, within 400 ms and 8 px; mouse and later clicks pass.
  Scroll anchoring is off while the editor shows: the deselect's panel
  swap scrolled the drawing under the finger. editor-deselect step c is
  back at the page's end, and asserts the drawing does not move.
- I-4, M-2: the double-click and undo tests press what is there now;
  a hand-set stale chosen vertex removes nothing.
- I-5: editor-zones undos, the vertex choice and the refused-trace
  clicks run under expectNoShift; new e2e for I-2.
- M-1: Delete on the last vertex and Enter on « − » keep the focus on a
  vertex (the next one is chosen).
- M-4: the strip notice comment names R-18. M-5: the tracing carries a
  `refused` flag; only a refused close titles « Fermeture refusée ».
- M-7: TODO lines (bubble size shortcut, scroll-padding-top, scroll
  clamp at the page's end).

Rewritten assertions: zone-edit « − » double click and undo-then-« − »
pressed the detached bubble -> press the live bubble or the box at the
same place. editor-deselect step c: scroll-to-top removed, drawing y
asserted unchanged. editor-geometry: scroll-to-top kept with the clamp
named (reported, TODO). editor-zones and editor-journey: comment says
the scroll-to-top undoes Playwright's own auto-scroll.
This commit is contained in:
bchanot committed 2026-11-17 21:04:23 +01:00
1 parent 316d8c475c
commit e596e0765e
17 files changed
+395 -57

No files matched your search

+209 -4
View File
@@ -16,6 +16,9 @@ import { answerDrawing, guardDrawing } from '@/editor/annotations/drawingGuard'
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
import { useLocaleStore } from '@/state/localeStore'
import { fr } from '@/i18n/fr'
import { stripLeadOf } from '@/editor/annotations/stripLead'
import { initialUi } from '@/editor/annotations/uiState'
import { drawnText, insert, point } from '../helpers/editorFixtures'
import { openReady, pressAt, resetStore, store } from '../helpers/editorHarness'
@@ -139,6 +142,11 @@ const marker = (id: string) =>
.getByTestId('annotation-canvas-drawing')
.querySelector(`[data-anno-id="${id}"]`)!
const detail = () => screen.getByTestId('edit-strip-detail')
/** A « − » bubble still drawn, else the canvas box: what a press at its place reaches. */
const liveBubbleOrCanvas = () =>
screen
.queryByRole('button', { name: /^Retirer le sommet/ })
?.querySelector('[data-handle]') ?? screen.getByTestId('annotation-canvas')
const message = () => screen.getByTestId('gesture-line')
const chosen = () => useAnnotationWork.getState().chosen
@@ -208,9 +216,12 @@ describe('a vertex (R-9)', () => {
expect(
screen.queryByRole('button', { name: /^Retirer le sommet/ }),
).toBeNull()
void bubble
const after = depth()
pressAt(bubble, 50, 20)
fireEvent.keyDown(vertex(2), { key: 'Delete' })
// A press where the bubble was reaches what is there now: a bubble still shown, else the
// box (which deselects).
pressAt(liveBubbleOrCanvas(), 50, 20)
expect(pointsOf('z')).toEqual(SQUARE)
expect(depth()).toBe(after)
})
@@ -306,9 +317,9 @@ describe('a double click on a handle (R-8, carried Task 2 gap)', () => {
await select()
clickHandle('Sommet 2', [80, 20])
const before = depth()
const bubble = hitOf('Retirer le sommet 2')
pressAt(bubble, 80, 10)
pressAt(bubble, 80, 10)
pressAt(hitOf('Retirer le sommet 2'), 80, 10)
// The second click of the double click lands on what is there now, at the same place.
pressAt(liveBubbleOrCanvas(), 80, 10)
expect(pointsOf('z')).toHaveLength(4)
expect(depth()).toBe(before + 1)
})
@@ -611,6 +622,159 @@ describe('redraw (R-12, board 06 C)', () => {
})
})
describe('fix round 1: no lost series, no lost focus, no stale « − »', () => {
it('I-1: ArrowRight then Insert, no Enter: the step is committed, then the insert', async () => {
await mount(squareText())
await select()
const before = depth()
vertex(1).focus()
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
fireEvent.keyDown(vertex(1), { key: 'Insert' })
expect(pointsOf('z')).toEqual([[20.5, 20], [50.25, 20], ...SQUARE.slice(1)])
expect(depth()).toBe(before + 2)
})
it('I-1: ArrowDown then Delete, no Enter: the step is committed, then the removal', async () => {
await mount(squareText([...SQUARE, [10, 50]]))
await select()
const before = depth()
vertex(1).focus()
fireEvent.keyDown(vertex(1), { key: 'ArrowDown' })
fireEvent.keyDown(vertex(1), { key: 'Delete' })
expect(pointsOf('z')).toEqual([...SQUARE.slice(1), [10, 50]])
expect(depth()).toBe(before + 2)
expect(message()).toHaveTextContent('Sommet retiré')
})
it('I-2: « Désélectionner » commits a pending series on a vertex', async () => {
await mount(squareText())
const panel = await select()
const before = depth()
vertex(2).focus()
fireEvent.keyDown(vertex(2), { key: 'ArrowDown' })
fireEvent.click(
within(panel).getByRole('button', { name: 'Désélectionner' }),
)
expect(pointsOf('z')![1]).toEqual([80, 20.5])
expect(depth()).toBe(before + 1)
expect(message()).toHaveTextContent('Sommet déplacé')
})
it('I-2: « Désélectionner » commits a pending series on a point handle', async () => {
await mount(insert(drawnText(), point('p', 50, 50, 5)))
const panel = await select()
const before = depth()
const handle = screen.getByTestId('point-handle')
handle.focus()
fireEvent.keyDown(handle, { key: 'ArrowRight' })
fireEvent.click(
within(panel).getByRole('button', { name: 'Désélectionner' }),
)
expect(annotationOf('p').geometry).toMatchObject({ cx: 50.5 })
expect(depth()).toBe(before + 1)
})
it('M-1: Delete on the last vertex keeps the focus on a vertex', async () => {
await mount(squareText([...SQUARE, [10, 50]]))
await select()
act(() => vertex(5).focus())
fireEvent.keyDown(vertex(5), { key: 'Delete' })
expect(pointsOf('z')).toHaveLength(4)
expect(document.activeElement).toBe(vertex(4))
})
it('M-1: Enter on « − » keeps the focus on a vertex', async () => {
await mount(squareText([...SQUARE, [10, 50]]))
await select()
act(() => vertex(2).focus())
act(() => minus(2).focus())
fireEvent.keyDown(minus(2), { key: 'Enter' })
expect(pointsOf('z')).toHaveLength(4)
expect(document.activeElement).toBe(vertex(2))
})
it('M-2: a chosen vertex stamped on another text removes nothing', async () => {
await mount(squareText())
await select()
clickHandle('Sommet 2', [80, 20])
const before = depth()
act(() =>
useAnnotationWork.setState({
chosen: { annotationId: 'z', vertex: 1, base: 'an older text' },
}),
)
fireEvent.keyDown(vertex(2), { key: 'Delete' })
pressAt(liveBubbleOrCanvas(), 80, 10)
expect(pointsOf('z')).toEqual(SQUARE)
expect(depth()).toBe(before)
})
})
describe('I-3: the click a touch tap synthesises is absorbed', () => {
// A tap arms its absorber for 400 ms: let it lapse before the next test clicks.
afterEach(() => new Promise((done) => setTimeout(done, 450)))
const tapOn = (el: Element, pointerType: string) => {
const init = {
pointerId: 1,
isPrimary: true,
button: 0,
buttons: 1,
pointerType,
clientX: 50,
clientY: 50,
}
fireEvent.pointerDown(el, init)
fireEvent.pointerUp(el, { ...init, buttons: 0 })
}
const addPoint = () =>
screen.getByRole('button', { name: 'Ajouter un point' })
/** A click at the tap's own place, as the browser synthesises it. */
const clickAtTap = (el: Element) =>
fireEvent.click(el, { clientX: 50, clientY: 50 })
const creation = () => screen.queryByTestId('annotation-creation')
it('a touch tap: its click landing elsewhere does nothing; the next click does', async () => {
await mount(squareText())
await select()
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
expect(screen.queryByTestId('annotation-properties')).toBeNull()
clickAtTap(addPoint())
expect(creation()).toBeNull()
clickAtTap(addPoint())
expect(creation()).not.toBeNull()
})
it('a pen tap is absorbed too; a mouse tap never is', async () => {
await mount(squareText())
tapOn(screen.getByTestId('annotation-canvas'), 'pen')
clickAtTap(addPoint())
expect(creation()).toBeNull()
tapOn(screen.getByTestId('annotation-canvas'), 'mouse')
clickAtTap(addPoint())
expect(creation()).not.toBeNull()
})
it('a click elsewhere right after a tap goes through', async () => {
await mount(squareText())
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
fireEvent.click(addPoint(), { clientX: 300, clientY: 300 })
expect(creation()).not.toBeNull()
})
it('a real click after the double-click window goes through', async () => {
await mount(squareText())
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
try {
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
act(() => void vi.advanceTimersByTime(450))
clickAtTap(addPoint())
expect(creation()).not.toBeNull()
} finally {
vi.useRealTimers()
}
})
})
describe('the zoom hint for short segments (R-18, D2)', () => {
const SHORT: Point[] = [
[20, 20],
@@ -674,3 +838,44 @@ describe('the zoom hint for short segments (R-18, D2)', () => {
)
})
})
describe('M-5: « Fermeture refusée » titles a refused close only', () => {
const t = (key: string) => (fr as Record<string, string>)[key] ?? key
const tracing = (refused: boolean) => ({
...initialUi,
tool: 'zone' as const,
hint: 'un autre message',
tracing: {
target: 'zone' as const,
annotationId: null,
points: [] as Point[],
refused,
},
})
it('another hint during a tracing keeps the tracing title', () => {
const lead = stripLeadOf(
tracing(false),
undefined,
JSON.parse(drawnText()),
{
t,
locale: 'fr',
},
)
expect(lead.title).toBe('Ajouter une zone')
})
it('a refused close says so', () => {
const lead = stripLeadOf(
tracing(true),
undefined,
JSON.parse(drawnText()),
{
t,
locale: 'fr',
},
)
expect(lead.title).toBe('Fermeture refusée')
})
})