feat(app): a click on the drawing deselects (R1, D6b)
The decision comes from the press (landed off a marker, moved <= 4 px, one pointer), not the click target: mouse and pen act at pointerup, touch in the tap's own click. The reader passes no onEmpty and is unchanged. No existing assertion rewritten.
This commit is contained in:
1 parent
bbb1668406
commit
bbdfd27311
9 files changed
+586
-21
No files matched your search
@@ -1089,3 +1089,335 @@ describe('« Désélectionner » (R1, A6)', () => {
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('a tap on the drawing (D6b)', () => {
|
||||
const announce = vi.fn()
|
||||
const DESELECTED = 'Aucune annotation sélectionnée.'
|
||||
const drawing = (readOnly = false) =>
|
||||
screen.getByTestId(
|
||||
readOnly ? 'catalogue-canvas-drawing' : 'annotation-canvas-drawing',
|
||||
)
|
||||
const rect = (readOnly = false) => drawing(readOnly).querySelector('rect')!
|
||||
const box = () => screen.getByTestId('annotation-canvas')
|
||||
const snapshot = () => {
|
||||
const state = store.getState()
|
||||
return [
|
||||
state.documentText,
|
||||
state.handleVersion,
|
||||
state.undo.length,
|
||||
state.unsaved,
|
||||
]
|
||||
}
|
||||
const init = (id = 1, type = 'mouse') => ({
|
||||
pointerId: id,
|
||||
isPrimary: true,
|
||||
button: 0,
|
||||
pointerType: type,
|
||||
})
|
||||
|
||||
interface Tap {
|
||||
dx?: number
|
||||
upOn?: Element
|
||||
type?: string
|
||||
during?: () => void
|
||||
}
|
||||
/** pointerdown on `el`, an optional move, pointerup then click on `upOn`. */
|
||||
function tap(el: Element, options: Tap = {}) {
|
||||
const { dx = 0, upOn = el, type = 'mouse', during } = options
|
||||
fireEvent.pointerDown(el, { ...init(1, type), clientX: 10, clientY: 10 })
|
||||
if (dx !== 0) {
|
||||
fireEvent.pointerMove(el, {
|
||||
...init(1, type),
|
||||
clientX: 10 + dx,
|
||||
clientY: 10,
|
||||
})
|
||||
}
|
||||
during?.()
|
||||
fireEvent.pointerUp(upOn, {
|
||||
...init(1, type),
|
||||
clientX: 10 + dx,
|
||||
clientY: 10,
|
||||
})
|
||||
fireEvent.click(upOn, { clientX: 10 + dx, clientY: 10 })
|
||||
}
|
||||
|
||||
async function mountSpy(options: { text?: string; readOnly?: boolean } = {}) {
|
||||
announce.mockReset()
|
||||
await openReady({ text: options.text ?? text() })
|
||||
const readOnly = options.readOnly ?? false
|
||||
render(
|
||||
<AnnounceContext value={announce}>
|
||||
<AnnotationsTab {...props} readOnly={readOnly} />
|
||||
</AnnounceContext>,
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(drawing(readOnly).querySelector('svg')).not.toBeNull(),
|
||||
)
|
||||
}
|
||||
const isDeselected = () =>
|
||||
screen.queryByTestId('annotation-properties') === null
|
||||
async function selected(options: { text?: string } = {}) {
|
||||
await mountSpy(options)
|
||||
await selectFromList()
|
||||
}
|
||||
|
||||
it('deselects on the inner rect: focus on the box, announced, store unchanged', async () => {
|
||||
await selected()
|
||||
const before = snapshot()
|
||||
tap(rect())
|
||||
expect(isDeselected()).toBe(true)
|
||||
expect(document.activeElement).toBe(box())
|
||||
expect(announce).toHaveBeenCalledWith(DESELECTED)
|
||||
expect(announce).toHaveBeenCalledTimes(1)
|
||||
expect(snapshot()).toEqual(before)
|
||||
})
|
||||
|
||||
it('deselects on the composed root svg and on the box margin', async () => {
|
||||
await selected()
|
||||
tap(drawing().querySelector('svg')!)
|
||||
expect(isDeselected()).toBe(true)
|
||||
await selectFromList()
|
||||
tap(box())
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('keeps the selection when the press began on the selected marker (click retargeted)', async () => {
|
||||
await selected()
|
||||
tap(marker('anno-a'), { upOn: box() })
|
||||
expect(isDeselected()).toBe(false)
|
||||
tap(marker('anno-a'), { dx: 2, upOn: box() })
|
||||
expect(isDeselected()).toBe(false)
|
||||
expect(announce).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('selects another marker and a zone polygon through the click', async () => {
|
||||
const zone = zoneAnnotation({ type: 'polygon', points: triangle })
|
||||
await selected({
|
||||
text: insert(
|
||||
insert(text(), { kind: 'annotation', value: zone }),
|
||||
named('anno-b', 90, 90, 3),
|
||||
),
|
||||
})
|
||||
tap(marker('anno-b'))
|
||||
expect(screen.getByTestId('annotation-selection-tag')).toBeInTheDocument()
|
||||
tap(marker('zone-a'))
|
||||
expect(screen.getByTestId('annotation-selection-tag')).toHaveTextContent(
|
||||
'zone',
|
||||
)
|
||||
expect(announce).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps a pending keyboard creation with its typed name', async () => {
|
||||
await mountSpy({ text: drawnText() })
|
||||
const user = userEvent.setup()
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter un point' }),
|
||||
).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
await user.type(within(panel).getByLabelText('Nom (FR)'), 'Nuque')
|
||||
tap(rect())
|
||||
expect(screen.getByTestId('annotation-creation')).toBeInTheDocument()
|
||||
expect(within(panel).getByLabelText('Nom (FR)')).toHaveValue('Nuque')
|
||||
})
|
||||
|
||||
it('tells a tap from a drag on the accumulated movement (4 px)', async () => {
|
||||
await selected()
|
||||
tap(rect(), { dx: 3 })
|
||||
expect(isDeselected()).toBe(true)
|
||||
await selectFromList()
|
||||
tap(rect(), { dx: 6 })
|
||||
expect(isDeselected()).toBe(false)
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerMove(rect(), { ...init(), clientX: 15, clientY: 10 })
|
||||
fireEvent.pointerMove(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(rect())
|
||||
expect(isDeselected()).toBe(false)
|
||||
})
|
||||
|
||||
it('a second pointer, inside the box or not, makes it a gesture; the next tap deselects', async () => {
|
||||
await selected()
|
||||
tap(rect(), {
|
||||
during: () =>
|
||||
fireEvent.pointerDown(box(), {
|
||||
pointerId: 2,
|
||||
isPrimary: false,
|
||||
button: 0,
|
||||
pointerType: 'touch',
|
||||
}),
|
||||
})
|
||||
expect(isDeselected()).toBe(false)
|
||||
tap(rect(), {
|
||||
during: () =>
|
||||
fireEvent.pointerDown(document.body, {
|
||||
pointerId: 2,
|
||||
isPrimary: false,
|
||||
button: 0,
|
||||
pointerType: 'touch',
|
||||
}),
|
||||
})
|
||||
expect(isDeselected()).toBe(false)
|
||||
tap(rect())
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('ignores a right-button press and a context menu during the press', async () => {
|
||||
await selected()
|
||||
fireEvent.pointerDown(rect(), { ...init(), button: 2 })
|
||||
fireEvent.pointerUp(rect(), { ...init(), button: 2 })
|
||||
fireEvent.click(rect())
|
||||
expect(isDeselected()).toBe(false)
|
||||
tap(rect(), { during: () => fireEvent.contextMenu(rect()) })
|
||||
expect(isDeselected()).toBe(false)
|
||||
})
|
||||
|
||||
it('removes its document listener once the press ends', async () => {
|
||||
await selected()
|
||||
const spy = vi.spyOn(document, 'removeEventListener')
|
||||
tap(rect())
|
||||
expect(spy).toHaveBeenCalledWith('pointerdown', expect.any(Function), true)
|
||||
spy.mockRestore()
|
||||
})
|
||||
|
||||
it('adds a vertex, selection kept, in a replace tracing', async () => {
|
||||
const zone = zoneAnnotation({
|
||||
type: 'path',
|
||||
d: 'M 20 20 L 80 20 L 50 80 Z',
|
||||
})
|
||||
await mountSpy({
|
||||
text: insert(drawnText(), { kind: 'annotation', value: zone }),
|
||||
})
|
||||
tap(marker('zone-a'))
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Remplacer par un polygone' }))
|
||||
// The zone tool is active: the select-tool deselect never runs.
|
||||
triangle.forEach(([x, y]) => {
|
||||
fireEvent.pointerDown(box(), { ...init(), clientX: x, clientY: y })
|
||||
fireEvent.pointerUp(box(), { ...init(), clientX: x, clientY: y })
|
||||
fireEvent.click(box(), { clientX: x, clientY: y })
|
||||
})
|
||||
fireEvent.keyDown(box(), { key: 'Enter' })
|
||||
await waitFor(() =>
|
||||
expect(geometryOf('zone-a')).toEqual({
|
||||
type: 'polygon',
|
||||
points: triangle,
|
||||
}),
|
||||
)
|
||||
expect(announce).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('a drag of the selected marker moves it and keeps the selection', async () => {
|
||||
await selected()
|
||||
const hit = marker('anno-a')
|
||||
fireEvent.pointerDown(hit, { ...init(), clientX: 50, clientY: 50 })
|
||||
fireEvent.pointerMove(hit, { ...init(), clientX: 58, clientY: 50 })
|
||||
fireEvent.pointerUp(hit, { ...init(), clientX: 60, clientY: 40 })
|
||||
fireEvent.click(box())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60, cy: 40 })
|
||||
expect(isDeselected()).toBe(false)
|
||||
})
|
||||
|
||||
it('a touch tap deselects in its own click, not at the pointer-up', async () => {
|
||||
await selected()
|
||||
const hit = rect()
|
||||
fireEvent.pointerDown(hit, {
|
||||
...init(1, 'touch'),
|
||||
clientX: 10,
|
||||
clientY: 10,
|
||||
})
|
||||
fireEvent.pointerUp(hit, { ...init(1, 'touch'), clientX: 10, clientY: 10 })
|
||||
expect(isDeselected()).toBe(false)
|
||||
fireEvent.click(hit)
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('a touch tap whose click lands on a marker (adjustment) selects that marker', async () => {
|
||||
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
|
||||
tap(rect(), { type: 'touch', upOn: marker('anno-b') })
|
||||
expect(announce).not.toHaveBeenCalled()
|
||||
expect(isDeselected()).toBe(false)
|
||||
})
|
||||
|
||||
it('a mouse tap deselects at the pointer-up and swallows the click on a marker', async () => {
|
||||
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
|
||||
tap(rect(), { upOn: rect() })
|
||||
expect(isDeselected()).toBe(true)
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(marker('anno-b'))
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('a press on a polygon vertex handle outside its fill deselects (documented)', async () => {
|
||||
await mountSpy({
|
||||
text: insert(drawnText(), {
|
||||
kind: 'annotation',
|
||||
value: zoneAnnotation({ type: 'polygon', points: triangle }),
|
||||
}),
|
||||
})
|
||||
tap(marker('zone-a'))
|
||||
const handle = screen
|
||||
.getByTestId('annotation-overlay')
|
||||
.querySelector('circle')!
|
||||
tap(handle)
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('read-only twin: deselects on the rect and focuses the catalogue canvas', async () => {
|
||||
await mountSpy({ readOnly: true })
|
||||
await selectFromList()
|
||||
tap(rect(true))
|
||||
expect(isDeselected()).toBe(true)
|
||||
expect(document.activeElement).toBe(screen.getByTestId('catalogue-canvas'))
|
||||
expect(announce).toHaveBeenCalledWith(DESELECTED)
|
||||
})
|
||||
|
||||
it('undo after a tap deselect undoes the earlier edit, redo restores it', async () => {
|
||||
await selected()
|
||||
const user = userEvent.setup()
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60{Enter}')
|
||||
tap(rect())
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
|
||||
act(() => void store.getState().redoStep())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
})
|
||||
|
||||
it('commits a typed valid value once and deselects when the press blurs the field', async () => {
|
||||
await selected()
|
||||
const user = userEvent.setup()
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60')
|
||||
const depth = store.getState().undo.length
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
// What mousedown does: the focus moves to the box, the field commits, the drawing rebuilds.
|
||||
act(() => box().focus())
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(rect())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
expect(store.getState().undo.length).toBe(depth + 1)
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('a refused typed value: the panel closes, the document is unchanged', async () => {
|
||||
await selected({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
|
||||
const user = userEvent.setup()
|
||||
const before = store.getState().documentText
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '1000000')
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
act(() => box().focus())
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(rect())
|
||||
expect(isDeselected()).toBe(true)
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
})
|
||||
@@ -207,6 +207,20 @@ describe('/app/anatomy/:sheetId', () => {
|
||||
expect(screen.queryByRole('link', { name: fr['catalogue.open_admin'] })).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps the zone panel when the empty drawing is tapped (reader: no deselect)', async () => {
|
||||
mount(`/app/anatomy/${SHEET}`)
|
||||
const canvas = await screen.findByTestId('catalogue-canvas-drawing')
|
||||
await waitFor(() => expect(canvas.querySelector('[data-anno-id="thoracic"]')).not.toBeNull())
|
||||
fireEvent.click(canvas.querySelector('[data-anno-id="thoracic"]')!)
|
||||
const empty = canvas.querySelector('svg')!
|
||||
const init = { pointerId: 1, isPrimary: true, button: 0, pointerType: 'mouse' }
|
||||
fireEvent.pointerDown(empty, init)
|
||||
fireEvent.pointerUp(empty, init)
|
||||
fireEvent.click(empty)
|
||||
expect(screen.getByRole('heading', { name: 'Zone : Vertèbres thoraciques' })).toBeInTheDocument()
|
||||
expect(canvas.querySelector('[data-anno-id="thoracic"]')).toHaveAttribute('data-state', 'current')
|
||||
})
|
||||
|
||||
it('opens the detail view from its link on the drawing', async () => {
|
||||
mount(`/app/anatomy/${SHEET}`)
|
||||
const canvas = await screen.findByTestId('catalogue-canvas-drawing')
|
||||
|
||||
Reference in new issue
Block a user