fix(editor): keyboard refused-commit rule, missing history tests

Keyboard activation after a refused blur commit skips the undo and refocuses the field. Adds restore, Général-from-Annotations and DeleteDialog tests; SaveLine helpers.
This commit is contained in:
bchanot committed 2026-11-08 18:09:10 +01:00
1 parent 99b669bf8f
commit 89da8d3f55
4 files changed
+133 -35

No files matched your search

@@ -4,11 +4,13 @@ import {
act,
cleanup,
fireEvent,
render,
screen,
waitFor,
within,
} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import DeleteDialog from '@/components/editor/DeleteDialog'
import { fr } from '@/i18n/fr'
import {
baseText,
@@ -175,6 +177,24 @@ describe('the buttons', () => {
expect(geometry()).toMatchObject({ cx: 50 })
})
it('undo from Annotations reverts a Général change', async () => {
const user = userEvent.setup()
mountDraft()
await ready()
const original = store.getState().previewState?.document.name?.fr
await user.click(screen.getByRole('tab', { name: 'Général' }))
const place = document.querySelector(
'[data-place="general"]',
) as HTMLElement
const field = within(place).getByLabelText('Nom (FR)')
await user.clear(field)
await user.type(field, 'Renommée')
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
expect(store.getState().previewState?.document.name?.fr).toBe('Renommée')
await user.click(undoButton())
expect(store.getState().previewState?.document.name?.fr).toBe(original)
})
it('leave no undo or redo pair in the tool column', async () => {
mountDraft()
await ready()
@@ -232,6 +252,38 @@ describe('typed text and the press', () => {
expect(geometry()).toMatchObject({ cx: 40 })
})
it('a keyboard activation after a refused blur commit skips the undo too', async () => {
const user = userEvent.setup()
mountDraft()
await ready()
act(() => void commitMove(40))
const field = await selectAnnotation(user)
await user.clear(field)
field.blur()
act(() => undoButton().focus())
fireEvent.focus(undoButton(), { relatedTarget: field })
await user.keyboard('{Enter}')
expect(field).toHaveAttribute('aria-invalid', 'true')
expect(field).toHaveFocus()
expect(geometry()).toMatchObject({ cx: 40 })
expect(store.getState().undo).toHaveLength(1)
})
it('Ctrl+Z is ignored while a DeleteDialog is open', async () => {
mountDraft()
await ready()
act(() => void commitMove(40))
render(
<DeleteDialog
target={{ key: { kind: 'annotation', id: 'anno-a' }, label: 'N' }}
onClose={vi.fn()}
/>,
)
await screen.findByRole('dialog')
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
expect(geometry()).toMatchObject({ cx: 40 })
})
it('Ctrl+Z inside a field leaves the store untouched', async () => {
mountDraft()
await ready()