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:
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()
|
||||
|
||||
@@ -13,8 +13,12 @@ import {
|
||||
import saveLineSource from '@/editor/saveLine.ts?raw'
|
||||
import saveSource from '@/editor/state/editorSave.ts?raw'
|
||||
import {
|
||||
SHEET,
|
||||
USER,
|
||||
VERSION,
|
||||
baseText,
|
||||
commitMove,
|
||||
copyKeyOf,
|
||||
openReady,
|
||||
resetStore,
|
||||
sb,
|
||||
@@ -97,6 +101,21 @@ describe('savedDistance', () => {
|
||||
expect(distance()).toBeNull()
|
||||
})
|
||||
|
||||
it('is null after a restored recovery copy', async () => {
|
||||
const copy = JSON.parse(baseText(), (key, value) => (key === 'cx' ? 10 : value))
|
||||
sessionStorage.setItem(
|
||||
copyKeyOf(),
|
||||
JSON.stringify({
|
||||
v: 1, user_id: USER, version_id: VERSION, sheet_id: SHEET, sheet_name: 'Fiche',
|
||||
revision: 3, written_at: '2026-11-03T10:00:00Z', document: copy, drawings: [],
|
||||
}),
|
||||
)
|
||||
await openReady({ revision: 3 })
|
||||
expect(await store.getState().restoreCopy()).toEqual({ ok: true })
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
expect(distance()).toBeNull()
|
||||
})
|
||||
|
||||
it('is null for a stale base', async () => {
|
||||
await openReady({ revision: 3 })
|
||||
commitMove(40)
|
||||
|
||||
Reference in new issue
Block a user