test(editor): double click opens an access view, focus kept
This commit is contained in:
1 parent
9a7a588e92
commit
d05c3fe34e
2 files changed
+31
-2
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import type { Dispatch } from 'react'
|
import type { Dispatch } from 'react'
|
||||||
import type { Scene } from '@/components/editor/annotations/EditableAnnotations'
|
import type { Scene } from '@/components/editor/annotations/EditableAnnotations'
|
||||||
import { guardDrawing } from './drawingGuard'
|
import { flushSync } from 'react-dom'
|
||||||
|
import { guardDrawing, focusPressedIfLost } from './drawingGuard'
|
||||||
import { guardedPress } from './guardedPress'
|
import { guardedPress } from './guardedPress'
|
||||||
import type { UiAction } from './uiState'
|
import type { UiAction } from './uiState'
|
||||||
|
|
||||||
@@ -12,6 +13,15 @@ export interface ViewNavigation {
|
|||||||
goToParent: (control: HTMLElement | null) => void
|
goToParent: (control: HTMLElement | null) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** No control was pressed: the marker unmounts, the focus returns to the drawing. */
|
||||||
|
function showFromDrawing(show: () => void) {
|
||||||
|
flushSync(show)
|
||||||
|
const viewport = document.querySelector<HTMLElement>(
|
||||||
|
'[data-drawing-column] [data-testid="annotation-canvas"]',
|
||||||
|
)
|
||||||
|
if (viewport) focusPressedIfLost(viewport)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The two ways to reach another view from the drawing, « Vue parente » and « Ouvrir la
|
* The two ways to reach another view from the drawing, « Vue parente » and « Ouvrir la
|
||||||
* vue » (D14). The view stays a UI state: no history entry is pushed (D15).
|
* vue » (D14). The view stays a UI state: no history entry is pushed (D15).
|
||||||
@@ -25,7 +35,7 @@ export function useViewNavigation(
|
|||||||
const openView = (viewId: string, control: HTMLElement | null) => {
|
const openView = (viewId: string, control: HTMLElement | null) => {
|
||||||
const show = () => dispatch({ type: 'view', viewId })
|
const show = () => dispatch({ type: 'view', viewId })
|
||||||
if (control) guardedPress(control, show)
|
if (control) guardedPress(control, show)
|
||||||
else if (guardDrawing(show)) show()
|
else if (guardDrawing(show)) showFromDrawing(show)
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
openView,
|
openView,
|
||||||
|
|||||||
@@ -174,6 +174,25 @@ describe('« Ouvrir la vue » and the second click', () => {
|
|||||||
expect(screen.queryByRole('dialog')).toBeNull()
|
expect(screen.queryByRole('dialog')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('a double click on an unselected access opens its view, focus kept', async () => {
|
||||||
|
await mount()
|
||||||
|
await screen.findByRole('list', { name: 'Annotations de la vue' })
|
||||||
|
pressAt(marker('l'), 50, 50)
|
||||||
|
pressAt(marker('l'), 50, 50)
|
||||||
|
await waitFor(() => shown('Tête'))
|
||||||
|
expect(screen.queryByRole('dialog')).toBeNull()
|
||||||
|
expect(document.activeElement).not.toBe(document.body)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a double click on an unselected point opens its properties', async () => {
|
||||||
|
await mount()
|
||||||
|
await screen.findByRole('list', { name: 'Annotations de la vue' })
|
||||||
|
pressAt(marker('p'), 50, 50)
|
||||||
|
pressAt(marker('p'), 50, 50)
|
||||||
|
expect(await screen.findByRole('dialog')).toBeInTheDocument()
|
||||||
|
shown('Vue principale')
|
||||||
|
})
|
||||||
|
|
||||||
it('a second click on a selected point still opens its properties', async () => {
|
it('a second click on a selected point still opens its properties', async () => {
|
||||||
await mount()
|
await mount()
|
||||||
await selectRow(0)
|
await selectRow(0)
|
||||||
|
|||||||
Reference in new issue
Block a user