fix(editor): sign-out and shell links ask the drawing guard first
With a started move, sign-out and an in-app link now ask « Abandonner le déplacement ? » (R-12) through the page's own question, registered by the draft route in leaveGuardStore (`ask`; the shell imports no editor module). The generic leave and sign-out dialogs cover only sheet-level unsaved work; with both pending the drawing asks first, then the sheet question, as useLeaveConfirm orders them. A move with nothing started arms nothing (it ends); a started one still guards a reload. Tests: sign-out and link with a started move (alone and with sheet changes), the history jump with only a move and after dirty layers, a section entry and « Tout afficher ».
This commit is contained in:
1 parent
44de465c6d
commit
e01d8519ea
8 files changed
+311
-26
No files matched your search
@@ -13,6 +13,13 @@ import {
|
||||
type LayerName,
|
||||
} from '@/editor/useEditorNavigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { answerDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import {
|
||||
resetWork,
|
||||
setModePreview,
|
||||
startMove,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
|
||||
const path = '/app/admin/sheets/S/draft'
|
||||
|
||||
@@ -132,3 +139,54 @@ describe('reference, citations and finding dialogs, all dirty', () => {
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the drawing guard on a history jump out of the editor (R-12)', () => {
|
||||
const STORED = { type: 'circle' as const, cx: 1, cy: 2, r: 3 }
|
||||
afterEach(resetWork)
|
||||
|
||||
it('with only a started move: the jump waits for its question, then goes', async () => {
|
||||
cleanup()
|
||||
render(
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<DrawingOnly />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
startMove('a', 'doc')
|
||||
setModePreview({ ...STORED, cx: 9 }, STORED)
|
||||
expect(jump().defaultPrevented).toBe(true)
|
||||
expect(useAnnotationWork.getState().question?.work).toBe('move')
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
act(() => answerDrawing(true))
|
||||
expect(api.traverseTo).toHaveBeenCalledWith('list')
|
||||
})
|
||||
|
||||
it('with nothing started: the jump is not held and the mode ends', () => {
|
||||
cleanup()
|
||||
render(
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<DrawingOnly />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
startMove('a', 'doc')
|
||||
expect(jump().defaultPrevented).toBe(false)
|
||||
})
|
||||
|
||||
it('dirty layers ask first, then the drawing, then the jump goes', async () => {
|
||||
const user = userEvent.setup()
|
||||
startMove('a', 'doc')
|
||||
setModePreview({ ...STORED, cx: 9 }, STORED)
|
||||
jump()
|
||||
await user.click(button('reference', 'Abandonner'))
|
||||
await user.click(button('citations', 'Abandonner'))
|
||||
await user.click(button('finding', 'Abandonner'))
|
||||
expect(api.traverseTo).not.toHaveBeenCalled()
|
||||
expect(useAnnotationWork.getState().question?.work).toBe('move')
|
||||
act(() => answerDrawing(true))
|
||||
expect(api.traverseTo).toHaveBeenCalledWith('list')
|
||||
})
|
||||
})
|
||||
|
||||
function DrawingOnly() {
|
||||
useLeaveConfirm(useEditorNavigation('findings'))
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user