feat(app): Désélectionner and the Escape priority (R1, D6, A5, A6)
« Désélectionner » (secondary sm, deselect glyph) sits left of « Supprimer » in a bordered row of the properties panel, read-only too, hidden while a tracing runs. It commits the typed field, clears the selection, focuses the row (else the drawing) and announces. Escape deselects through one document listener per visible body (not in a text field, only inside the workspace); G1: row focus only from the panel. « Plus » and the references panel close first; a tracing cancel marks its Escape. No existing assertion rewritten.
This commit is contained in:
1 parent
7dda61d2ae
commit
bbb1668406
14 files changed
+633
-42
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import { AnnounceContext } from '@/editor/focusRequest'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import {
|
||||
ASSET,
|
||||
@@ -944,3 +945,147 @@ describe('the drag and the canvas follow the handle (H8)', () => {
|
||||
await waitFor(() => expect(marker('anno-a')).not.toBe(first))
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Désélectionner » (R1, A6)', () => {
|
||||
const announce = vi.fn()
|
||||
const rowOf = (id: string, prefix = '') =>
|
||||
document.querySelector<HTMLElement>(
|
||||
`[data-focus-key='{"kind":"annotation","id":"${id}"}']`,
|
||||
) ?? document.getElementById(`${prefix}${id}`)
|
||||
const snapshot = () => {
|
||||
const state = store.getState()
|
||||
return [
|
||||
state.documentText,
|
||||
state.handleVersion,
|
||||
state.undo.length,
|
||||
state.unsaved,
|
||||
]
|
||||
}
|
||||
|
||||
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>,
|
||||
)
|
||||
const drawing = readOnly
|
||||
? 'catalogue-canvas-drawing'
|
||||
: 'annotation-canvas-drawing'
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId(drawing).querySelector('svg')).not.toBeNull(),
|
||||
)
|
||||
}
|
||||
const button = (panel: HTMLElement, name = 'Désélectionner') =>
|
||||
within(panel).getByRole('button', { name })
|
||||
|
||||
it('shows the overview, focuses the row, announces, and changes nothing else', async () => {
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
const before = snapshot()
|
||||
await userEvent.setup().click(button(panel))
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
expect(screen.getByTestId('annotation-overview')).toBeInTheDocument()
|
||||
expect(document.activeElement).toBe(rowOf('anno-a'))
|
||||
expect(announce).toHaveBeenCalledWith('Aucune annotation sélectionnée.')
|
||||
expect(snapshot()).toEqual(before)
|
||||
})
|
||||
|
||||
it('focuses the drawing when a filter hides the row', async () => {
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
// The filter lives in the overview: type it there, then reselect from the drawing.
|
||||
await userEvent.setup().click(button(panel))
|
||||
const filter = screen.getByLabelText('Filtrer par nom')
|
||||
fireEvent.change(filter, { target: { value: 'zzz-no-match' } })
|
||||
fireEvent.click(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector(
|
||||
'[data-anno-id="anno-a"]',
|
||||
)!,
|
||||
)
|
||||
const reopened = await screen.findByTestId('annotation-properties')
|
||||
await userEvent.setup().click(button(reopened))
|
||||
expect(document.activeElement).toBe(screen.getByTestId('annotation-canvas'))
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
})
|
||||
|
||||
it('undo after it undoes the earlier edit', async () => {
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
await user.clear(within(panel).getByLabelText('Centre x'))
|
||||
await user.type(within(panel).getByLabelText('Centre x'), '60{Enter}')
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
await user.click(button(panel))
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
|
||||
})
|
||||
|
||||
it('read-only: no « Supprimer », it deselects and focuses the ro- row', async () => {
|
||||
await mountSpy({ readOnly: true })
|
||||
const panel = await selectFromList()
|
||||
expect(within(panel).queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
||||
await userEvent.setup().click(button(panel))
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
const row = document.querySelector(
|
||||
'[data-focus-key=\'{"kind":"annotation","id":"anno-a"}\']',
|
||||
)
|
||||
expect(document.activeElement).toBe(row)
|
||||
expect(announce).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('commits a valid typed value once when the field is not blurred', async () => {
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60')
|
||||
const depth = store.getState().undo.length
|
||||
await user.click(button(panel))
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
expect(store.getState().undo.length).toBe(depth + 1)
|
||||
})
|
||||
|
||||
it('a refused typed value: the panel closes, the document is unchanged', async () => {
|
||||
await mountSpy({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const before = store.getState().documentText
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '1000000')
|
||||
await user.click(button(panel))
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('speaks English', async () => {
|
||||
useLocaleStore.setState({ locale: 'en' })
|
||||
await mountSpy()
|
||||
await screen.findByTestId('annotation-overview')
|
||||
await userEvent.setup().click(rowOf('anno-a')!)
|
||||
const panel = await screen.findByTestId('annotation-properties')
|
||||
await userEvent.setup().click(button(panel, 'Deselect'))
|
||||
expect(announce).toHaveBeenCalledWith('No annotation selected.')
|
||||
})
|
||||
|
||||
it('is not offered while a replace tracing runs', async () => {
|
||||
await mountSpy({
|
||||
text: insert(drawnText(), {
|
||||
kind: 'annotation',
|
||||
value: zoneAnnotation({ type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' }),
|
||||
}),
|
||||
})
|
||||
const panel = await selectFromList()
|
||||
await userEvent.setup().click(
|
||||
within(panel).getByRole('button', { name: 'Remplacer par un polygone' }),
|
||||
)
|
||||
const open = await screen.findByTestId('annotation-properties')
|
||||
expect(
|
||||
within(open).queryByRole('button', { name: 'Désélectionner' }),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,248 @@
|
||||
/** R1 (A5, A6): the Escape priority across the whole editor workspace. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { resetStore, serverHas, store } from '../helpers/editorHarness'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||||
getSheetVersion: vi.fn(),
|
||||
downloadSheetDrawing: vi.fn(),
|
||||
saveSheetDraft: vi.fn(),
|
||||
getOfficialSheetAdmin: vi.fn(),
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
|
||||
Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', {
|
||||
configurable: true,
|
||||
value: () => ({ ...identity, inverse: () => identity }),
|
||||
})
|
||||
})
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
setWidth(1024)
|
||||
})
|
||||
|
||||
const TWO = () =>
|
||||
insert(
|
||||
insert(drawnText(), point('anno-a', 50, 50, 5)),
|
||||
point('anno-b', 20, 20, 3),
|
||||
)
|
||||
const ZONE = () =>
|
||||
insert(drawnText(), {
|
||||
kind: 'annotation',
|
||||
value: {
|
||||
...(point('zone-a', 0, 0, 1).value as Annotation),
|
||||
kind: 'zone',
|
||||
geometry: { type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' },
|
||||
} as Annotation,
|
||||
})
|
||||
|
||||
const shown = (selector: string) =>
|
||||
[...document.querySelectorAll<HTMLElement>(selector)].find(
|
||||
(element) => !element.closest('[hidden]'),
|
||||
)
|
||||
const panel = () => shown('[data-testid="annotation-properties"]')
|
||||
const rowOf = (id: string) =>
|
||||
shown(`[data-focus-key='{"kind":"annotation","id":"${id}"}']`)
|
||||
const live = () => document.querySelector('[aria-live="polite"]')!
|
||||
const escape = (target: Element | Window = document.body) =>
|
||||
fireEvent.keyDown(target, { key: 'Escape' })
|
||||
|
||||
async function mount(text = TWO(), width?: number) {
|
||||
serverHas(text, 3)
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width })
|
||||
await screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
await waitFor(() =>
|
||||
expect(shown('[data-testid$="canvas-drawing"] svg')).toBeDefined(),
|
||||
)
|
||||
return user
|
||||
}
|
||||
|
||||
/** Selects through the overview row (the visible body's). */
|
||||
async function select(user: ReturnType<typeof userEvent.setup>, id = 'anno-a') {
|
||||
await waitFor(() => expect(rowOf(id)).toBeDefined())
|
||||
await user.click(rowOf(id)!)
|
||||
await waitFor(() => expect(panel()).toBeDefined())
|
||||
}
|
||||
const canvasBox = () =>
|
||||
shown('[data-place="annotations.drawing"] [role="group"][tabindex="0"]')!
|
||||
const inPanel = (name: string) => within(panel()!).getByRole('button', { name })
|
||||
|
||||
describe('Escape deselects', () => {
|
||||
it('from the canvas box: deselected, the focus stays, announced', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
canvasBox().focus()
|
||||
escape(canvasBox())
|
||||
expect(panel()).toBeUndefined()
|
||||
expect(document.activeElement).toBe(canvasBox())
|
||||
await waitFor(() =>
|
||||
expect(live()).toHaveTextContent('Aucune annotation sélectionnée.'),
|
||||
)
|
||||
})
|
||||
|
||||
it('from a button of the panel: deselected, the focus on the row', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
inPanel('Marquer comme relu').focus()
|
||||
escape(document.activeElement!)
|
||||
expect(panel()).toBeUndefined()
|
||||
expect(document.activeElement).toBe(rowOf('anno-a'))
|
||||
})
|
||||
|
||||
it("after A then B, from the panel: the focus on B's row", async () => {
|
||||
const user = await mount()
|
||||
await select(user, 'anno-a')
|
||||
await user.click(inPanel('Toutes les annotations'))
|
||||
await select(user, 'anno-b')
|
||||
inPanel('Marquer comme relu').focus()
|
||||
escape(document.activeElement!)
|
||||
expect(document.activeElement).toBe(rowOf('anno-b'))
|
||||
})
|
||||
|
||||
it('from body and from the history button of the tab row', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
escape(document.body)
|
||||
expect(panel()).toBeUndefined()
|
||||
await select(user)
|
||||
act(
|
||||
() =>
|
||||
void store
|
||||
.getState()
|
||||
.commit({ op: 'remove', key: { kind: 'annotation', id: 'anno-b' } }),
|
||||
)
|
||||
const undo = screen.getByRole('button', { name: /Défaire/ })
|
||||
await waitFor(() => expect(undo).toBeEnabled())
|
||||
undo.focus()
|
||||
escape(undo)
|
||||
expect(panel()).toBeUndefined()
|
||||
expect(document.activeElement).toBe(undo)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Escape leaves alone', () => {
|
||||
it('a text field', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
const field = within(panel()!).getByLabelText('Nom (FR)')
|
||||
field.focus()
|
||||
escape(field)
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('a target outside the workspace', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
const outside = document.createElement('button')
|
||||
document.body.append(outside)
|
||||
outside.focus()
|
||||
escape(outside)
|
||||
outside.remove()
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('nothing selected, or the selected annotation deleted: no announcement', async () => {
|
||||
const user = await mount()
|
||||
escape(document.body)
|
||||
expect(live()).toBeEmptyDOMElement()
|
||||
await select(user)
|
||||
act(
|
||||
() =>
|
||||
void store
|
||||
.getState()
|
||||
.commit({ op: 'remove', key: { kind: 'annotation', id: 'anno-a' } }),
|
||||
)
|
||||
const before = store.getState().documentText
|
||||
escape(document.body)
|
||||
expect(live()).toBeEmptyDOMElement()
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('a tracing: the TracingBar keeps its Escape, the canvas box cancels the tracing only', async () => {
|
||||
const user = await mount(ZONE())
|
||||
await select(user, 'zone-a')
|
||||
await user.click(inPanel('Remplacer par un polygone'))
|
||||
const bar = await screen.findByTestId('tracing-bar')
|
||||
bar.focus()
|
||||
escape(bar)
|
||||
expect(screen.queryByTestId('tracing-bar')).not.toBeNull()
|
||||
canvasBox().focus()
|
||||
escape(canvasBox())
|
||||
await waitFor(() => expect(screen.queryByTestId('tracing-bar')).toBeNull())
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('a modal dialog open: only its own handling (wiring proof)', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
await user.click(inPanel('Supprimer'))
|
||||
const dialog = document.querySelector('dialog')!
|
||||
expect(dialog).not.toBeNull()
|
||||
escape(dialog)
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Escape and the other layers', () => {
|
||||
it('closes the references panel from the tab row, the selection kept', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Références' }))
|
||||
const tab = screen.getByRole('tab', { name: 'Annotations' })
|
||||
escape(tab)
|
||||
expect(screen.getByRole('button', { name: 'Références' })).toHaveAttribute(
|
||||
'aria-expanded',
|
||||
'false',
|
||||
)
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('closes « Plus » first (small tier), the twin selection kept', async () => {
|
||||
const user = await mount(TWO(), 500)
|
||||
await select(user)
|
||||
const more = screen.getByRole('button', { name: 'Plus' })
|
||||
await user.click(more)
|
||||
expect(more).toHaveAttribute('aria-expanded', 'true')
|
||||
canvasBox().focus()
|
||||
escape(canvasBox())
|
||||
expect(more).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(document.activeElement).toBe(more)
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('read-only width: only the visible twin deselects, the hidden body keeps its own', async () => {
|
||||
const user = await mount()
|
||||
await select(user)
|
||||
setWidth(500)
|
||||
act(() => void window.dispatchEvent(new Event('resize')))
|
||||
await waitFor(() =>
|
||||
expect(shown('[data-testid="catalogue-canvas"]')).toBeDefined(),
|
||||
)
|
||||
await select(user)
|
||||
escape(document.body)
|
||||
expect(panel()).toBeUndefined()
|
||||
const hidden = [
|
||||
...document.querySelectorAll('[data-testid="annotation-properties"]'),
|
||||
].filter((element) => element.closest('[hidden]'))
|
||||
expect(hidden).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user