refactor(editor): one press machine for clicks, drags and taps on the drawing
press.ts (pure: slop per pointer kind, nearest handle, press target, click and drag actions, double click, stepPress) is now the editor canvas's only decider; useCanvasGestures no longer uses clickHandler, useEmptyTap, swallowClick nor useMoveGesture (deleted), and the box has no onClick. canPan = dragAction(press target).type === 'pan' at pointer-down; framing keys only when the box itself is the target. workStore.ts holds the U2 work with stale stamps: dropStale on every documentText change, reset on a new session (editorStore subscription). The catalogue keeps useFraming defaults and useEmptyTap, unchanged. Named change (A13): a finger drag on a selected zone's (or circle link's) interior moves nothing; the selected point is its own handle and still moves by any pointer. Second observable change: touch and pen taps are decided at the pointer-up from the press target, no longer from the following click (no browser touch adjustment toward a marker). tests/setup.ts: happy-dom has no elementsFromPoint; a shim answers the pointerdown target and its ancestors. Rewritten tests (editor-annotations-tab.test.tsx, D6b): - "a touch tap deselects in its own click, not at the pointer-up" -> "a touch tap deselects at the pointer-up" (deselected after pointerup) - "a touch tap whose click lands on a marker (adjustment) selects that marker" -> "a touch tap is decided by its press: a click adjusted toward a marker selects nothing" (deselected, announced, marker b not current) - "a pen tap deselects in its own click, like a touch tap" -> "a pen tap deselects at the pointer-up, like a mouse tap" - "a pen tap whose click lands on a marker selects that marker" -> "a pen tap is decided by its press: a click landing on a marker selects nothing" Added: "a finger drags the selected point (its handle), never a selected zone (A13)". Drive-only changes, assertions unchanged: canvas fireEvent.click(x, y) -> pressAt (pointerdown + pointerup) in the tab suite (C26, tracing, paths, H3, H6, H8, filter reselect), editor-keep-alive and editor-sections; drag moves carry buttons: 1 (C34, polygon block move, H8 lostpointercapture and read-only, editor-no-loss drag in flight), since a move without a button is a hover.
This commit is contained in:
1 parent
5ca2b7e3ad
commit
08d266c89f
18 files changed
+1341
-311
No files matched your search
@@ -0,0 +1,345 @@
|
||||
/** U2 Task 2: the press machine, the editor's one decider for clicks, drags and taps. */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
clickAction,
|
||||
dragAction,
|
||||
isDoubleClick,
|
||||
nearestHandle,
|
||||
pressTarget,
|
||||
stepPress,
|
||||
type DragContext,
|
||||
type Hit,
|
||||
type Press,
|
||||
type PressEvent,
|
||||
type PressTarget,
|
||||
type Selection,
|
||||
} from '@/editor/annotations/press'
|
||||
|
||||
const NONE: Selection = { selectedId: null, chosenVertex: null }
|
||||
const ZONE: Selection = { selectedId: 'zone', chosenVertex: null }
|
||||
|
||||
describe('nearestHandle (R-9)', () => {
|
||||
it('takes the nearest of three overlapping hit circles (an 11 px segment)', () => {
|
||||
const hits: Hit[] = [
|
||||
{
|
||||
kind: 'handle',
|
||||
handle: { kind: 'vertex', index: 0 },
|
||||
centre: { x: 0, y: 0 },
|
||||
},
|
||||
{
|
||||
kind: 'handle',
|
||||
handle: { kind: 'insert', after: 0 },
|
||||
centre: { x: 5.5, y: 0 },
|
||||
},
|
||||
{
|
||||
kind: 'handle',
|
||||
handle: { kind: 'vertex', index: 1 },
|
||||
centre: { x: 11, y: 0 },
|
||||
},
|
||||
]
|
||||
expect(nearestHandle(hits, { x: 9, y: 0 })).toEqual({
|
||||
kind: 'vertex',
|
||||
index: 1,
|
||||
})
|
||||
expect(nearestHandle(hits, { x: 5, y: 1 })).toEqual({
|
||||
kind: 'insert',
|
||||
after: 0,
|
||||
})
|
||||
expect(nearestHandle(hits, { x: 1, y: 0 })).toEqual({
|
||||
kind: 'vertex',
|
||||
index: 0,
|
||||
})
|
||||
})
|
||||
|
||||
it('at a tie a vertex beats « − », which beats « + »', () => {
|
||||
const at = { x: 0, y: 0 }
|
||||
const remove: Hit = {
|
||||
kind: 'handle',
|
||||
handle: { kind: 'remove', index: 2 },
|
||||
centre: { x: 3, y: 0 },
|
||||
}
|
||||
const insert: Hit = {
|
||||
kind: 'handle',
|
||||
handle: { kind: 'insert', after: 2 },
|
||||
centre: { x: -3, y: 0 },
|
||||
}
|
||||
const vertex: Hit = {
|
||||
kind: 'handle',
|
||||
handle: { kind: 'vertex', index: 2 },
|
||||
centre: { x: 0, y: 3 },
|
||||
}
|
||||
expect(nearestHandle([insert, remove, vertex], at)).toEqual(vertex.handle)
|
||||
expect(nearestHandle([insert, remove], at)).toEqual(remove.handle)
|
||||
expect(nearestHandle([remove, insert], at)).toEqual(remove.handle)
|
||||
})
|
||||
|
||||
it('answers null without a handle', () => {
|
||||
expect(
|
||||
nearestHandle([{ kind: 'annotation', id: 'a' }], { x: 0, y: 0 }),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('pressTarget (board 32)', () => {
|
||||
const at = { x: 0, y: 0 }
|
||||
it('a selected zone hit first, a point hitbox under it: the interior', () => {
|
||||
const hits: Hit[] = [
|
||||
{ kind: 'annotation', id: 'zone' },
|
||||
{ kind: 'annotation', id: 'point' },
|
||||
]
|
||||
expect(pressTarget(hits, at, ZONE)).toEqual({
|
||||
kind: 'interior',
|
||||
id: 'zone',
|
||||
})
|
||||
})
|
||||
|
||||
it('a point twin hit first, the selected zone under it: the other one', () => {
|
||||
const hits: Hit[] = [
|
||||
{ kind: 'annotation', id: 'point' },
|
||||
{ kind: 'annotation', id: 'zone' },
|
||||
]
|
||||
expect(pressTarget(hits, at, ZONE)).toEqual({ kind: 'other', id: 'point' })
|
||||
})
|
||||
|
||||
it('a handle wins over every annotation; nothing is empty', () => {
|
||||
const hits: Hit[] = [
|
||||
{ kind: 'annotation', id: 'point' },
|
||||
{ kind: 'handle', handle: { kind: 'vertex', index: 1 }, centre: at },
|
||||
]
|
||||
expect(pressTarget(hits, at, ZONE)).toEqual({
|
||||
kind: 'handle',
|
||||
handle: { kind: 'vertex', index: 1 },
|
||||
})
|
||||
expect(pressTarget([], at, ZONE)).toEqual({ kind: 'empty' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('clickAction (A1)', () => {
|
||||
const handle = (h: PressTarget & { kind: 'handle' }) => h
|
||||
it('selects another, deselects on empty', () => {
|
||||
expect(clickAction({ kind: 'other', id: 'b' }, ZONE)).toEqual({
|
||||
type: 'select',
|
||||
id: 'b',
|
||||
})
|
||||
expect(clickAction({ kind: 'empty' }, ZONE)).toEqual({ type: 'deselect' })
|
||||
})
|
||||
|
||||
it('the interior opens without a chosen vertex, unchooses with one', () => {
|
||||
const interior: PressTarget = { kind: 'interior', id: 'zone' }
|
||||
expect(clickAction(interior, ZONE)).toEqual({ type: 'open', id: 'zone' })
|
||||
expect(clickAction(interior, { ...ZONE, chosenVertex: 2 })).toEqual({
|
||||
type: 'unchoose',
|
||||
})
|
||||
})
|
||||
|
||||
it('maps each handle, and a point handle opens the selection', () => {
|
||||
const on = (h: Parameters<typeof handle>[0]['handle']) =>
|
||||
clickAction(handle({ kind: 'handle', handle: h }), ZONE)
|
||||
expect(on({ kind: 'vertex', index: 3 })).toEqual({
|
||||
type: 'choose_vertex',
|
||||
index: 3,
|
||||
})
|
||||
expect(on({ kind: 'insert', after: 1 })).toEqual({
|
||||
type: 'insert',
|
||||
after: 1,
|
||||
})
|
||||
expect(on({ kind: 'remove', index: 2 })).toEqual({
|
||||
type: 'remove',
|
||||
index: 2,
|
||||
})
|
||||
expect(on({ kind: 'point' })).toEqual({ type: 'open', id: 'zone' })
|
||||
expect(
|
||||
clickAction({ kind: 'handle', handle: { kind: 'point' } }, NONE),
|
||||
).toEqual({
|
||||
type: 'deselect',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('isDoubleClick (R-8)', () => {
|
||||
const last = { at: { x: 0, y: 0 }, time: 1000 }
|
||||
it('holds within 400 ms and 8 px, edges included', () => {
|
||||
expect(isDoubleClick(last, { x: 8, y: 0 }, 1400)).toBe(true)
|
||||
expect(isDoubleClick(last, { x: 8.01, y: 0 }, 1400)).toBe(false)
|
||||
expect(isDoubleClick(last, { x: 0, y: 0 }, 1400.5)).toBe(false)
|
||||
expect(isDoubleClick(null, { x: 0, y: 0 }, 1000)).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('dragAction (A13)', () => {
|
||||
const ctx = (over: Partial<DragContext> = {}): DragContext => ({
|
||||
kind: 'mouse',
|
||||
movable: true,
|
||||
moveMode: false,
|
||||
...over,
|
||||
})
|
||||
const interior: PressTarget = { kind: 'interior', id: 'zone' }
|
||||
const point: PressTarget = { kind: 'handle', handle: { kind: 'point' } }
|
||||
|
||||
it('a move mode drags whatever the target or the pointer', () => {
|
||||
for (const kind of ['mouse', 'pen', 'touch'] as const) {
|
||||
for (const target of [
|
||||
interior,
|
||||
point,
|
||||
{ kind: 'empty' } as PressTarget,
|
||||
]) {
|
||||
expect(dragAction(target, ctx({ kind, moveMode: true }))).toEqual({
|
||||
type: 'drag_mode',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('a finger moves only what it holds: off a handle it is futile', () => {
|
||||
const touch = ctx({ kind: 'touch' })
|
||||
expect(dragAction(point, touch)).toEqual({ type: 'drag_point' })
|
||||
expect(
|
||||
dragAction(
|
||||
{ kind: 'handle', handle: { kind: 'vertex', index: 4 } },
|
||||
touch,
|
||||
),
|
||||
).toEqual({
|
||||
type: 'drag_vertex',
|
||||
index: 4,
|
||||
})
|
||||
expect(dragAction(interior, touch)).toEqual({ type: 'none', futile: true })
|
||||
expect(dragAction({ kind: 'empty' }, touch)).toEqual({
|
||||
type: 'none',
|
||||
futile: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('a mouse or pen drags the movable interior, pans otherwise', () => {
|
||||
expect(dragAction(interior, ctx())).toEqual({
|
||||
type: 'drag_shape',
|
||||
id: 'zone',
|
||||
})
|
||||
expect(dragAction(interior, ctx({ kind: 'pen' }))).toEqual({
|
||||
type: 'drag_shape',
|
||||
id: 'zone',
|
||||
})
|
||||
expect(dragAction(interior, ctx({ movable: false }))).toEqual({
|
||||
type: 'pan',
|
||||
})
|
||||
expect(dragAction({ kind: 'other', id: 'b' }, ctx())).toEqual({
|
||||
type: 'pan',
|
||||
})
|
||||
expect(dragAction({ kind: 'empty' }, ctx())).toEqual({ type: 'pan' })
|
||||
})
|
||||
|
||||
it('« + » and « − » never drag; an unmovable handle moves nothing', () => {
|
||||
for (const kind of ['mouse', 'touch'] as const) {
|
||||
expect(
|
||||
dragAction(
|
||||
{ kind: 'handle', handle: { kind: 'insert', after: 0 } },
|
||||
ctx({ kind }),
|
||||
),
|
||||
).toEqual({ type: 'none', futile: false })
|
||||
expect(
|
||||
dragAction(
|
||||
{ kind: 'handle', handle: { kind: 'remove', index: 0 } },
|
||||
ctx({ kind }),
|
||||
),
|
||||
).toEqual({ type: 'none', futile: false })
|
||||
}
|
||||
expect(dragAction(point, ctx({ movable: false }))).toEqual({
|
||||
type: 'none',
|
||||
futile: false,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('stepPress (R-8)', () => {
|
||||
const ctx = { movable: true, moveMode: false }
|
||||
const target: PressTarget = { kind: 'interior', id: 'zone' }
|
||||
const down = (
|
||||
pointerId: number,
|
||||
pointers: number,
|
||||
kind = 'mouse' as const,
|
||||
): PressEvent => ({
|
||||
type: 'down',
|
||||
pointerId,
|
||||
kind,
|
||||
at: { x: 0, y: 0 },
|
||||
target,
|
||||
pointers,
|
||||
})
|
||||
const move = (pointerId: number, x: number): PressEvent => ({
|
||||
type: 'move',
|
||||
pointerId,
|
||||
at: { x, y: 0 },
|
||||
})
|
||||
const up = (pointerId: number, pointers: number): PressEvent => ({
|
||||
type: 'up',
|
||||
pointerId,
|
||||
pointers,
|
||||
})
|
||||
/** Runs the events from idle; answers the effects and the last press. */
|
||||
function run(events: PressEvent[]) {
|
||||
let press: Press = { phase: 'idle' }
|
||||
const effects = events.map((event) => {
|
||||
const step = stepPress(press, event, ctx)
|
||||
press = step.press
|
||||
return step.effect
|
||||
})
|
||||
return { press, effects }
|
||||
}
|
||||
|
||||
it('a single press within the slop is a click', () => {
|
||||
const { press, effects } = run([down(1, 1), move(1, 4), up(1, 0)])
|
||||
expect(effects).toEqual([null, null, { type: 'click', target }])
|
||||
expect(press).toEqual({ phase: 'idle' })
|
||||
})
|
||||
|
||||
it('past the slop it starts a drag, then ends it', () => {
|
||||
const action = { type: 'drag_shape', id: 'zone' }
|
||||
const { press, effects } = run([
|
||||
down(1, 1),
|
||||
move(1, 5),
|
||||
move(1, 30),
|
||||
up(1, 0),
|
||||
])
|
||||
expect(effects).toEqual([
|
||||
null,
|
||||
{ type: 'drag_start', action },
|
||||
null,
|
||||
{ type: 'drag_end' },
|
||||
])
|
||||
expect(press).toEqual({ phase: 'idle' })
|
||||
})
|
||||
|
||||
it('the slop follows the pointer kind', () => {
|
||||
const finger = run([down(1, 1, 'touch' as never), move(1, 10), up(1, 0)])
|
||||
expect(finger.effects[2]).toEqual({ type: 'click', target })
|
||||
})
|
||||
|
||||
it('a second down while down is a gesture: no click on any up, idle at zero pointers', () => {
|
||||
const { press, effects } = run([down(1, 1), down(2, 2), up(1, 1), up(2, 0)])
|
||||
expect(effects).toEqual([null, null, null, null])
|
||||
expect(press).toEqual({ phase: 'idle' })
|
||||
const held = run([down(1, 1), down(2, 2), up(2, 1)])
|
||||
expect(held.press).toEqual({ phase: 'multi' })
|
||||
})
|
||||
|
||||
it('a second down while dragging cancels the drag', () => {
|
||||
const { press, effects } = run([down(1, 1), move(1, 20), down(2, 2)])
|
||||
expect(effects[2]).toEqual({ type: 'drag_cancel' })
|
||||
expect(press).toEqual({ phase: 'multi' })
|
||||
})
|
||||
|
||||
it('cancel while dragging cancels the drag; while down it is silent', () => {
|
||||
expect(
|
||||
run([down(1, 1), move(1, 20), { type: 'cancel' }]).effects[2],
|
||||
).toEqual({
|
||||
type: 'drag_cancel',
|
||||
})
|
||||
const quiet = run([down(1, 1), { type: 'cancel' }, up(1, 0)])
|
||||
expect(quiet.effects).toEqual([null, null, null])
|
||||
})
|
||||
|
||||
it('ignores a move from another pointer id', () => {
|
||||
const { press, effects } = run([down(1, 1), move(2, 50), up(1, 0)])
|
||||
expect(effects).toEqual([null, null, { type: 'click', target }])
|
||||
expect(press).toEqual({ phase: 'idle' })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,52 @@
|
||||
/** U2 Task 2: the annotation work store and its stale stamp (R-13). */
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
dropStale,
|
||||
resetWork,
|
||||
useAnnotationWork,
|
||||
type Preview,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { useEditorStore } from '@/editor/state/editorStore'
|
||||
|
||||
const preview = (base: string): Preview => ({
|
||||
annotationId: 'a',
|
||||
geometry: { type: 'circle', cx: 1, cy: 2, r: 3 },
|
||||
base,
|
||||
source: 'move',
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
resetWork()
|
||||
useEditorStore.setState({ documentText: '', session: 0 })
|
||||
})
|
||||
|
||||
describe('dropStale (R-13)', () => {
|
||||
it('drops what was computed on another text, keeps what was computed on this one', () => {
|
||||
useAnnotationWork.setState({
|
||||
preview: preview('one'),
|
||||
chosen: { annotationId: 'a', vertex: 1, base: 'one' },
|
||||
})
|
||||
dropStale('one')
|
||||
expect(useAnnotationWork.getState().preview).toEqual(preview('one'))
|
||||
expect(useAnnotationWork.getState().chosen).not.toBeNull()
|
||||
dropStale('two')
|
||||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||||
expect(useAnnotationWork.getState().chosen).toBeNull()
|
||||
})
|
||||
|
||||
it('runs on every document change of the editor store', () => {
|
||||
useAnnotationWork.setState({ preview: preview('one') })
|
||||
useEditorStore.setState({ documentText: 'one' })
|
||||
expect(useAnnotationWork.getState().preview).not.toBeNull()
|
||||
useEditorStore.setState({ documentText: 'two' })
|
||||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||||
})
|
||||
|
||||
it('a new session (another sheet, the editor closed) resets the work', () => {
|
||||
useAnnotationWork.setState({
|
||||
mode: { kind: 'move', annotationId: 'a', started: true },
|
||||
})
|
||||
useEditorStore.setState({ session: useEditorStore.getState().session + 1 })
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
commitMove,
|
||||
openReady,
|
||||
resetStore,
|
||||
pressAt,
|
||||
sb,
|
||||
store,
|
||||
versionAnswer,
|
||||
@@ -274,10 +275,7 @@ describe('the point tool and the corrected position (C26)', () => {
|
||||
async function clickCorner() {
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 0,
|
||||
clientY: 0,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 0, 0)
|
||||
return user
|
||||
}
|
||||
|
||||
@@ -351,10 +349,7 @@ describe('the point tool and the corrected position (C26)', () => {
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: -5,
|
||||
clientY: 50,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), -5, 50)
|
||||
expect(
|
||||
await screen.findByText("Cliquez à l'intérieur du dessin."),
|
||||
).toBeInTheDocument()
|
||||
@@ -379,7 +374,12 @@ describe('select and move gestures (C34)', () => {
|
||||
pointerId: 1,
|
||||
})
|
||||
const moveTo = (el: Element, x: number, y: number) =>
|
||||
fireEvent.pointerMove(el, { clientX: x, clientY: y, pointerId: 1 })
|
||||
fireEvent.pointerMove(el, {
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
pointerId: 1,
|
||||
buttons: 1,
|
||||
})
|
||||
const up = (el: Element, x: number, y: number) =>
|
||||
fireEvent.pointerUp(el, { clientX: x, clientY: y, pointerId: 1 })
|
||||
|
||||
@@ -555,10 +555,7 @@ const zoneAnnotation = (geometry: object): Annotation =>
|
||||
|
||||
describe('tracing a zone or a link', () => {
|
||||
const clickAt = (x: number, y: number) =>
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), x, y)
|
||||
|
||||
it('closes on Enter, holds the polygon pending, inserts it on « Créer »', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
@@ -689,7 +686,12 @@ describe('polygons and paths', () => {
|
||||
button: 0,
|
||||
pointerId: 1,
|
||||
})
|
||||
fireEvent.pointerMove(hit, { clientX: 55, clientY: 40, pointerId: 1 })
|
||||
fireEvent.pointerMove(hit, {
|
||||
clientX: 55,
|
||||
clientY: 40,
|
||||
pointerId: 1,
|
||||
buttons: 1,
|
||||
})
|
||||
fireEvent.pointerUp(hit, { clientX: 60, clientY: 45, pointerId: 1 })
|
||||
expect(geometryOf('zone-a')).toMatchObject({
|
||||
points: [
|
||||
@@ -712,9 +714,7 @@ describe('polygons and paths', () => {
|
||||
}),
|
||||
)
|
||||
const canvas = screen.getByTestId('annotation-canvas')
|
||||
triangle.forEach(([x, y]) =>
|
||||
fireEvent.click(canvas, { clientX: x, clientY: y }),
|
||||
)
|
||||
triangle.forEach(([x, y]) => pressAt(canvas, x, y))
|
||||
fireEvent.keyDown(canvas, { key: 'Enter' })
|
||||
await waitFor(() =>
|
||||
expect(geometryOf('zone-a')).toEqual({
|
||||
@@ -727,10 +727,7 @@ describe('polygons and paths', () => {
|
||||
|
||||
describe('keys while tracing (H3)', () => {
|
||||
const clickAt = (x: number, y: number) =>
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), x, y)
|
||||
|
||||
async function traced() {
|
||||
await mount({ text: drawnText() })
|
||||
@@ -774,15 +771,9 @@ describe('a second click with the point tool (H6)', () => {
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 50,
|
||||
clientY: 50,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 50, 50)
|
||||
const panel = await fillCreation(user)
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 60,
|
||||
clientY: 40,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 60, 40)
|
||||
await waitFor(() =>
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('60'),
|
||||
)
|
||||
@@ -867,7 +858,7 @@ describe('refusals through the tab (H8)', () => {
|
||||
[20, 20],
|
||||
[500, 20],
|
||||
[50, 80],
|
||||
].forEach(([x, y]) => fireEvent.click(canvas, { clientX: x, clientY: y }))
|
||||
].forEach(([x, y]) => pressAt(canvas, x, y))
|
||||
fireEvent.keyDown(canvas, { key: 'Enter' })
|
||||
expect(await screen.findByRole('alert')).toBeInTheDocument()
|
||||
expect(
|
||||
@@ -917,7 +908,12 @@ describe('the drag and the canvas follow the handle (H8)', () => {
|
||||
const hit = marker('anno-a')
|
||||
const version = store.getState().handleVersion
|
||||
down(hit, 50, 50)
|
||||
fireEvent.pointerMove(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
fireEvent.pointerMove(hit, {
|
||||
clientX: 70,
|
||||
clientY: 50,
|
||||
pointerId: 1,
|
||||
buttons: 1,
|
||||
})
|
||||
fireEvent.lostPointerCapture(hit, { pointerId: 1 })
|
||||
fireEvent.pointerUp(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
expect(store.getState().handleVersion).toBe(version)
|
||||
@@ -935,7 +931,12 @@ describe('the drag and the canvas follow the handle (H8)', () => {
|
||||
const hit = marker('anno-a')
|
||||
const version = store.getState().handleVersion
|
||||
down(hit, 50, 50)
|
||||
fireEvent.pointerMove(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
fireEvent.pointerMove(hit, {
|
||||
clientX: 70,
|
||||
clientY: 50,
|
||||
pointerId: 1,
|
||||
buttons: 1,
|
||||
})
|
||||
view.rerender(<AnnotationsTab {...props} readOnly />)
|
||||
fireEvent.pointerUp(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
expect(store.getState().handleVersion).toBe(version)
|
||||
@@ -1009,10 +1010,10 @@ describe('« Désélectionner » (R1, A6)', () => {
|
||||
await userEvent.setup().click(button(panel))
|
||||
const filter = screen.getByLabelText('Filtrer par nom')
|
||||
fireEvent.change(filter, { target: { value: 'zzz-no-match' } })
|
||||
fireEvent.click(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector(
|
||||
'[data-anno-id="anno-a"]',
|
||||
)!,
|
||||
pressAt(
|
||||
screen
|
||||
.getByTestId('annotation-canvas-drawing')
|
||||
.querySelector('[data-anno-id="anno-a"]')!,
|
||||
)
|
||||
const reopened = await screen.findByTestId('annotation-properties')
|
||||
await userEvent.setup().click(button(reopened))
|
||||
@@ -1035,7 +1036,9 @@ describe('« Désélectionner » (R1, A6)', () => {
|
||||
it('read-only: no « Supprimer », it deselects and focuses the ro- row', async () => {
|
||||
await mountSpy({ readOnly: true })
|
||||
const panel = await selectFromList()
|
||||
expect(within(panel).queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
||||
expect(
|
||||
within(panel).queryByRole('button', { name: 'Supprimer' }),
|
||||
).toBeNull()
|
||||
await userEvent.setup().click(button(panel))
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
const row = document.querySelector(
|
||||
@@ -1089,9 +1092,13 @@ describe('« Désélectionner » (R1, A6)', () => {
|
||||
}),
|
||||
})
|
||||
const panel = await selectFromList()
|
||||
await userEvent.setup().click(
|
||||
within(panel).getByRole('button', { name: 'Remplacer par un polygone' }),
|
||||
)
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
const open = await screen.findByTestId('annotation-properties')
|
||||
expect(
|
||||
within(open).queryByRole('button', { name: 'Désélectionner' }),
|
||||
@@ -1275,23 +1282,21 @@ describe('a tap on the drawing (D6b)', () => {
|
||||
expect(fireEvent.keyDown(canvas, { key: 'ArrowLeft' })).toBe(false)
|
||||
})
|
||||
|
||||
it('a pen tap deselects in its own click, like a touch tap', async () => {
|
||||
it('a pen tap deselects at the pointer-up, like a mouse tap', async () => {
|
||||
await selected()
|
||||
const hit = rect()
|
||||
fireEvent.pointerDown(hit, { ...init(1, 'pen'), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerUp(hit, { ...init(1, 'pen'), clientX: 10, clientY: 10 })
|
||||
expect(isDeselected()).toBe(false)
|
||||
fireEvent.click(hit)
|
||||
expect(isDeselected()).toBe(true)
|
||||
expect(announce).toHaveBeenCalledWith(DESELECTED)
|
||||
})
|
||||
|
||||
it('a pen tap whose click lands on a marker selects that marker', async () => {
|
||||
it('a pen tap is decided by its press: a click landing on a marker selects nothing', async () => {
|
||||
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
|
||||
tap(rect(), { type: 'pen', upOn: marker('anno-b') })
|
||||
expect(announce).not.toHaveBeenCalled()
|
||||
expect(marker('anno-b')).toHaveAttribute('data-state', 'current')
|
||||
expect(marker('anno-a')).not.toHaveAttribute('data-state')
|
||||
expect(announce).toHaveBeenCalledWith(DESELECTED)
|
||||
expect(marker('anno-b')).not.toHaveAttribute('data-state')
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('a hover move after the press does not count as a drag', async () => {
|
||||
@@ -1312,7 +1317,11 @@ describe('a tap on the drawing (D6b)', () => {
|
||||
await selected()
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerUp(document.body, { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerDown(document.body, { ...init(), clientX: 300, clientY: 10 })
|
||||
fireEvent.pointerDown(document.body, {
|
||||
...init(),
|
||||
clientX: 300,
|
||||
clientY: 10,
|
||||
})
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(rect())
|
||||
expect(isDeselected()).toBe(false)
|
||||
@@ -1432,7 +1441,7 @@ describe('a tap on the drawing (D6b)', () => {
|
||||
expect(isDeselected()).toBe(false)
|
||||
})
|
||||
|
||||
it('a touch tap deselects in its own click, not at the pointer-up', async () => {
|
||||
it('a touch tap deselects at the pointer-up', async () => {
|
||||
await selected()
|
||||
const hit = rect()
|
||||
fireEvent.pointerDown(hit, {
|
||||
@@ -1441,18 +1450,42 @@ describe('a tap on the drawing (D6b)', () => {
|
||||
clientY: 10,
|
||||
})
|
||||
fireEvent.pointerUp(hit, { ...init(1, 'touch'), clientX: 10, clientY: 10 })
|
||||
expect(isDeselected()).toBe(false)
|
||||
fireEvent.click(hit)
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('a touch tap whose click lands on a marker (adjustment) selects that marker', async () => {
|
||||
it('a touch tap is decided by its press: a click adjusted toward a marker selects nothing', async () => {
|
||||
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
|
||||
tap(rect(), { type: 'touch', upOn: marker('anno-b') })
|
||||
expect(announce).not.toHaveBeenCalled()
|
||||
expect(announce).toHaveBeenCalledWith(DESELECTED)
|
||||
expect(isDeselected()).toBe(true)
|
||||
expect(marker('anno-b')).not.toHaveAttribute('data-state')
|
||||
})
|
||||
|
||||
it('a finger drags the selected point (its handle), never a selected zone (A13)', async () => {
|
||||
const zone = zoneAnnotation({ type: 'polygon', points: triangle })
|
||||
await selected({
|
||||
text: insert(text(), { kind: 'annotation', value: zone }),
|
||||
})
|
||||
const drag = (el: Element) => {
|
||||
fireEvent.pointerDown(el, {
|
||||
...init(1, 'touch'),
|
||||
clientX: 50,
|
||||
clientY: 50,
|
||||
})
|
||||
fireEvent.pointerMove(el, {
|
||||
...init(1, 'touch'),
|
||||
clientX: 70,
|
||||
clientY: 50,
|
||||
})
|
||||
fireEvent.pointerUp(el, { ...init(1, 'touch'), clientX: 70, clientY: 40 })
|
||||
}
|
||||
drag(marker('anno-a'))
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 70, cy: 40 })
|
||||
tap(marker('zone-a'))
|
||||
const before = store.getState().documentText
|
||||
drag(marker('zone-a'))
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(isDeselected()).toBe(false)
|
||||
expect(marker('anno-b')).toHaveAttribute('data-state', 'current')
|
||||
expect(marker('anno-a')).not.toHaveAttribute('data-state')
|
||||
})
|
||||
|
||||
it('a mouse tap deselects at the pointer-up and swallows the click on a marker', async () => {
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
serverHas,
|
||||
store,
|
||||
versionAnswer,
|
||||
pressAt,
|
||||
} from '../helpers/editorHarness'
|
||||
import { testLayer } from '../helpers/findingsHost'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
@@ -500,10 +501,7 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
await user.click(
|
||||
inPlace('annotations.drawing').getByRole('button', { name: 'Zone' }),
|
||||
)
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 20,
|
||||
clientY: 20,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
|
||||
})
|
||||
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
|
||||
const bar = within(place('annotations.drawing')).getByTestId('tracing-bar')
|
||||
|
||||
@@ -348,7 +348,12 @@ describe('the guards of a width change', () => {
|
||||
button: 0,
|
||||
pointerId: 1,
|
||||
})
|
||||
fireEvent.pointerMove(marker(), { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
fireEvent.pointerMove(marker(), {
|
||||
clientX: 70,
|
||||
clientY: 50,
|
||||
pointerId: 1,
|
||||
buttons: 1,
|
||||
})
|
||||
const version = store.getState().handleVersion
|
||||
cross(800)
|
||||
cross(1280)
|
||||
|
||||
@@ -3,7 +3,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
@@ -25,6 +24,7 @@ import {
|
||||
resetStore,
|
||||
serverHas,
|
||||
store,
|
||||
pressAt,
|
||||
} from '../helpers/editorHarness'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
@@ -227,10 +227,7 @@ describe('the shown view disappears (undo)', () => {
|
||||
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 20,
|
||||
clientY: 30,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 20, 30)
|
||||
expect(screen.getByTestId('tracing-bar')).toBeInTheDocument()
|
||||
act(() => void store.getState().undoStep())
|
||||
await waitFor(() => expect(screen.queryByTestId('tracing-bar')).toBeNull())
|
||||
@@ -277,10 +274,7 @@ describe('« Aller à » an annotation while something is in progress', () => {
|
||||
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 20,
|
||||
clientY: 20,
|
||||
})
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
|
||||
})
|
||||
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'kept'))
|
||||
expect(document.activeElement).toBe(screen.getByTestId('tracing-bar'))
|
||||
|
||||
Reference in new issue
Block a user