fix(editor): redo and move-mode handle keys keep pending work
Final review I-1. Redo (Ctrl+Shift+Z and the header « Refaire ») is inactive while a started move or redraw, a keyboard series or a size change is pending (holdsRedo): the work stays, the user commits or cancels it first. In a move mode, Insert and Delete on a vertex and Enter or Space on « + » and « − » do nothing, as the press machine. Tests: no assertion removed. The history-guards move-mode helper and reset run in act, since « Refaire » now re-renders on a started mode.
This commit is contained in:
1 parent
c6b8c7e48a
commit
ae80511964
7 files changed
+211
-12
No files matched your search
@@ -395,12 +395,14 @@ describe('final review: queued landings (M-6)', () => {
|
||||
|
||||
describe('the drawing guard (R-12): a move mode and the navigations', () => {
|
||||
const STORED = { type: 'circle' as const, cx: 1, cy: 2, r: 3 }
|
||||
afterEach(resetWork)
|
||||
afterEach(() => act(() => resetWork()))
|
||||
const tabShown = () => screen.getByRole('tab', { selected: true })
|
||||
const started = () => {
|
||||
startMove('a', 'doc')
|
||||
setModePreview({ ...STORED, cx: 9 }, STORED)
|
||||
}
|
||||
// In act: « Refaire » now follows a started mode (final review I-1) and re-renders.
|
||||
const started = () =>
|
||||
act(() => {
|
||||
startMove('a', 'doc')
|
||||
setModePreview({ ...STORED, cx: 9 }, STORED)
|
||||
})
|
||||
|
||||
it('with no step taken, a tab ends the mode at once, without a question', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
|
||||
@@ -131,3 +131,57 @@ describe('undo with something pending (R-13)', () => {
|
||||
expect(cx()).toMatchObject({ cx: 50 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('redo with something pending (final review I-1)', () => {
|
||||
const REDO = 'Refaire la dernière modification défaite'
|
||||
/** A commit undone: the redo stack holds it, the shape is back at cx 50. */
|
||||
async function undone() {
|
||||
mountDraft()
|
||||
await ready()
|
||||
act(() => void commitMove(40))
|
||||
ctrlZ(document.body)
|
||||
expect(cx()).toMatchObject({ cx: 50 })
|
||||
}
|
||||
const pend = (source: 'keys' | 'size') => {
|
||||
const stored = store.getState().previewState!.document.annotations[0]
|
||||
act(() =>
|
||||
useAnnotationWork.setState({
|
||||
preview: {
|
||||
annotationId: stored.id,
|
||||
geometry: { type: 'circle', cx: 60, cy: 50, r: 10 },
|
||||
base: store.getState().documentText,
|
||||
source,
|
||||
},
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
it('Ctrl+Shift+Z keeps a pending size change and redoes nothing', async () => {
|
||||
await undone()
|
||||
pend('size')
|
||||
ctrlZ(document.body, true)
|
||||
expect(useAnnotationWork.getState().preview?.source).toBe('size')
|
||||
expect(cx()).toMatchObject({ cx: 50 })
|
||||
})
|
||||
|
||||
it('the header « Refaire » is off and keeps a keyboard series', async () => {
|
||||
await undone()
|
||||
pend('keys')
|
||||
const redo = screen.getByRole('button', { name: REDO })
|
||||
// A click that leaves the focus in place (Safari does not focus a clicked button).
|
||||
fireEvent.click(redo)
|
||||
expect(useAnnotationWork.getState().preview?.source).toBe('keys')
|
||||
expect(cx()).toMatchObject({ cx: 50 })
|
||||
expect(redo).toHaveAttribute('aria-disabled', 'true')
|
||||
})
|
||||
|
||||
it('once the work is gone, redo works again', async () => {
|
||||
await undone()
|
||||
pend('keys')
|
||||
act(() => useAnnotationWork.setState({ preview: null }))
|
||||
const redo = screen.getByRole('button', { name: REDO })
|
||||
expect(redo).toHaveAttribute('aria-disabled', 'false')
|
||||
fireEvent.click(redo)
|
||||
expect(cx()).toMatchObject({ cx: 40 })
|
||||
})
|
||||
})
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation, Point } from '@faunosteo/core-wasm/types'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import HistoryButtons from '@/components/editor/HistoryButtons'
|
||||
import { answerDrawing, guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
|
||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||
@@ -892,3 +893,115 @@ describe('M-5: « Fermeture refusée » titles a refused close only', () => {
|
||||
expect(lead.title).toBe('Fermeture refusée')
|
||||
})
|
||||
})
|
||||
|
||||
describe('final review I-1: a redo or a handle key never drops pending work', () => {
|
||||
const redoKey = (target: Element) =>
|
||||
fireEvent.keyDown(target, { key: 'z', ctrlKey: true, shiftKey: true })
|
||||
const canvas = () => screen.getByTestId('annotation-canvas')
|
||||
const ABANDONED = /abandonné : la fiche a changé/
|
||||
|
||||
/** One committed step on vertex 1, undone: the redo stack holds it. */
|
||||
async function withRedo() {
|
||||
await mount(squareText())
|
||||
render(<UndoKeys />)
|
||||
await select()
|
||||
act(() => vertex(1).focus())
|
||||
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
|
||||
fireEvent.keyDown(vertex(1), { key: 'Enter' })
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(store.getState().redo).toHaveLength(1)
|
||||
}
|
||||
|
||||
async function startedMove(name = 'Déplacer la zone') {
|
||||
await userEvent.setup().click(screen.getByRole('button', { name }))
|
||||
const bar = screen.getByTestId('move-mode-bar')
|
||||
fireEvent.click(
|
||||
within(bar).getByRole('button', { name: 'Déplacer vers la droite' }),
|
||||
)
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
}
|
||||
|
||||
it('Ctrl+Shift+Z on a vertex keyed with arrows keeps the series; Enter commits it', async () => {
|
||||
await withRedo()
|
||||
fireEvent.keyDown(vertex(1), { key: 'ArrowDown' })
|
||||
redoKey(vertex(1))
|
||||
expect(useAnnotationWork.getState().preview?.source).toBe('keys')
|
||||
expect(store.getState().redo).toHaveLength(1)
|
||||
fireEvent.keyDown(vertex(1), { key: 'Enter' })
|
||||
expect(pointsOf('z')![0]).toEqual([20, 20.5])
|
||||
})
|
||||
|
||||
it('Ctrl+Shift+Z in a started move keeps the move, said by nothing', async () => {
|
||||
await withRedo()
|
||||
await startedMove()
|
||||
redoKey(document.body)
|
||||
expect(useAnnotationWork.getState().mode).toMatchObject({
|
||||
kind: 'move',
|
||||
started: true,
|
||||
})
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(screen.queryByText(ABANDONED)).toBeNull()
|
||||
})
|
||||
|
||||
it('the header « Refaire » is off in a started move and keeps it', async () => {
|
||||
await withRedo()
|
||||
render(<HistoryButtons />)
|
||||
await startedMove()
|
||||
const redo = screen.getByRole('button', {
|
||||
name: 'Refaire la dernière modification défaite',
|
||||
})
|
||||
// A click that leaves the focus in place (Safari does not focus a clicked button).
|
||||
fireEvent.click(redo)
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
expect(store.getState().redo).toHaveLength(1)
|
||||
expect(screen.queryByText(ABANDONED)).toBeNull()
|
||||
expect(redo).toHaveAttribute('aria-disabled', 'true')
|
||||
})
|
||||
|
||||
it('Ctrl+Shift+Z in a started redraw keeps the trace', async () => {
|
||||
await withRedo()
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Redessiner' }))
|
||||
pressAt(canvas(), 30, 30)
|
||||
redoKey(canvas())
|
||||
expect(useAnnotationWork.getState().mode).toMatchObject({
|
||||
kind: 'redraw',
|
||||
started: true,
|
||||
})
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Fermer le tracé' }),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText(ABANDONED)).toBeNull()
|
||||
})
|
||||
|
||||
it('in a started zone move, Enter or Space on « + » and Insert change nothing', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
await startedMove()
|
||||
const before = depth()
|
||||
fireEvent.keyDown(plus(1), { key: 'Enter' })
|
||||
fireEvent.keyDown(plus(4), { key: ' ' })
|
||||
fireEvent.keyDown(vertex(1), { key: 'Insert' })
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(depth()).toBe(before)
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
expect(screen.queryByText(ABANDONED)).toBeNull()
|
||||
})
|
||||
|
||||
it('in a started vertex move, Enter on « − », Insert and Delete change nothing', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
clickHandle('Sommet 3', [80, 80])
|
||||
await startedMove('Déplacer le sommet')
|
||||
const before = depth()
|
||||
fireEvent.keyDown(minus(3), { key: 'Enter' })
|
||||
fireEvent.keyDown(vertex(3), { key: 'Insert' })
|
||||
fireEvent.keyDown(vertex(3), { key: 'Delete' })
|
||||
fireEvent.keyDown(plus(2), { key: 'Enter' })
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(depth()).toBe(before)
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
expect(screen.queryByText(ABANDONED)).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user