feat(editor): drawing guard before navigations drop a started move (R-12)
The move mode lives in the work store with its document stamp. guardDrawing ends an unstarted mode at once and asks « Abandonner le déplacement ? » (DrawingGuardDialog, at workspace level) once work is started, before a tab, a section, « Aller à », Back and a history jump out of the editor; the leave guard and sign-out count started work. An undo from the header, Ctrl+Z or the message only cancels a pending mode or preview (R-13), and a document change drops a stale mode, keeping a started one to be said. ConfirmDialog takes an optional body. Strings for Task 4 added.
This commit is contained in:
1 parent
8cd1bda6c2
commit
2882821661
18 files changed
+465
-37
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
renderHook,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
@@ -26,6 +27,13 @@ import useEditorHistory from '@/editor/history/useEditorHistory'
|
||||
import { defaultView, targetOfKey } from '@/editor/navigation'
|
||||
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
|
||||
import {
|
||||
resetWork,
|
||||
setModePreview,
|
||||
startMove,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
@@ -66,6 +74,7 @@ function Page({ guard }: { guard?: () => { allowed: boolean } }) {
|
||||
<button onClick={() => nav.announce('one')}>say one</button>
|
||||
<button onClick={() => nav.announce('two')}>say two</button>
|
||||
<p data-testid="live">{nav.live}</p>
|
||||
<DrawingGuardDialog />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -372,3 +381,81 @@ describe('final review: queued landings (M-6)', () => {
|
||||
expect(focused).not.toContain(references)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the drawing guard (R-12): a move mode and the navigations', () => {
|
||||
const STORED = { type: 'circle' as const, cx: 1, cy: 2, r: 3 }
|
||||
afterEach(resetWork)
|
||||
const tabShown = () => screen.getByRole('tab', { selected: true })
|
||||
const started = () => {
|
||||
startMove('a', 'doc')
|
||||
setModePreview({ ...STORED, cx: 9 }, STORED)
|
||||
}
|
||||
|
||||
it('with no step taken, a tab ends the mode at once, without a question', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
startMove('a', 'doc')
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
expect(tabShown()).toHaveTextContent('Constats')
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
})
|
||||
|
||||
it('after one step a tab asks; « Continuer » keeps the mode and its position', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
started()
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
const dialog = screen.getByRole('dialog', {
|
||||
name: 'Abandonner le déplacement ?',
|
||||
})
|
||||
expect(tabShown()).toHaveTextContent('Général')
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Continuer' }))
|
||||
expect(tabShown()).toHaveTextContent('Général')
|
||||
expect(useAnnotationWork.getState().preview?.geometry).toMatchObject({
|
||||
cx: 9,
|
||||
})
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(tabShown()).toHaveTextContent('Constats')
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
})
|
||||
|
||||
it('« Aller à » asks the same way', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
started()
|
||||
await user.click(screen.getByRole('button', { name: 'go to' }))
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Abandonner le déplacement ?' }),
|
||||
).toBeInTheDocument()
|
||||
expect(tabShown()).toHaveTextContent('Général')
|
||||
})
|
||||
|
||||
it('a Back asks and keeps the view; an unstarted mode lets it go and ends', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
started()
|
||||
act(() => navigate(-1))
|
||||
expect(tabShown()).toHaveTextContent('Constats')
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Abandonner le déplacement ?' }),
|
||||
).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
// As after a layer's question, the Back is not replayed: the user goes Back again.
|
||||
expect(tabShown()).toHaveTextContent('Constats')
|
||||
await waitFor(() =>
|
||||
expect(document.querySelector('dialog[open]')).toBeNull(),
|
||||
)
|
||||
startMove('a', 'doc')
|
||||
act(() => navigate(-1))
|
||||
expect(tabShown()).toHaveTextContent('Général')
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user