feat(editor): say why redo is unavailable during pending work

This commit is contained in:
bchanot committed 2026-11-19 12:38:26 +01:00
1 parent e341f03390
commit 00e995a6cb
7 files changed
+216 -21

No files matched your search

@@ -14,6 +14,9 @@ import DeleteDialog from '@/components/editor/DeleteDialog'
import { en } from '@/i18n/en'
import { fr } from '@/i18n/fr'
import { useLocaleStore } from '@/state/localeStore'
import { emptyForm } from '@/editor/annotations/creation'
import { traceVertex } from '@/editor/annotations/creationWork'
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
import {
baseText,
commitMove,
@@ -559,3 +562,108 @@ describe('« Abandonner les modifications »', () => {
).toBeNull()
})
})
describe('why a button is held (point 6)', () => {
const CREATION =
"Indisponible pendant une création : créez l'annotation ou abandonnez-la."
const PENDING =
'Refaire attend la fin de la modification en cours : validez-la ou annulez-la.'
const STORED = { type: 'circle' as const, cx: 1, cy: 2, r: 3 }
afterEach(() => act(() => resetWork()))
const line = () => screen.getByTestId('gesture-line')
const reason = (button: HTMLElement) => {
const id = button.getAttribute('aria-describedby')
return id ? document.getElementById(id)?.textContent : null
}
async function openAnnotations() {
const user = userEvent.setup()
mountDraft()
await ready()
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
await screen.findByTestId('gesture-line')
return user
}
const create = () =>
act(() =>
traceVertex(
{
viewId: 'v',
frame: null,
origin: 'tool',
form: emptyForm({ categories: [] } as never),
},
'zone',
[1, 1],
),
)
// A slider change in progress: a size preview on the stored document (I-1).
const pend = () =>
act(() =>
useAnnotationWork.setState({
preview: {
annotationId: 'anno-a',
geometry: { ...STORED, r: 9 },
base: store.getState().documentText,
source: 'size',
},
}),
)
it('a creation describes both buttons and every press says why, once', async () => {
const user = await openAnnotations()
create()
expect(reason(undoButton())).toBe(CREATION)
expect(reason(redoButton())).toBe(CREATION)
expect(disabled(redoButton())).toBe(true)
await user.click(redoButton())
expect(line()).toHaveTextContent(CREATION)
const first = within(line()).getByTestId('gesture-message')
redoButton().focus()
await user.keyboard('{Enter}')
expect(line()).toHaveTextContent(CREATION)
expect(within(line()).getByTestId('gesture-message')).not.toBe(first)
await user.keyboard(' ')
expect(within(line()).getAllByTestId('gesture-message')).toHaveLength(1)
undoButton().focus()
await user.keyboard('{Enter}')
expect(line()).toHaveTextContent(CREATION)
})
it('pending work holds redo only, with its own reason', async () => {
const user = await openAnnotations()
pend()
expect(reason(redoButton())).toBe(PENDING)
expect(reason(undoButton())).toBeNull()
await user.click(redoButton())
expect(line()).toHaveTextContent(PENDING)
})
it('say it in English', async () => {
const user = await openAnnotations()
act(() => useLocaleStore.setState({ locale: 'en' }))
create()
const redo = screen.getByRole('button', {
name: 'Redo the last undone change',
})
expect(reason(redo)).toBe(
'Unavailable during a creation: create the annotation or discard it.',
)
await user.click(redo)
expect(line()).toHaveTextContent('Unavailable during a creation')
})
it('give no reason when nothing is pending, nothing to redo or read-only', async () => {
const user = await openAnnotations()
expect(reason(redoButton())).toBeNull()
await user.click(redoButton())
expect(within(line()).queryByTestId('gesture-message')).toBeNull()
cleanup()
resetStore()
serverHas(baseText(), 3)
mountDraft({ width: 800 })
await ready()
await user.click(undoButton())
expect(reason(undoButton())).toBeNull()
expect(reason(redoButton())).toBeNull()
})
})