fix(editor): « Défaire » cancels pending work; reasons only when they help
A press on « Défaire » over a pending series or mode keeps the focus and skips the field commit, so its handle's blur no longer commits before the cancel (R-13): the redo stack survives. A held button gives its reason only when that cause alone holds it; redo during a creation gets its own text, and the pending text says to cancel with « Défaire ».
This commit is contained in:
1 parent
de418b29a9
commit
59e189c375
6 files changed
+184
-40
No files matched your search
@@ -566,8 +566,10 @@ describe('« Abandonner les modifications »', () => {
|
||||
describe('why a button is held (point 6)', () => {
|
||||
const CREATION =
|
||||
"Indisponible pendant une création : créez l'annotation ou abandonnez-la."
|
||||
const REDO_CREATION =
|
||||
'Refaire est suspendu pendant une création : abandonnez-la pour pouvoir refaire.'
|
||||
const PENDING =
|
||||
'Refaire attend la fin de la modification en cours : validez-la ou annulez-la.'
|
||||
'Refaire est suspendu pendant la modification en cours : annulez-la avec Défaire pour pouvoir refaire.'
|
||||
const STORED = { type: 'circle' as const, cx: 1, cy: 2, r: 3 }
|
||||
afterEach(() => act(() => resetWork()))
|
||||
const line = () => screen.getByTestId('gesture-line')
|
||||
@@ -575,6 +577,8 @@ describe('why a button is held (point 6)', () => {
|
||||
const id = button.getAttribute('aria-describedby')
|
||||
return id ? document.getElementById(id)?.textContent : null
|
||||
}
|
||||
const noMessage = () =>
|
||||
expect(within(line()).queryByTestId('gesture-message')).toBeNull()
|
||||
async function openAnnotations() {
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
@@ -583,6 +587,14 @@ describe('why a button is held (point 6)', () => {
|
||||
await screen.findByTestId('gesture-line')
|
||||
return user
|
||||
}
|
||||
// Something to undo and to redo: a reason shows only when its cause alone holds the button.
|
||||
const stacks = () =>
|
||||
act(() =>
|
||||
store.setState({
|
||||
undo: [{ text: baseText(), bytes: 1 }],
|
||||
redo: [{ text: baseText(), bytes: 1 }],
|
||||
}),
|
||||
)
|
||||
const create = () =>
|
||||
act(() =>
|
||||
traceVertex(
|
||||
@@ -608,19 +620,30 @@ describe('why a button is held (point 6)', () => {
|
||||
},
|
||||
}),
|
||||
)
|
||||
// A handle's blur commits its series (here: ends the preview), as the real one does.
|
||||
function focusedHandle() {
|
||||
const handle = document.createElement('button')
|
||||
handle.addEventListener('blur', () =>
|
||||
useAnnotationWork.setState({ preview: null }),
|
||||
)
|
||||
document.body.append(handle)
|
||||
handle.focus()
|
||||
return handle
|
||||
}
|
||||
|
||||
it('a creation describes both buttons and every press says why, once', async () => {
|
||||
it('a creation describes each button with its own reason and every press says why, once', async () => {
|
||||
const user = await openAnnotations()
|
||||
stacks()
|
||||
create()
|
||||
expect(reason(undoButton())).toBe(CREATION)
|
||||
expect(reason(redoButton())).toBe(CREATION)
|
||||
expect(reason(redoButton())).toBe(REDO_CREATION)
|
||||
expect(disabled(redoButton())).toBe(true)
|
||||
await user.click(redoButton())
|
||||
expect(line()).toHaveTextContent(CREATION)
|
||||
expect(line()).toHaveTextContent(REDO_CREATION)
|
||||
const first = within(line()).getByTestId('gesture-message')
|
||||
redoButton().focus()
|
||||
await user.keyboard('{Enter}')
|
||||
expect(line()).toHaveTextContent(CREATION)
|
||||
expect(line()).toHaveTextContent(REDO_CREATION)
|
||||
expect(within(line()).getByTestId('gesture-message')).not.toBe(first)
|
||||
await user.keyboard(' ')
|
||||
expect(within(line()).getAllByTestId('gesture-message')).toHaveLength(1)
|
||||
@@ -631,6 +654,7 @@ describe('why a button is held (point 6)', () => {
|
||||
|
||||
it('pending work holds redo only, with its own reason', async () => {
|
||||
const user = await openAnnotations()
|
||||
stacks()
|
||||
pend()
|
||||
expect(reason(redoButton())).toBe(PENDING)
|
||||
expect(reason(undoButton())).toBeNull()
|
||||
@@ -641,13 +665,7 @@ describe('why a button is held (point 6)', () => {
|
||||
it('a mouse press on a held « Refaire » leaves the focused pending work alone', async () => {
|
||||
const user = await openAnnotations()
|
||||
pend()
|
||||
// A handle's blur commits its series (here: ends the preview), as the real one does.
|
||||
const handle = document.createElement('button')
|
||||
handle.addEventListener('blur', () =>
|
||||
useAnnotationWork.setState({ preview: null }),
|
||||
)
|
||||
document.body.append(handle)
|
||||
handle.focus()
|
||||
const handle = focusedHandle()
|
||||
store.setState({ redo: [{ text: baseText(), bytes: 1 }] })
|
||||
await user.pointer([
|
||||
{ keys: '[MouseLeft>]', target: redoButton() },
|
||||
@@ -660,8 +678,58 @@ describe('why a button is held (point 6)', () => {
|
||||
handle.remove()
|
||||
})
|
||||
|
||||
for (const [kind, keys] of [
|
||||
['mouse', '[MouseLeft]'],
|
||||
['touch', '[TouchA]'],
|
||||
] as const) {
|
||||
it(`a ${kind} press on « Défaire » during pending work only cancels it: focus and redo stay`, async () => {
|
||||
const user = await openAnnotations()
|
||||
stacks()
|
||||
pend()
|
||||
let committed = false
|
||||
const handle = focusedHandle()
|
||||
handle.addEventListener('blur', () => {
|
||||
committed = true
|
||||
})
|
||||
await user.pointer({ keys, target: undoButton() })
|
||||
expect(committed).toBe(false)
|
||||
expect(handle).toHaveFocus()
|
||||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||||
expect(store.getState().undo).toHaveLength(1)
|
||||
expect(store.getState().redo).toHaveLength(1)
|
||||
handle.remove()
|
||||
})
|
||||
}
|
||||
|
||||
it('with nothing to redo, pending work gives « Refaire » no reason and a press commits it', async () => {
|
||||
const user = await openAnnotations()
|
||||
pend()
|
||||
expect(reason(redoButton())).toBeNull()
|
||||
expect(disabled(redoButton())).toBe(true)
|
||||
const handle = focusedHandle()
|
||||
await user.click(redoButton())
|
||||
expect(handle).not.toHaveFocus()
|
||||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||||
noMessage()
|
||||
handle.remove()
|
||||
})
|
||||
|
||||
it('a creation with nothing to undo or redo gives no reason, and a press says nothing', async () => {
|
||||
const user = await openAnnotations()
|
||||
create()
|
||||
expect(reason(undoButton())).toBeNull()
|
||||
expect(reason(redoButton())).toBeNull()
|
||||
await user.click(redoButton())
|
||||
await user.click(undoButton())
|
||||
undoButton().focus()
|
||||
await user.keyboard('{Enter}')
|
||||
noMessage()
|
||||
expect(useAnnotationWork.getState().creation).not.toBeNull()
|
||||
})
|
||||
|
||||
it('Space on a held « Défaire » and Enter on a pending « Refaire » say why', async () => {
|
||||
const user = await openAnnotations()
|
||||
stacks()
|
||||
create()
|
||||
undoButton().focus()
|
||||
await user.keyboard(' ')
|
||||
@@ -676,22 +744,34 @@ describe('why a button is held (point 6)', () => {
|
||||
it('say it in English', async () => {
|
||||
const user = await openAnnotations()
|
||||
act(() => useLocaleStore.setState({ locale: 'en' }))
|
||||
stacks()
|
||||
create()
|
||||
const redo = screen.getByRole('button', {
|
||||
name: 'Redo the last undone change',
|
||||
})
|
||||
const undo = screen.getByRole('button', {
|
||||
name: 'Undo the last change',
|
||||
})
|
||||
expect(reason(redo)).toBe(
|
||||
'Redo is paused during a creation: discard it to redo.',
|
||||
)
|
||||
expect(reason(undo)).toBe(
|
||||
'Unavailable during a creation: create the annotation or discard it.',
|
||||
)
|
||||
await user.click(redo)
|
||||
expect(line()).toHaveTextContent('Unavailable during a creation')
|
||||
expect(line()).toHaveTextContent('Redo is paused during a creation')
|
||||
act(() => resetWork())
|
||||
pend()
|
||||
expect(reason(redo)).toBe(
|
||||
'Redo is paused during the change in progress: cancel it with Undo to redo.',
|
||||
)
|
||||
})
|
||||
|
||||
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()
|
||||
noMessage()
|
||||
cleanup()
|
||||
resetStore()
|
||||
serverHas(baseText(), 3)
|
||||
|
||||
Reference in new issue
Block a user