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.
114 lines
3.2 KiB
TypeScript
114 lines
3.2 KiB
TypeScript
import { expect, vi } from 'vitest'
|
|
import { fireEvent } from '@testing-library/react'
|
|
import type { EditCommand } from '@faunosteo/core-wasm/types'
|
|
import * as supabase from '@faunosteo/supabase'
|
|
import { useEditorStore } from '@/editor/state/editorStore'
|
|
import { ASSET, drawnText, insert, point, svgBytes } from './editorFixtures'
|
|
|
|
/**
|
|
* The store harness. The calling test file declares the two module mocks (hoisted):
|
|
* vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
|
* vi.mock('@faunosteo/supabase', async (orig) => ({ ...(await orig()), getSheetVersion: vi.fn(),
|
|
* downloadSheetDrawing: vi.fn(), saveSheetDraft: vi.fn(), getOfficialSheetAdmin: vi.fn(),
|
|
* submitSheetReview: vi.fn() }))
|
|
*/
|
|
export const USER = 'user-1'
|
|
export const VERSION = 'ver-1'
|
|
export const SHEET = 'sheet-1'
|
|
|
|
export const sb = vi.mocked(supabase)
|
|
export const store = useEditorStore
|
|
|
|
export function baseText(): string {
|
|
return insert(drawnText(), point('anno-a', 50, 50, 5))
|
|
}
|
|
|
|
export function versionAnswer(
|
|
text: string,
|
|
revision: number,
|
|
withDrawing = true,
|
|
) {
|
|
const drawings = withDrawing
|
|
? [{ asset_id: ASSET, sha256: svgBytes().sha256 }]
|
|
: []
|
|
return {
|
|
sheet_id: SHEET,
|
|
version_id: VERSION,
|
|
version_number: 1,
|
|
status: 'draft',
|
|
species_id: 'equine',
|
|
document: JSON.parse(text),
|
|
fingerprint: null,
|
|
revision,
|
|
drawings,
|
|
}
|
|
}
|
|
|
|
export function serverHas(
|
|
text: string,
|
|
revision: number,
|
|
withDrawing = true,
|
|
): void {
|
|
sb.getSheetVersion.mockResolvedValue(
|
|
versionAnswer(text, revision, withDrawing) as never,
|
|
)
|
|
sb.downloadSheetDrawing.mockResolvedValue(svgBytes().bytes)
|
|
}
|
|
|
|
export async function openReady(
|
|
options: { text?: string; revision?: number; canEdit?: boolean } = {},
|
|
): Promise<number> {
|
|
serverHas(options.text ?? baseText(), options.revision ?? 3)
|
|
const token = store
|
|
.getState()
|
|
.open(VERSION, USER, { canEdit: options.canEdit ?? true })
|
|
await vi.waitFor(() => expect(store.getState().status).not.toBe('loading'))
|
|
return token
|
|
}
|
|
|
|
export function resetStore(): void {
|
|
store.getState().close()
|
|
sessionStorage.clear()
|
|
vi.restoreAllMocks()
|
|
vi.resetAllMocks()
|
|
}
|
|
|
|
/** Moves anno-a to (x, 50): a valid, always different, document. */
|
|
export function moveCommand(x: number): EditCommand {
|
|
return {
|
|
op: 'update',
|
|
key: { kind: 'annotation', id: 'anno-a' },
|
|
element: point('anno-a', x, 50, 5),
|
|
}
|
|
}
|
|
|
|
export function commitMove(x: number) {
|
|
return store.getState().commit(moveCommand(x))
|
|
}
|
|
|
|
export const copyKeyOf = (version = VERSION, user = USER) =>
|
|
`osteo:sheet-draft:${user}:${version}`
|
|
|
|
export function storedCopy(version = VERSION, user = USER) {
|
|
const raw = sessionStorage.getItem(copyKeyOf(version, user))
|
|
return raw === null ? null : JSON.parse(raw)
|
|
}
|
|
|
|
/**
|
|
* A mouse press released in place on `el`: the editor's click on the drawing (the press
|
|
* machine decides at the pointer-up; the box has no `click` listener).
|
|
*/
|
|
export function pressAt(el: Element, x = 0, y = 0): void {
|
|
const init = {
|
|
clientX: x,
|
|
clientY: y,
|
|
pointerId: 1,
|
|
isPrimary: true,
|
|
button: 0,
|
|
buttons: 1,
|
|
pointerType: 'mouse',
|
|
}
|
|
fireEvent.pointerDown(el, init)
|
|
fireEvent.pointerUp(el, { ...init, buttons: 0 })
|
|
}
|