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.
71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
/** U2 Task 8: the two-finger pan of the editor (`twoPointerPan`); the catalogue keeps its pinch. */
|
|
import { describe, expect, it } from 'vitest'
|
|
import { act, renderHook } from '@testing-library/react'
|
|
import type { PointerEvent } from 'react'
|
|
import { useFraming, type FramingOptions } from '@/catalogue/useFraming'
|
|
|
|
const BOX = { left: 0, top: 0, width: 400, height: 300 }
|
|
|
|
function viewport() {
|
|
const element = document.createElement('div')
|
|
element.getBoundingClientRect = () =>
|
|
({ ...BOX, right: BOX.width, bottom: BOX.height, x: 0, y: 0 }) as DOMRect
|
|
return { current: element }
|
|
}
|
|
|
|
const pointer = (pointerId: number, x: number, y: number) =>
|
|
({
|
|
pointerId,
|
|
clientX: x,
|
|
clientY: y,
|
|
currentTarget: { setPointerCapture: () => {} },
|
|
}) as unknown as PointerEvent
|
|
|
|
function mount(options?: FramingOptions) {
|
|
return renderHook(() => useFraming(viewport(), 'view', options)).result
|
|
}
|
|
|
|
type Hook = ReturnType<typeof mount>
|
|
|
|
/** Two fingers at (100, 100) and (200, 100), the trailing one moved first, both by `dx`. */
|
|
function moveTogether(result: Hook, dx: number) {
|
|
const { handlers } = result.current
|
|
act(() => {
|
|
handlers.onPointerDown(pointer(1, 100, 100))
|
|
handlers.onPointerDown(pointer(2, 200, 100))
|
|
})
|
|
act(() => result.current.handlers.onPointerMove(pointer(1, 100 + dx, 100)))
|
|
act(() => result.current.handlers.onPointerMove(pointer(2, 200 + dx, 100)))
|
|
}
|
|
|
|
describe('useFraming with twoPointerPan (U2 Task 8)', () => {
|
|
it('two pointers moving together translate by their movement without scaling', () => {
|
|
const result = mount({ twoPointerPan: true })
|
|
act(() => result.current.zoomIn())
|
|
const before = result.current.framing
|
|
expect(before.scale).toBe(1.5)
|
|
moveTogether(result, 20)
|
|
const after = result.current.framing
|
|
expect(after.scale).toBeCloseTo(1.5, 9)
|
|
expect(after.x - before.x).toBeCloseTo(20, 9)
|
|
expect(after.y).toBeCloseTo(before.y, 9)
|
|
})
|
|
|
|
it('at the fit, a pan that first narrows the fingers zooms nothing (no clamp ratchet)', () => {
|
|
const result = mount({ twoPointerPan: true })
|
|
moveTogether(result, 20)
|
|
expect(result.current.framing).toEqual({ scale: 1, x: 0, y: 0 })
|
|
})
|
|
|
|
it('still zooms when the fingers spread', () => {
|
|
const result = mount({ twoPointerPan: true })
|
|
const { handlers } = result.current
|
|
act(() => {
|
|
handlers.onPointerDown(pointer(1, 150, 150))
|
|
handlers.onPointerDown(pointer(2, 250, 150))
|
|
})
|
|
act(() => result.current.handlers.onPointerMove(pointer(2, 300, 150)))
|
|
expect(result.current.framing.scale).toBeCloseTo(1.5, 9)
|
|
})
|
|
})
|