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).
134 lines
4.4 KiB
TypeScript
134 lines
4.4 KiB
TypeScript
/** Lot H fix H2: Ctrl+Z and Ctrl+Shift+Z are editor-wide, writable only, not in a dialog. */
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { act, cleanup, fireEvent, screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import {
|
|
baseText,
|
|
commitMove,
|
|
resetStore,
|
|
serverHas,
|
|
store,
|
|
} from '../helpers/editorHarness'
|
|
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
|
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
|
|
|
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(),
|
|
}))
|
|
|
|
beforeEach(() => serverHas(baseText(), 3))
|
|
afterEach(() => {
|
|
cleanup()
|
|
resetStore()
|
|
setWidth(1024)
|
|
})
|
|
|
|
const ready = () =>
|
|
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
|
const cx = () => store.getState().previewState?.document.annotations[0].geometry
|
|
const ctrlZ = (target: Element, shift = false) =>
|
|
fireEvent.keyDown(target, { key: 'z', ctrlKey: true, shiftKey: shift })
|
|
|
|
describe('editor-wide undo', () => {
|
|
it('undoes and redoes from another tab', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await userEvent.setup().click(screen.getByRole('tab', { name: 'Général' }))
|
|
ctrlZ(document.body)
|
|
expect(cx()).toMatchObject({ cx: 50 })
|
|
ctrlZ(document.body, true)
|
|
expect(cx()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
it('does nothing in a text field', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
await userEvent.setup().click(screen.getByRole('tab', { name: 'Général' }))
|
|
ctrlZ(document.querySelector('input') as Element)
|
|
expect(cx()).toMatchObject({ cx: 40 })
|
|
})
|
|
|
|
it('does nothing while a modal dialog is open', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const dialog = document.createElement('dialog')
|
|
dialog.setAttribute('open', '')
|
|
document.body.append(dialog)
|
|
ctrlZ(document.body)
|
|
expect(cx()).toMatchObject({ cx: 40 })
|
|
dialog.remove()
|
|
})
|
|
|
|
it("is off in the narrow read-only mode, with the route's own store state", async () => {
|
|
mountDraft({ width: 1280 })
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
act(() => {
|
|
setWidth(800)
|
|
window.dispatchEvent(new Event('resize'))
|
|
})
|
|
await screen.findByText(/L'édition nécessite une largeur/)
|
|
// The route keeps the store able to hold a recovery copy in `narrow`: no forced flag.
|
|
expect(store.getState().canEdit).toBe(true)
|
|
ctrlZ(document.body)
|
|
expect(cx()).toMatchObject({ cx: 40 })
|
|
expect(store.getState().unsaved).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('undo with something pending (R-13)', () => {
|
|
it('Ctrl+Z only cancels a keyboard series; the next one undoes', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const stored = store.getState().previewState!.document.annotations[0]
|
|
act(() =>
|
|
useAnnotationWork.setState({
|
|
preview: {
|
|
annotationId: stored.id,
|
|
geometry: { type: 'circle', cx: 90, cy: 50, r: 10 },
|
|
base: store.getState().documentText,
|
|
source: 'keys',
|
|
},
|
|
}),
|
|
)
|
|
ctrlZ(document.body)
|
|
expect(useAnnotationWork.getState().preview).toBeNull()
|
|
expect(cx()).toMatchObject({ cx: 40 })
|
|
ctrlZ(document.body)
|
|
expect(cx()).toMatchObject({ cx: 50 })
|
|
})
|
|
|
|
it('the header « Défaire » only cancels a pending size preview', async () => {
|
|
mountDraft()
|
|
await ready()
|
|
act(() => void commitMove(40))
|
|
const stored = store.getState().previewState!.document.annotations[0]
|
|
act(() =>
|
|
useAnnotationWork.setState({
|
|
preview: {
|
|
annotationId: stored.id,
|
|
geometry: { type: 'circle', cx: 40, cy: 50, r: 20 },
|
|
base: store.getState().documentText,
|
|
source: 'size',
|
|
},
|
|
}),
|
|
)
|
|
const user = userEvent.setup()
|
|
await user.click(screen.getByRole('button', { name: /Défaire/ }))
|
|
expect(useAnnotationWork.getState().preview).toBeNull()
|
|
expect(cx()).toMatchObject({ cx: 40 })
|
|
await user.click(screen.getByRole('button', { name: /Défaire/ }))
|
|
expect(cx()).toMatchObject({ cx: 50 })
|
|
})
|
|
})
|