feat(editor): point handle, size slider with core minimum, move mode
HandleLayer: its own svg over the overlay, not aria-hidden; the selected
point (or link circle) gets a focusable « Point {nom} » handle whose hit
circle (data-handle) the press machine reads, sized in CSS px under zoom
(R-9, read once from any-pointer: coarse). The Task 2 stand-in (the
selected marker as its own handle) is removed.
Keys on the handle: arrows step 0.5 % of the frame (Shift x10) as a
stamped series, Enter or blur commit once, Escape drops it (R-11, R-13).
SizeSlider in the strip for a selected point and for the Point tool (A5):
the view's sizes as ticks, the core minimum as a red mark, snap 8 px,
arrows 1 %, Page Up/Down next size, one commit on release, Enter or blur;
a refusal restores the size and draws the refused place in red dashes.
« Déplacer le point » opens the move mode (board 06 B): drag anywhere or
four arrows move a preview only, clicks select nothing, « Valider la
position » commits once, « Annuler » and Escape restore; the focus comes
back to the button. Escape follows board 32 (escapeAction). The overlay
reads the preview from the work store and draws the old place in grey
dashes. Ctrl+Z now also works from a slider (not a text field).
Rewritten assertions:
- editor-annotations-tab « a finger drags the selected point »:
drag(marker('anno-a')) -> drag(pointHandle()), same expected geometry.
- editor-geometry.spec « a point inherited out of its frame is repaired
through the geometry group » (cx/cy typed 200) -> « ... repaired with
the move mode »: a partial move refused and restored (cx 110, issue
kept), then a move inside kept (issue gone, fewer errors).
This commit is contained in:
1 parent
2882821661
commit
91e94952f0
23 files changed
+1679
-149
No files matched your search
@@ -0,0 +1,437 @@
|
||||
/** U2 Task 4: the point handle, the size slider and the move mode in the Annotations tab. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||
import {
|
||||
ASSET,
|
||||
drawnText,
|
||||
insert,
|
||||
point,
|
||||
svgBytes,
|
||||
} from '../helpers/editorFixtures'
|
||||
import {
|
||||
USER,
|
||||
VERSION,
|
||||
openReady,
|
||||
resetStore,
|
||||
sb,
|
||||
store,
|
||||
versionAnswer,
|
||||
} 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(),
|
||||
}
|
||||
|
||||
function UndoKeys() {
|
||||
useUndoShortcuts(true)
|
||||
return null
|
||||
}
|
||||
|
||||
const annotations = () => store.getState().previewState!.document.annotations
|
||||
const geometryOf = (id: string) =>
|
||||
annotations().find((a: Annotation) => a.id === id)?.geometry
|
||||
const depth = () => store.getState().undo.length
|
||||
|
||||
/** A change made elsewhere: the other point `b` moved through the store. */
|
||||
const moveOther = () =>
|
||||
store.getState().commit({
|
||||
op: 'update',
|
||||
key: { kind: 'annotation', id: 'b' },
|
||||
element: point('b', 30, 30, 5),
|
||||
})
|
||||
|
||||
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 withPoints = (...points: ReturnType<typeof point>[]) =>
|
||||
points.reduce((text, p) => insert(text, p), drawnText())
|
||||
|
||||
async function mount(text: string) {
|
||||
await openReady({ text })
|
||||
// The Escape listener acts inside the editor workspace only.
|
||||
render(
|
||||
<div data-editor-workspace>
|
||||
<AnnotationsTab {...props} />
|
||||
</div>,
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||||
).not.toBeNull(),
|
||||
)
|
||||
}
|
||||
|
||||
/** The same tab on a 4000 × 3000 drawing: the core gives the main view a minimum radius. */
|
||||
async function mountLarge(text: string) {
|
||||
const drawing = svgBytes('0 0 4000 3000')
|
||||
sb.getSheetVersion.mockResolvedValue({
|
||||
...versionAnswer(text, 3),
|
||||
drawings: [{ asset_id: ASSET, sha256: drawing.sha256 }],
|
||||
} as never)
|
||||
sb.downloadSheetDrawing.mockResolvedValue(drawing.bytes)
|
||||
store.getState().open(VERSION, USER, { canEdit: true })
|
||||
await waitFor(() => expect(store.getState().status).toBe('ready'))
|
||||
// The Escape listener acts inside the editor workspace only.
|
||||
render(
|
||||
<div data-editor-workspace>
|
||||
<AnnotationsTab {...props} />
|
||||
</div>,
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||||
).not.toBeNull(),
|
||||
)
|
||||
}
|
||||
|
||||
async function select(index = 0) {
|
||||
const list = await screen.findByRole('list', {
|
||||
name: 'Annotations de la vue',
|
||||
})
|
||||
await userEvent.setup().click(within(list).getAllByRole('button')[index])
|
||||
return screen.findByTestId('annotation-properties')
|
||||
}
|
||||
|
||||
const slider = () =>
|
||||
within(screen.getByTestId('size-slider')).getByRole('slider')
|
||||
const handle = () => screen.getByRole('button', { name: 'Point N' })
|
||||
const message = () => screen.getByTestId('gesture-line')
|
||||
const moveButton = () =>
|
||||
screen.getByRole('button', { name: 'Déplacer le point' })
|
||||
const bar = () => screen.getByTestId('move-mode-bar')
|
||||
const arrow = (name: string) =>
|
||||
within(bar()).getByRole('button', { name: `Déplacer vers ${name}` })
|
||||
|
||||
describe('the size slider (R-10)', () => {
|
||||
it('shows the view stops and the red mark at the core value', async () => {
|
||||
await mountLarge(
|
||||
withPoints(
|
||||
point('a', 500, 500, 30),
|
||||
point('b', 900, 500, 34),
|
||||
point('c', 1500, 500, 34),
|
||||
),
|
||||
)
|
||||
await select()
|
||||
const minimum = store.getState().previewState!.min_point_radius['view-main']
|
||||
expect(minimum).toBeGreaterThan(0)
|
||||
expect(screen.getAllByTestId('size-stop')).toHaveLength(2)
|
||||
expect(screen.getByTestId('size-minimum')).toHaveAttribute(
|
||||
'data-value',
|
||||
String(minimum),
|
||||
)
|
||||
const low = Math.round((Math.min(30, minimum) / 2) * 100) / 100
|
||||
expect(slider()).toHaveAttribute('min', String(low))
|
||||
expect(slider()).toHaveAttribute('max', '68')
|
||||
})
|
||||
|
||||
it('has no red mark where the core gives no minimum', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5)))
|
||||
await select()
|
||||
expect(screen.queryByTestId('size-minimum')).toBeNull()
|
||||
})
|
||||
|
||||
it('arrows and Page Up preview only; leaving the slider commits once', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5), point('b', 20, 20, 8)))
|
||||
await select()
|
||||
const before = depth()
|
||||
fireEvent.keyDown(slider(), { key: 'ArrowRight' })
|
||||
fireEvent.keyDown(slider(), { key: 'ArrowRight' })
|
||||
expect(geometryOf('a')).toMatchObject({ r: 5 })
|
||||
fireEvent.keyDown(slider(), { key: 'PageUp' })
|
||||
expect(slider()).toHaveValue('8')
|
||||
expect(depth()).toBe(before)
|
||||
fireEvent.blur(slider())
|
||||
expect(geometryOf('a')).toMatchObject({ r: 8 })
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(message()).toHaveTextContent('Taille modifiée')
|
||||
})
|
||||
|
||||
it('a track click commits once at the release (WCAG 2.5.7)', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5)))
|
||||
await select()
|
||||
const before = depth()
|
||||
fireEvent.change(slider(), { target: { value: '7' } })
|
||||
expect(geometryOf('a')).toMatchObject({ r: 5 })
|
||||
fireEvent.pointerUp(slider())
|
||||
fireEvent.blur(slider())
|
||||
expect(geometryOf('a')).toMatchObject({ r: 7 })
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('Ctrl+Z on the slider cancels its preview, then undoes (R-13)', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5)))
|
||||
render(<UndoKeys />)
|
||||
await select()
|
||||
fireEvent.change(slider(), { target: { value: '7' } })
|
||||
fireEvent.keyDown(slider(), { key: 'z', ctrlKey: true })
|
||||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||||
expect(slider()).toHaveValue('5')
|
||||
fireEvent.change(slider(), { target: { value: '7' } })
|
||||
fireEvent.pointerUp(slider())
|
||||
expect(geometryOf('a')).toMatchObject({ r: 7 })
|
||||
fireEvent.keyDown(slider(), { key: 'z', ctrlKey: true })
|
||||
expect(geometryOf('a')).toMatchObject({ r: 5 })
|
||||
})
|
||||
|
||||
it('a value under the mark is refused by the core and restored in red', async () => {
|
||||
await mountLarge(withPoints(point('a', 500, 500, 30)))
|
||||
await select()
|
||||
const before = depth()
|
||||
fireEvent.change(slider(), { target: { value: '8' } })
|
||||
fireEvent.pointerUp(slider())
|
||||
expect(geometryOf('a')).toMatchObject({ r: 30 })
|
||||
expect(depth()).toBe(before)
|
||||
expect(slider()).toHaveValue('30')
|
||||
expect(within(message()).getByRole('alert')).toHaveTextContent(
|
||||
'Taille refusée',
|
||||
)
|
||||
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the move mode (A11, R-12, R-13)', () => {
|
||||
const two = () => withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5))
|
||||
|
||||
it('its arrows commit nothing until « Valider la position », which commits once', async () => {
|
||||
await mount(two())
|
||||
await select()
|
||||
const before = depth()
|
||||
await userEvent.setup().click(moveButton())
|
||||
expect(document.activeElement).toBe(arrow('la gauche'))
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||
'Déplacer le point',
|
||||
)
|
||||
fireEvent.click(arrow('la droite'))
|
||||
fireEvent.click(arrow('la droite'))
|
||||
fireEvent.click(arrow('le bas'))
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50, cy: 50 })
|
||||
expect(screen.getByTestId('overlay-old-place')).toBeInTheDocument()
|
||||
expect(depth()).toBe(before)
|
||||
fireEvent.click(
|
||||
within(bar()).getByRole('button', { name: 'Valider la position' }),
|
||||
)
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 51, cy: 50.5 })
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(message()).toHaveTextContent('Point déplacé')
|
||||
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
|
||||
})
|
||||
|
||||
it('« Annuler » restores the place, the focus back on « Déplacer le point »', async () => {
|
||||
await mount(two())
|
||||
await select()
|
||||
await userEvent.setup().click(moveButton())
|
||||
fireEvent.click(arrow('la droite'))
|
||||
fireEvent.click(within(bar()).getByRole('button', { name: 'Annuler' }))
|
||||
expect(useAnnotationWork.getState()).toMatchObject({
|
||||
mode: null,
|
||||
preview: null,
|
||||
})
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||||
await waitFor(() => expect(document.activeElement).toBe(moveButton()))
|
||||
})
|
||||
|
||||
it('Escape restores the place', async () => {
|
||||
await mount(two())
|
||||
await select()
|
||||
await userEvent.setup().click(moveButton())
|
||||
fireEvent.click(arrow('la droite'))
|
||||
fireEvent.keyDown(arrow('la droite'), { key: 'Escape' })
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
|
||||
expect(screen.getByTestId('annotation-properties')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a click on another annotation selects nothing during the mode', async () => {
|
||||
await mount(two())
|
||||
await select()
|
||||
await userEvent.setup().click(moveButton())
|
||||
const other = screen
|
||||
.getByTestId('annotation-canvas-drawing')
|
||||
.querySelector('[data-anno-id="b"]')!
|
||||
const init = {
|
||||
pointerId: 1,
|
||||
isPrimary: true,
|
||||
button: 0,
|
||||
buttons: 1,
|
||||
pointerType: 'mouse',
|
||||
}
|
||||
fireEvent.pointerDown(other, { ...init, clientX: 20, clientY: 20 })
|
||||
fireEvent.pointerUp(other, { ...init, clientX: 20, clientY: 20 })
|
||||
expect(useAnnotationWork.getState().mode?.annotationId).toBe('a')
|
||||
expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a drag anywhere moves the mode preview and commits nothing', async () => {
|
||||
await mount(two())
|
||||
await select()
|
||||
await userEvent.setup().click(moveButton())
|
||||
const box = screen.getByTestId('annotation-canvas')
|
||||
const init = {
|
||||
pointerId: 1,
|
||||
isPrimary: true,
|
||||
button: 0,
|
||||
buttons: 1,
|
||||
pointerType: 'touch',
|
||||
}
|
||||
fireEvent.pointerDown(box, { ...init, clientX: 80, clientY: 80 })
|
||||
fireEvent.pointerMove(box, { ...init, clientX: 92, clientY: 80 })
|
||||
fireEvent.pointerUp(box, { ...init, clientX: 92, clientY: 80 })
|
||||
expect(useAnnotationWork.getState().preview?.geometry).toMatchObject({
|
||||
cx: 62,
|
||||
})
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
})
|
||||
|
||||
it('Ctrl+Z only cancels it; a later Enter on the handle commits nothing', async () => {
|
||||
await mount(two())
|
||||
render(<UndoKeys />)
|
||||
await select()
|
||||
await userEvent.setup().click(moveButton())
|
||||
fireEvent.click(arrow('la droite'))
|
||||
const before = depth()
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
expect(useAnnotationWork.getState()).toMatchObject({
|
||||
mode: null,
|
||||
preview: null,
|
||||
})
|
||||
expect(depth()).toBe(before)
|
||||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||||
expect(depth()).toBe(before)
|
||||
})
|
||||
|
||||
it('a document change during the mode drops it and says so', async () => {
|
||||
await mount(two())
|
||||
await select()
|
||||
await userEvent.setup().click(moveButton())
|
||||
fireEvent.click(arrow('la droite'))
|
||||
act(() => void moveOther())
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(
|
||||
await screen.findByText('Déplacement abandonné : la fiche a changé.'),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the point handle (R-9, R-11)', () => {
|
||||
it('is a focusable button outside any aria-hidden subtree, named « Point {nom} »', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5)))
|
||||
await select()
|
||||
expect(handle()).toHaveAttribute('tabindex', '0')
|
||||
expect(handle().closest('[aria-hidden="true"]')).toBeNull()
|
||||
})
|
||||
|
||||
it('arrows move a preview only (no pan), Enter commits once; Shift ×10', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5)))
|
||||
await select()
|
||||
const before = depth()
|
||||
const transform = () =>
|
||||
(screen.getByTestId('annotation-canvas').firstElementChild as HTMLElement)
|
||||
.style.transform
|
||||
const panned = transform()
|
||||
handle().focus()
|
||||
fireEvent.keyDown(handle(), { key: 'ArrowRight' })
|
||||
fireEvent.keyDown(handle(), { key: 'ArrowDown', shiftKey: true })
|
||||
expect(transform()).toBe(panned)
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50, cy: 50 })
|
||||
expect(depth()).toBe(before)
|
||||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50.5, cy: 55 })
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('leaving the handle commits the series (BDR-050); Escape drops it', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5)))
|
||||
await select()
|
||||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||||
fireEvent.keyDown(handle(), { key: 'Escape' })
|
||||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||||
fireEvent.blur(handle())
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||||
fireEvent.blur(handle())
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 49.5 })
|
||||
})
|
||||
|
||||
it('a stale series never commits (R-13)', async () => {
|
||||
await mount(withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5)))
|
||||
await select()
|
||||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||||
act(() => void moveOther())
|
||||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('A5: a new point takes the most used size', () => {
|
||||
const sized = () =>
|
||||
withPoints(
|
||||
point('a', 20, 20, 7),
|
||||
point('b', 40, 40, 7),
|
||||
point('c', 60, 60, 9),
|
||||
)
|
||||
|
||||
it('the keyboard point and the Point tool click', async () => {
|
||||
await mount(sized())
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('7')
|
||||
})
|
||||
|
||||
it('the Point tool shows the slider at that size; a new size feeds the click', async () => {
|
||||
await mount(sized())
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
expect(slider()).toHaveValue('7')
|
||||
fireEvent.change(slider(), { target: { value: '9' } })
|
||||
expect(slider()).toHaveValue('9')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user