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
@@ -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