U2 Task 5. A selected polygon gets its vertex, « + » and « − » handles (R-9, hidden « + » under two hit radii, R-18 zoom hint in the strip), the handle cap at 40 (R-7), vertex drag and keys, the move mode on the zone or the chosen vertex, « Redessiner » as a redraw mode kept in step with its tracing (R-12 guard, R-13 drop), close radius in CSS px (R-11). The numeric group leaves the properties panel (D1). Removed or rewritten assertions (numeric group -> replacement): - tab « shows its exact stored numbers » (Centre x field) -> the overlay selection circle's cx attribute, same exact value. - tab « a numeric edit » x3 -> « an edit on the drawing »: Enter on the handle without a step commits nothing, a step + Enter commits once; a refused handle drag keeps the stored shape then a drag inside the frame repairs it (issues gone); Escape drops a pending series. - tab C26 « Centre x 15 » -> overlay cx 15. - tab C32 unmeasured « Centre x as text » -> no handle, no field. - tab « adds and removes a vertex as part of the whole group » -> « + » then « − » on the drawing; « never offers to remove below three » -> « − » aria-disabled at 3. - tab H8 « refused Remplacer drops the tracing » -> keeps it open with « Fermeture refusée » (board 33 A); « refused vertex add/remove stay non appliqué » -> a refused vertex drag restores the shape exactly. - tab Désélectionner and D6b (typed Centre x committed, refused, undone) x6 and strip « a new commit replaces the message » -> the same with the Nom (FR) field (a blank name is the refused value). - focus-request « Centre x 20 » -> overlay cx 20. - escape « strip commands keep their Escape » -> a redraw: Escape on the strip or the box cancels it (R-12 row 4); kept for a new zone tracing. - keep-alive « Remplacer tracing kept across Aller à » -> ended by a tab when empty, asked once a vertex is placed (R-12). - e2e annotations: numeric cx edit + undo/redo -> handle keys + undo/ redo; jitter/drag and Task 4 point reads -> overlay attributes (the stored place during the mode -> overlay-old-place); keyboard-only cy and vertex x typed -> handle and vertex keys. - e2e deselect: Centre x typed/refused/committed -> Nom (FR). - e2e geometry, shell-crossing: Centre x/cy reads -> overlay attributes. - e2e journey: cx +3 and vertex x +4 typed -> 3 and 4 arrow steps + Enter; a far typed value + revert -> a far handle drag refused. - e2e equine latency: typed cx rounds -> handle arrow + Enter rounds.
375 lines
12 KiB
TypeScript
375 lines
12 KiB
TypeScript
/** R1 (A5, A6): the Escape priority across the whole editor workspace. */
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import {
|
|
act,
|
|
cleanup,
|
|
fireEvent,
|
|
render,
|
|
screen,
|
|
waitFor,
|
|
within,
|
|
} from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { Annotation } from '@faunosteo/core-wasm/types'
|
|
import ModalDialog from '@/components/ui/ModalDialog'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import { drawnText, edit, insert, point } from '../helpers/editorFixtures'
|
|
import { pressAt, resetStore, serverHas, store } from '../helpers/editorHarness'
|
|
import { openFinding } from '../helpers/findingDialog'
|
|
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,
|
|
})
|
|
|
|
/** TWO plus a finding node that cites one reference: the citations panel has a trigger. */
|
|
const WITH_NODE = () => {
|
|
const name = (n: string) => ({ fr: n, en: n })
|
|
let text = insert(TWO(), {
|
|
kind: 'reference',
|
|
value: {
|
|
id: 'ref-a',
|
|
type: 'book',
|
|
citation: 'Alpha',
|
|
url: null,
|
|
doi: null,
|
|
},
|
|
})
|
|
text = insert(text, {
|
|
kind: 'zone',
|
|
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
|
})
|
|
text = edit(text, {
|
|
op: 'insert',
|
|
parent: { kind: 'zone', id: 'zone-a' },
|
|
element: {
|
|
kind: 'finding_category',
|
|
value: {
|
|
id: 'fcat-a',
|
|
kind: 'dysfunction',
|
|
name: name('Cat A'),
|
|
description: {},
|
|
reference_ids: [],
|
|
review_status: 'to_confirm',
|
|
children: [],
|
|
},
|
|
},
|
|
})
|
|
return edit(text, {
|
|
op: 'insert',
|
|
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
|
element: {
|
|
kind: 'finding_node',
|
|
value: {
|
|
id: 'fnode-a',
|
|
name: name('Node A'),
|
|
description: {},
|
|
reference_ids: ['ref-a'],
|
|
requires_vet_referral: false,
|
|
review_status: 'to_confirm',
|
|
children: [],
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
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 citations = () => screen.queryByTestId('editor-citations-panel')
|
|
|
|
/** Constats, the node selected, its « 1 référence » trigger pressed. */
|
|
async function openCitations(user: ReturnType<typeof userEvent.setup>) {
|
|
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
|
await openFinding(user, /Node A/)
|
|
await user.click(screen.getByRole('button', { name: '1 référence' }))
|
|
expect(citations()).not.toBeNull()
|
|
}
|
|
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 new zone tracing: the strip tracing commands keep their Escape (Task 7 asks)', async () => {
|
|
const user = await mount(ZONE())
|
|
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
|
pressAt(canvasBox(), 20, 20)
|
|
const bar = await screen.findByTestId('tracing-commands')
|
|
bar.focus()
|
|
escape(bar)
|
|
expect(screen.queryByTestId('tracing-commands')).not.toBeNull()
|
|
})
|
|
|
|
// U2 Task 5 (R-12, board 32 row 4): « Remplacer par un polygone » is a redraw, which
|
|
// Escape cancels at once from anywhere in the workspace, the strip's commands included
|
|
// (before Task 5 only the canvas box did). The selection stays.
|
|
it('a redraw: Escape on the strip commands or on 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-commands')
|
|
bar.focus()
|
|
escape(bar)
|
|
await waitFor(() =>
|
|
expect(screen.queryByTestId('tracing-commands')).toBeNull(),
|
|
)
|
|
expect(panel()).toBeDefined()
|
|
await user.click(inPanel('Remplacer par un polygone'))
|
|
await screen.findByTestId('tracing-commands')
|
|
canvasBox().focus()
|
|
escape(canvasBox())
|
|
await waitFor(() =>
|
|
expect(screen.queryByTestId('tracing-commands')).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 with the focus on the page', () => {
|
|
it('a delete dialog open: the selection is kept', async () => {
|
|
const user = await mount()
|
|
await select(user)
|
|
await user.click(inPanel('Supprimer'))
|
|
expect(document.querySelector('dialog[open]')).not.toBeNull()
|
|
document.body.focus()
|
|
escape(document.body)
|
|
expect(panel()).toBeDefined()
|
|
})
|
|
|
|
it('the citations sheet open: Escape closes it only, the annotation selection is kept', async () => {
|
|
const user = await mount(WITH_NODE())
|
|
await select(user)
|
|
await openCitations(user)
|
|
const trigger = screen.getByRole('button', { name: '1 référence' })
|
|
expect(trigger).toHaveAttribute('aria-haspopup', 'dialog')
|
|
await user.keyboard('{Escape}')
|
|
await waitFor(() => expect(citations()).toBeNull())
|
|
await waitFor(() => expect(trigger).toHaveFocus())
|
|
// the finding dialog under the sheet is still there: a second Escape closes it
|
|
expect(document.querySelector('dialog[open]')).not.toBeNull()
|
|
await user.keyboard('{Escape}')
|
|
await waitFor(() =>
|
|
expect(document.querySelector('dialog[open]')).toBeNull(),
|
|
)
|
|
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
|
expect(panel()).toBeDefined()
|
|
})
|
|
|
|
it('a dialog outside the workspace open: the selection is kept', async () => {
|
|
const user = await mount()
|
|
await select(user)
|
|
render(
|
|
<ModalDialog onClose={() => undefined} label="Outside">
|
|
<p>Outside</p>
|
|
</ModalDialog>,
|
|
)
|
|
escape(document.body)
|
|
expect(panel()).toBeDefined()
|
|
})
|
|
|
|
it('« Plus » open, Escape in the twin filter: the menu and the field stay', async () => {
|
|
const user = await mount(TWO(), 500)
|
|
const more = screen.getByRole('button', { name: 'Plus' })
|
|
await user.click(more)
|
|
const filter = within(
|
|
shown('[data-testid="annotation-overview"]')!,
|
|
).getByRole('searchbox', { name: 'Filtrer par nom' })
|
|
filter.focus()
|
|
escape(filter)
|
|
expect(more).toHaveAttribute('aria-expanded', 'true')
|
|
expect(document.activeElement).toBe(filter)
|
|
})
|
|
})
|
|
|
|
describe('Escape and the other layers', () => {
|
|
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)
|
|
})
|
|
})
|