feat(editor): two-finger pan, touch hint, loupe, touch-sized handles
useFraming gains twoPointerPan (the editor's pinch also pans by the midpoint and scales from the spread since the pinch began; the catalogue passes nothing). A futile one-finger drag shows the R-1 hint unless two fingers already worked in this editor visit (work store flag). A finger drag of a handle shows the loupe (technique A: the drawing copied once, data-anno-id stripped, outline on top). editor-touch.spec covers 1 024, 1 180 and 1 280 px with CDP touch. measure-drag.ts is the hand-run smoothness measure (MEASURE_DRAG=1). equineShape moved from editor-zones.spec to support/editor.ts, no assertion changed.
This commit is contained in:
1 parent
3a7715486b
commit
85231a2680
18 files changed
+1338
-53
No files matched your search
@@ -0,0 +1,222 @@
|
||||
/** U2 Task 8: the two-finger hint (R-1) and the loupe of a finger's drag. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation, Point } from '@faunosteo/core-wasm/types'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import { resetWork } from '@/editor/annotations/workStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { openReady, resetStore } from '../helpers/editorHarness'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||||
getSheetVersion: vi.fn(),
|
||||
downloadSheetDrawing: vi.fn(),
|
||||
saveSheetDraft: vi.fn(),
|
||||
getOfficialSheetAdmin: vi.fn(),
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
const props = {
|
||||
readOnly: false,
|
||||
navigate: vi.fn(),
|
||||
reloadSheet: vi.fn(),
|
||||
section: 'drawing' as const,
|
||||
visited: ['drawing'] as const,
|
||||
onOpenSection: vi.fn(),
|
||||
onBack: vi.fn(),
|
||||
}
|
||||
|
||||
const HINT = fr['editor.annotations.message.two_fingers']
|
||||
|
||||
function stubCtm(): void {
|
||||
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
|
||||
Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', {
|
||||
configurable: true,
|
||||
value: () => ({ ...identity, inverse: () => identity }),
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
stubCtm()
|
||||
})
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
resetWork()
|
||||
})
|
||||
|
||||
const SQUARE: Point[] = [
|
||||
[20, 20],
|
||||
[80, 20],
|
||||
[80, 80],
|
||||
[20, 80],
|
||||
]
|
||||
|
||||
const squareText = () =>
|
||||
insert(drawnText(), {
|
||||
kind: 'annotation',
|
||||
value: {
|
||||
...(point('z', 0, 0, 1).value as Annotation),
|
||||
kind: 'zone',
|
||||
geometry: { type: 'polygon', points: SQUARE },
|
||||
} as Annotation,
|
||||
})
|
||||
|
||||
const tab = () => (
|
||||
<div data-editor-workspace>
|
||||
<AnnotationsTab {...props} />
|
||||
</div>
|
||||
)
|
||||
|
||||
async function show() {
|
||||
render(tab())
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||||
).not.toBeNull(),
|
||||
)
|
||||
}
|
||||
|
||||
async function mount() {
|
||||
await openReady({ text: squareText() })
|
||||
await show()
|
||||
}
|
||||
|
||||
async function select() {
|
||||
const list = await screen.findByRole('list', {
|
||||
name: 'Annotations de la vue',
|
||||
})
|
||||
await userEvent.setup().click(within(list).getAllByRole('button')[0])
|
||||
await screen.findByRole('button', { name: 'Propriétés' })
|
||||
}
|
||||
|
||||
const canvas = () => screen.getByTestId('annotation-canvas')
|
||||
const line = () => screen.getByTestId('gesture-line')
|
||||
const loupe = () => screen.queryByTestId('loupe')
|
||||
const hitOf = (name: string) =>
|
||||
screen.getByRole('button', { name }).querySelector('[data-handle]')!
|
||||
|
||||
const finger = (
|
||||
pointerId: number,
|
||||
x: number,
|
||||
y: number,
|
||||
pointerType = 'touch',
|
||||
) => ({
|
||||
pointerId,
|
||||
isPrimary: pointerId === 1,
|
||||
button: 0,
|
||||
buttons: 1,
|
||||
pointerType,
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
})
|
||||
|
||||
/** One pointer pressed at `from`, moved to `to` (past every slop), released there. */
|
||||
function drag(el: Element, from: Point, to: Point, pointerType = 'touch') {
|
||||
fireEvent.pointerDown(el, finger(1, from[0], from[1], pointerType))
|
||||
fireEvent.pointerMove(el, finger(1, to[0], to[1], pointerType))
|
||||
fireEvent.pointerUp(el, {
|
||||
...finger(1, to[0], to[1], pointerType),
|
||||
buttons: 0,
|
||||
})
|
||||
}
|
||||
|
||||
/** Two fingers on the box, the second one spread: the drawing zooms. */
|
||||
function pinch() {
|
||||
fireEvent.pointerDown(canvas(), finger(1, 10, 10))
|
||||
fireEvent.pointerDown(canvas(), finger(2, 60, 10))
|
||||
fireEvent.pointerMove(canvas(), finger(2, 110, 10))
|
||||
fireEvent.pointerUp(canvas(), { ...finger(2, 110, 10), buttons: 0 })
|
||||
fireEvent.pointerUp(canvas(), { ...finger(1, 10, 10), buttons: 0 })
|
||||
}
|
||||
|
||||
describe('the two-finger hint (R-1)', () => {
|
||||
it('a finger dragged off the handles moves nothing and shows the hint', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
drag(canvas(), [5, 5], [45, 5])
|
||||
expect(line()).toHaveTextContent(HINT)
|
||||
})
|
||||
|
||||
it('a mouse drag pans: no hint', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
drag(canvas(), [5, 5], [45, 5], 'mouse')
|
||||
expect(line()).not.toHaveTextContent(HINT)
|
||||
})
|
||||
|
||||
it('never replaces a message that shows', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
drag(hitOf('Sommet 2'), [80, 20], [90, 10], 'mouse')
|
||||
expect(line()).toHaveTextContent('Sommet déplacé')
|
||||
drag(canvas(), [5, 5], [45, 5])
|
||||
expect(line()).toHaveTextContent('Sommet déplacé')
|
||||
expect(line()).not.toHaveTextContent(HINT)
|
||||
})
|
||||
|
||||
it('never shows again once two fingers worked, even after a remount', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
pinch()
|
||||
drag(canvas(), [5, 5], [45, 5])
|
||||
expect(line()).not.toHaveTextContent(HINT)
|
||||
cleanup()
|
||||
await show()
|
||||
await select()
|
||||
drag(canvas(), [5, 5], [45, 5])
|
||||
expect(line()).not.toHaveTextContent(HINT)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the loupe of a finger drag', () => {
|
||||
it('shows a picture of the drawing above the finger, then goes on the drop', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
const vertex = hitOf('Sommet 2')
|
||||
fireEvent.pointerDown(vertex, finger(1, 80, 20))
|
||||
fireEvent.pointerMove(vertex, finger(1, 95, 35))
|
||||
const shown = loupe()!
|
||||
expect(shown).not.toBeNull()
|
||||
expect(shown).toHaveAttribute('aria-hidden', 'true')
|
||||
expect(shown.hasAttribute('inert')).toBe(true)
|
||||
expect(shown.querySelector('svg')).not.toBeNull()
|
||||
expect(shown.querySelector('[data-anno-id]')).toBeNull()
|
||||
expect(shown.querySelector('polygon')).not.toBeNull()
|
||||
fireEvent.pointerUp(vertex, { ...finger(1, 95, 35), buttons: 0 })
|
||||
expect(loupe()).toBeNull()
|
||||
})
|
||||
|
||||
it('goes when the drag is cancelled by a second finger', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
const vertex = hitOf('Sommet 2')
|
||||
fireEvent.pointerDown(vertex, finger(1, 80, 20))
|
||||
fireEvent.pointerMove(vertex, finger(1, 95, 35))
|
||||
expect(loupe()).not.toBeNull()
|
||||
fireEvent.pointerDown(canvas(), finger(2, 10, 10))
|
||||
expect(loupe()).toBeNull()
|
||||
})
|
||||
|
||||
it('a mouse drag shows none', async () => {
|
||||
await mount()
|
||||
await select()
|
||||
const vertex = hitOf('Sommet 2')
|
||||
fireEvent.pointerDown(vertex, finger(1, 80, 20, 'mouse'))
|
||||
fireEvent.pointerMove(vertex, finger(1, 95, 35, 'mouse'))
|
||||
expect(loupe()).toBeNull()
|
||||
fireEvent.pointerUp(vertex, { ...finger(1, 95, 35, 'mouse'), buttons: 0 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user