U2 Task 6 (A1, A2, A3, A9, A10, R-3, R-5, R-6, R-14, R-16). - Dialog: `anchor` places the panel at the column's left and width, from its top, under a 22 % ink veil that ignores clicks; the visual viewport below 320 px; centred without an anchor box. - Navigation: `annotation` layer (LAYERS, EditorView, history entry, leave guards, left-draft flag); Back closes, Forward reopens. - AnnotationDialog: read body, « Modifier » form (CreationFields with « Couleur », missingFields, R-3 messages), one `update` on the current annotation by id, « Marquer comme relu », « Modifier la forme », « Supprimer »; read-only flip keeps the draft. - The column always shows the overview, selected row marked; Enter on it, a second click or a double click, the strip's « Propriétés » open the dialog. « Aller à » focuses the row (R-5). - Read-only twin: strip and read-only dialog at 1 024 px and wider, inline read body below. PropertiesPanel and AnnotationFields gone. - Strip lead 256 px and a fixed status slot, so the commands fit at 1 024 px and a status change moves nothing. - e2e: `aside-content` exemption removed; scroll-to-top workarounds of editor-geometry, editor-zones and editor-journey removed. Removed assertions mapped: editor-annotations-tab.test.tsx: - selectFromList waited for `annotation-properties` -> waits for the strip's « Propriétés » (selection without dialog, A1) - refused place: issues block `annotation-geometry-issues` in the panel -> the strip notice alert (present, then gone) - keyboard creation / C26 confirmation: `annotation-properties` after create -> strip « Propriétés » (new element selected) - Désélectionner from the panel -> « Désélectionner » in the strip (all 7 tests); « panel closes » -> strip has no « Propriétés » - undo after deselect (typed name) -> handle key series then deselect then undo - commits a valid typed value once without blur (name field) -> a pending handle key series committed once by the strip deselect - a refused typed value: the panel closes (two tests: strip deselect, tap deselect) -> removed: no field outside the dialog; the dialog's draft writes nothing before « Enregistrer » (new dialog tests) - not offered while a replace tracing runs: panel's Désélectionner absent -> strip offers neither « Désélectionner » nor « Propriétés » during the tracing - tap: isDeselected read `annotation-properties` -> strip « Propriétés » absent; link select -> strip title data-selection - tap: undo after tap deselect (typed name) -> handle series; typed value committed on blur -> handle series committed on blur - strip geometry issues: list read in the panel -> list read in the properties dialog's issues block - a new commit replaces the message (typed name) -> « Marquer comme relu » in the dialog editor-escape.test.tsx: - `panel()` = `annotation-properties` -> the strip's « Propriétés » or the phone twin's inline read body - Escape from a panel button (« Marquer comme relu ») -> from the selected row in the side column: focus on the row - after A then B from the panel (via « Toutes les annotations ») -> select A, select B, Escape from a button of the side column: focus on B's row - a text field (panel « Nom (FR) ») -> the overview « Filtrer par nom » - redraw via the panel's « Remplacer par un polygone » -> the strip's command - modal / delete dialog opened by the panel's « Supprimer » -> « Supprimer » of the properties dialog - read-only width: hidden `annotation-properties` -> hidden strip « Propriétés » of the kept edit body editor-history-buttons.test.tsx (typed text and the press, 8 tests): the annotation's committed « Nom (FR) » field of the panel -> the sheet's committed « Nom (FR) » on Général (same TextField commit-on-blur path; annotation fields are now a dialog draft) editor-focus-request.test.tsx: « Aller à » focuses `data-properties-heading` inside `annotation-properties` -> focuses the annotation's row, marked aria-current, no dialog (R-5) editor-sections.test.tsx: « Aller à » with nothing in progress focused the properties heading -> focuses the row (R-5); creation kept: no `annotation-properties` -> no strip « Propriétés » editor-overview.test.tsx (edit and read-only): row opens `annotation-properties`, « Toutes les annotations » returns -> row selects, stays marked aria-current, no dialog; strip « Désélectionner » returns focus to the row; filter kept across select and « Désélectionner » editor-citations-guards.test.tsx: LAYERS_TOP_DOWN gains 'annotation' at the bottom editor-keep-alive.test.tsx: `annotation-properties` visible after the round trip -> the strip's « Propriétés » visible (selection kept) editor-no-loss.test.tsx: ids `ro-annotation-name-fr` and `annotation-name-fr` (both panels' fields) -> the twin's inline read body (no ids), then the dialog edit form's `annotation-edit-fr`, kept through a flip to 800 px, no duplicate id; « Aller à » visible `annotation-properties` -> visible `annotation-read` (inline twin), none at 1 280 editor-point-edit.test.tsx / editor-zone-edit.test.tsx: `select()` waited for `annotation-properties` and returned it -> waits for the strip's « Propriétés » and returns the strip (its « Désélectionner » and « Remplacer par un polygone » moved there) - move mode Escape: `annotation-properties` still there -> the strip's « Propriétés » back after the mode - « Toutes les annotations » asks first during a started move -> Enter on the selected row asks first (no dialog), and the strip offers neither « Propriétés » nor « Désélectionner » during the mode - Escape from the handle / slider: `annotation-properties` gone -> the strip's « Propriétés » gone - I-3 touch tap: `annotation-properties` gone -> the strip's « Propriétés » gone e2e (sandbox): - support/layout.ts: `aside-content` exemption removed (ShiftExemption type, the loose compare); every `swaps`/`SWAPS` argument removed (editor-annotations, editor-zones, editor-geometry) - support/editor.ts pickAnnotation: clicked « Toutes les annotations » first when the panel showed -> the overview is always shown: clicks the row, then scrolls back to the top (the page no longer shortens) - editor-annotations: `annotation-properties` visible after a creation -> strip with « Propriétés »; review toggle and « Supprimer » of the panel -> the properties dialog's; a jitter click on the selected point now opens the dialog (A1), closed by Escape before the drag; handle names exact (the marked row shares the prefix); trace close moved out of expectNoShift (creation panel until Task 7, shortcut + TODO) - editor-deselect: `annotation-properties` -> the strip with « Propriétés » or the twin's inline read body; Escape in a field: panel « Nom (FR) » -> overview filter; delete dialog from the panel -> from the properties dialog (Escape closes it, then the dialog); « a typed value is applied by the click that deselects » (name field, refused blank) -> a pending point-handle key series applied by the deselecting click and by « Désélectionner » (refused value: no field outside the dialog); « the selected one stays » -> a second click, double click and jitter open the dialog, Escape closes it, selection kept - editor-geometry: `annotation-geometry-issues` in the panel -> read in the properties dialog, then the strip notice; after the refusal the error count unchanged; scroll-to-top workaround removed - editor-zones: panel « Désélectionner » -> strip; scroll-to-top after pickAnnotation removed (helper does it) - editor-structures: panel « Supprimer » -> properties dialog « Supprimer », confirmation over it - editor-journey: `#annotation-name-fr` committed field + `#annotation-laterality` -> the dialog's edit form, one « Enregistrer »; scroll-to-top removed - editor-shell / editor-shell-journeys: « Aller à » focus on `data-properties-heading` -> the annotation's row (aria-current), no dialog (R-5) - editor-shell-layout: focus kind `annotation-properties` -> removed (the overview is the side)
648 lines
23 KiB
TypeScript
648 lines
23 KiB
TypeScript
/** U2 Task 4: the point handle, the size slider and the move mode in the Annotations tab. */
|
||
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 AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
|
||
import { guardDrawing } from '@/editor/annotations/drawingGuard'
|
||
import { useLocaleStore } from '@/state/localeStore'
|
||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||
import {
|
||
ASSET,
|
||
drawnText,
|
||
insert,
|
||
point,
|
||
svgBytes,
|
||
} from '../helpers/editorFixtures'
|
||
import {
|
||
USER,
|
||
VERSION,
|
||
openReady,
|
||
pressAt,
|
||
resetStore,
|
||
sb,
|
||
store,
|
||
versionAnswer,
|
||
} from '../helpers/editorHarness'
|
||
|
||
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(),
|
||
}))
|
||
|
||
const props = {
|
||
readOnly: false,
|
||
navigate: vi.fn(),
|
||
reloadSheet: vi.fn(),
|
||
section: 'drawing' as const,
|
||
visited: ['drawing'] as const,
|
||
onOpenSection: vi.fn(),
|
||
onBack: vi.fn(),
|
||
}
|
||
|
||
function UndoKeys() {
|
||
useUndoShortcuts(true)
|
||
return null
|
||
}
|
||
|
||
const annotations = () => store.getState().previewState!.document.annotations
|
||
const geometryOf = (id: string) =>
|
||
annotations().find((a: Annotation) => a.id === id)?.geometry
|
||
const depth = () => store.getState().undo.length
|
||
|
||
/** A change made elsewhere: the other point `b` moved through the store. */
|
||
const moveOther = () =>
|
||
store.getState().commit({
|
||
op: 'update',
|
||
key: { kind: 'annotation', id: 'b' },
|
||
element: point('b', 30, 30, 5),
|
||
})
|
||
|
||
function stubCtm(): void {
|
||
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 }),
|
||
})
|
||
}
|
||
|
||
beforeEach(() => {
|
||
useLocaleStore.setState({ locale: 'fr' })
|
||
stubCtm()
|
||
})
|
||
afterEach(() => {
|
||
cleanup()
|
||
resetStore()
|
||
resetWork()
|
||
})
|
||
|
||
/** A link circle on the main view, opening the detail view `view-det` it adds first. */
|
||
const withLink = (text: string, id: string) => {
|
||
const withView = insert(text, {
|
||
kind: 'view',
|
||
value: {
|
||
kind: 'detail',
|
||
id: 'view-det',
|
||
name: { fr: 'Tête', en: 'Head' },
|
||
svg_asset_id: null,
|
||
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
|
||
parent_view_id: 'view-main',
|
||
},
|
||
})
|
||
const value = {
|
||
id,
|
||
view_id: 'view-main',
|
||
category_id: 'cat-a',
|
||
laterality: 'unpaired',
|
||
geometry: { type: 'circle', cx: 70, cy: 70, r: 6 },
|
||
review_status: 'to_confirm',
|
||
color: null,
|
||
kind: 'detail_trigger',
|
||
name: null,
|
||
opens_view_id: 'view-det',
|
||
} as Annotation
|
||
return insert(withView, { kind: 'annotation', value })
|
||
}
|
||
|
||
const withPoints = (...points: ReturnType<typeof point>[]) =>
|
||
points.reduce((text, p) => insert(text, p), drawnText())
|
||
|
||
const tab = (readOnly = false) => (
|
||
// The Escape listener acts inside the editor workspace only.
|
||
<div data-editor-workspace>
|
||
<AnnotationsTab {...props} readOnly={readOnly} />
|
||
</div>
|
||
)
|
||
|
||
async function mount(text: string) {
|
||
await openReady({ text })
|
||
const view = render(tab())
|
||
await waitFor(() =>
|
||
expect(
|
||
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||
).not.toBeNull(),
|
||
)
|
||
return view
|
||
}
|
||
|
||
/** The same tab on a 4000 × 3000 drawing: the core gives the main view a minimum radius. */
|
||
async function mountLarge(text: string) {
|
||
const drawing = svgBytes('0 0 4000 3000')
|
||
sb.getSheetVersion.mockResolvedValue({
|
||
...versionAnswer(text, 3),
|
||
drawings: [{ asset_id: ASSET, sha256: drawing.sha256 }],
|
||
} as never)
|
||
sb.downloadSheetDrawing.mockResolvedValue(drawing.bytes)
|
||
store.getState().open(VERSION, USER, { canEdit: true })
|
||
await waitFor(() => expect(store.getState().status).toBe('ready'))
|
||
// The Escape listener acts inside the editor workspace only.
|
||
render(
|
||
<div data-editor-workspace>
|
||
<AnnotationsTab {...props} />
|
||
</div>,
|
||
)
|
||
await waitFor(() =>
|
||
expect(
|
||
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||
).not.toBeNull(),
|
||
)
|
||
}
|
||
|
||
async function select(index = 0) {
|
||
const list = await screen.findByRole('list', {
|
||
name: 'Annotations de la vue',
|
||
})
|
||
await userEvent.setup().click(within(list).getAllByRole('button')[index])
|
||
// U2 Task 6: a row selects only (A1); the strip holds the selection's commands.
|
||
await screen.findByRole('button', { name: 'Propriétés' })
|
||
return screen.getByTestId('edit-strip')
|
||
}
|
||
|
||
const slider = () =>
|
||
within(screen.getByTestId('size-slider')).getByRole('slider')
|
||
const handle = () => screen.getByRole('button', { name: 'Point N' })
|
||
const message = () => screen.getByTestId('gesture-line')
|
||
const moveButton = () =>
|
||
screen.getByRole('button', { name: 'Déplacer le point' })
|
||
const bar = () => screen.getByTestId('move-mode-bar')
|
||
const arrow = (name: string) =>
|
||
within(bar()).getByRole('button', { name: `Déplacer vers ${name}` })
|
||
|
||
describe('the size slider (R-10)', () => {
|
||
it('shows the view stops and the red mark at the core value', async () => {
|
||
await mountLarge(
|
||
withPoints(
|
||
point('a', 500, 500, 30),
|
||
point('b', 900, 500, 34),
|
||
point('c', 1500, 500, 34),
|
||
),
|
||
)
|
||
await select()
|
||
const minimum = store.getState().previewState!.min_point_radius['view-main']
|
||
expect(minimum).toBeGreaterThan(0)
|
||
expect(screen.getAllByTestId('size-stop')).toHaveLength(2)
|
||
expect(screen.getByTestId('size-minimum')).toHaveAttribute(
|
||
'data-value',
|
||
String(minimum),
|
||
)
|
||
const low = Math.round((Math.min(30, minimum) / 2) * 100) / 100
|
||
expect(slider()).toHaveAttribute('min', String(low))
|
||
expect(slider()).toHaveAttribute('max', '68')
|
||
})
|
||
|
||
it('has no red mark where the core gives no minimum', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5)))
|
||
await select()
|
||
expect(screen.queryByTestId('size-minimum')).toBeNull()
|
||
})
|
||
|
||
it('arrows and Page Up preview only; leaving the slider commits once', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5), point('b', 20, 20, 8)))
|
||
await select()
|
||
const before = depth()
|
||
fireEvent.keyDown(slider(), { key: 'ArrowRight' })
|
||
fireEvent.keyDown(slider(), { key: 'ArrowRight' })
|
||
expect(geometryOf('a')).toMatchObject({ r: 5 })
|
||
fireEvent.keyDown(slider(), { key: 'PageUp' })
|
||
expect(slider()).toHaveValue('8')
|
||
expect(depth()).toBe(before)
|
||
fireEvent.blur(slider())
|
||
expect(geometryOf('a')).toMatchObject({ r: 8 })
|
||
expect(depth()).toBe(before + 1)
|
||
expect(message()).toHaveTextContent('Taille modifiée')
|
||
})
|
||
|
||
it('a track click commits once at the release (WCAG 2.5.7)', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5)))
|
||
await select()
|
||
const before = depth()
|
||
fireEvent.change(slider(), { target: { value: '7' } })
|
||
expect(geometryOf('a')).toMatchObject({ r: 5 })
|
||
fireEvent.pointerUp(slider())
|
||
fireEvent.blur(slider())
|
||
expect(geometryOf('a')).toMatchObject({ r: 7 })
|
||
expect(depth()).toBe(before + 1)
|
||
})
|
||
|
||
it('Ctrl+Z on the slider cancels its preview, then undoes (R-13)', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5)))
|
||
render(<UndoKeys />)
|
||
await select()
|
||
fireEvent.change(slider(), { target: { value: '7' } })
|
||
fireEvent.keyDown(slider(), { key: 'z', ctrlKey: true })
|
||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||
expect(slider()).toHaveValue('5')
|
||
fireEvent.change(slider(), { target: { value: '7' } })
|
||
fireEvent.pointerUp(slider())
|
||
expect(geometryOf('a')).toMatchObject({ r: 7 })
|
||
fireEvent.keyDown(slider(), { key: 'z', ctrlKey: true })
|
||
expect(geometryOf('a')).toMatchObject({ r: 5 })
|
||
})
|
||
|
||
it('a value under the mark is refused by the core and restored in red', async () => {
|
||
await mountLarge(withPoints(point('a', 500, 500, 30)))
|
||
await select()
|
||
const before = depth()
|
||
fireEvent.change(slider(), { target: { value: '8' } })
|
||
fireEvent.pointerUp(slider())
|
||
expect(geometryOf('a')).toMatchObject({ r: 30 })
|
||
expect(depth()).toBe(before)
|
||
expect(slider()).toHaveValue('30')
|
||
expect(within(message()).getByRole('alert')).toHaveTextContent(
|
||
'Taille refusée',
|
||
)
|
||
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
|
||
})
|
||
})
|
||
|
||
describe('the move mode (A11, R-12, R-13)', () => {
|
||
const two = () => withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5))
|
||
|
||
it('its arrows commit nothing until « Valider la position », which commits once', async () => {
|
||
await mount(two())
|
||
await select()
|
||
const before = depth()
|
||
await userEvent.setup().click(moveButton())
|
||
expect(document.activeElement).toBe(arrow('la gauche'))
|
||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||
'Déplacer le point',
|
||
)
|
||
fireEvent.click(arrow('la droite'))
|
||
fireEvent.click(arrow('la droite'))
|
||
fireEvent.click(arrow('le bas'))
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50, cy: 50 })
|
||
expect(screen.getByTestId('overlay-old-place')).toBeInTheDocument()
|
||
expect(depth()).toBe(before)
|
||
fireEvent.click(
|
||
within(bar()).getByRole('button', { name: 'Valider la position' }),
|
||
)
|
||
expect(geometryOf('a')).toMatchObject({ cx: 51, cy: 50.5 })
|
||
expect(depth()).toBe(before + 1)
|
||
expect(message()).toHaveTextContent('Point déplacé')
|
||
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
|
||
})
|
||
|
||
it('« Annuler » restores the place, the focus back on « Déplacer le point »', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
fireEvent.click(within(bar()).getByRole('button', { name: 'Annuler' }))
|
||
expect(useAnnotationWork.getState()).toMatchObject({
|
||
mode: null,
|
||
preview: null,
|
||
})
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||
await waitFor(() => expect(document.activeElement).toBe(moveButton()))
|
||
})
|
||
|
||
it('Escape restores the place', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
fireEvent.keyDown(arrow('la droite'), { key: 'Escape' })
|
||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
|
||
expect(
|
||
screen.getByRole('button', { name: 'Propriétés' }),
|
||
).toBeInTheDocument()
|
||
})
|
||
|
||
it('a click on another annotation selects nothing during the mode', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
const other = screen
|
||
.getByTestId('annotation-canvas-drawing')
|
||
.querySelector('[data-anno-id="b"]')!
|
||
const init = {
|
||
pointerId: 1,
|
||
isPrimary: true,
|
||
button: 0,
|
||
buttons: 1,
|
||
pointerType: 'mouse',
|
||
}
|
||
fireEvent.pointerDown(other, { ...init, clientX: 20, clientY: 20 })
|
||
fireEvent.pointerUp(other, { ...init, clientX: 20, clientY: 20 })
|
||
expect(useAnnotationWork.getState().mode?.annotationId).toBe('a')
|
||
expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument()
|
||
})
|
||
|
||
it('a drag anywhere moves the mode preview and commits nothing', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
const box = screen.getByTestId('annotation-canvas')
|
||
const init = {
|
||
pointerId: 1,
|
||
isPrimary: true,
|
||
button: 0,
|
||
buttons: 1,
|
||
pointerType: 'touch',
|
||
}
|
||
fireEvent.pointerDown(box, { ...init, clientX: 80, clientY: 80 })
|
||
fireEvent.pointerMove(box, { ...init, clientX: 92, clientY: 80 })
|
||
fireEvent.pointerUp(box, { ...init, clientX: 92, clientY: 80 })
|
||
expect(useAnnotationWork.getState().preview?.geometry).toMatchObject({
|
||
cx: 62,
|
||
})
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||
})
|
||
|
||
it('Ctrl+Z only cancels it; a later Enter on the handle commits nothing', async () => {
|
||
await mount(two())
|
||
render(<UndoKeys />)
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
const before = depth()
|
||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||
expect(useAnnotationWork.getState()).toMatchObject({
|
||
mode: null,
|
||
preview: null,
|
||
})
|
||
expect(depth()).toBe(before)
|
||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||
expect(depth()).toBe(before)
|
||
})
|
||
|
||
it('a document change during the mode drops it and says so', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
act(() => void moveOther())
|
||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||
expect(
|
||
await screen.findByText('Déplacement abandonné : la fiche a changé.'),
|
||
).toBeInTheDocument()
|
||
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
|
||
})
|
||
})
|
||
|
||
describe('the point handle (R-9, R-11)', () => {
|
||
it('is a focusable button outside any aria-hidden subtree, named « Point {nom} »', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5)))
|
||
await select()
|
||
expect(handle()).toHaveAttribute('tabindex', '0')
|
||
expect(handle().closest('[aria-hidden="true"]')).toBeNull()
|
||
})
|
||
|
||
it('arrows move a preview only (no pan), Enter commits once; Shift ×10', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5)))
|
||
await select()
|
||
const before = depth()
|
||
const transform = () =>
|
||
(screen.getByTestId('annotation-canvas').firstElementChild as HTMLElement)
|
||
.style.transform
|
||
const panned = transform()
|
||
handle().focus()
|
||
fireEvent.keyDown(handle(), { key: 'ArrowRight' })
|
||
fireEvent.keyDown(handle(), { key: 'ArrowDown', shiftKey: true })
|
||
expect(transform()).toBe(panned)
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50, cy: 50 })
|
||
expect(depth()).toBe(before)
|
||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50.5, cy: 55 })
|
||
expect(depth()).toBe(before + 1)
|
||
})
|
||
|
||
it('leaving the handle commits the series (BDR-050); Escape drops it', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5)))
|
||
await select()
|
||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||
fireEvent.keyDown(handle(), { key: 'Escape' })
|
||
expect(useAnnotationWork.getState().preview).toBeNull()
|
||
fireEvent.blur(handle())
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||
fireEvent.blur(handle())
|
||
expect(geometryOf('a')).toMatchObject({ cx: 49.5 })
|
||
})
|
||
|
||
it('a stale series never commits (R-13)', async () => {
|
||
await mount(withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5)))
|
||
await select()
|
||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||
act(() => void moveOther())
|
||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50 })
|
||
})
|
||
})
|
||
|
||
describe('A5: a new point takes the most used size', () => {
|
||
const sized = () =>
|
||
withPoints(
|
||
point('a', 20, 20, 7),
|
||
point('b', 40, 40, 7),
|
||
point('c', 60, 60, 9),
|
||
)
|
||
|
||
it('the keyboard point and the Point tool click', async () => {
|
||
await mount(sized())
|
||
const user = userEvent.setup()
|
||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||
const panel = await screen.findByTestId('annotation-creation')
|
||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('7')
|
||
})
|
||
|
||
it('the Point tool shows the slider at that size; a new size feeds the click', async () => {
|
||
await mount(sized())
|
||
const user = userEvent.setup()
|
||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||
expect(slider()).toHaveValue('7')
|
||
fireEvent.change(slider(), { target: { value: '9' } })
|
||
expect(slider()).toHaveValue('9')
|
||
})
|
||
})
|
||
|
||
describe('review fixes: no silent loss, no empty commit, no lost focus', () => {
|
||
const two = () => withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5))
|
||
const started = async () => {
|
||
const view = await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
return view
|
||
}
|
||
const question = () => useAnnotationWork.getState().question?.work ?? null
|
||
|
||
it('Enter on the selected row, a tool and « Ajouter un point » ask first', async () => {
|
||
await started()
|
||
// During the mode the strip offers only its exits (U2 Task 6: no « Propriétés »).
|
||
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
|
||
expect(screen.queryByRole('button', { name: 'Désélectionner' })).toBeNull()
|
||
const list = screen.getByRole('list', { name: 'Annotations de la vue' })
|
||
const row = within(list).getByRole('button', { current: true })
|
||
fireEvent.keyDown(row, { key: 'Enter' })
|
||
expect(question()).toBe('move')
|
||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||
expect(screen.queryByRole('dialog')).toBeNull()
|
||
act(() => useAnnotationWork.setState({ question: null }))
|
||
fireEvent.click(screen.getByRole('button', { name: 'Point' }))
|
||
expect(question()).toBe('move')
|
||
expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument()
|
||
act(() => useAnnotationWork.setState({ question: null }))
|
||
fireEvent.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||
expect(question()).toBe('move')
|
||
expect(screen.queryByTestId('annotation-creation')).toBeNull()
|
||
})
|
||
|
||
it('an unstarted mode ends at once on a tool change', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(screen.getByRole('button', { name: 'Point' }))
|
||
expect(question()).toBeNull()
|
||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||
})
|
||
|
||
it('a series back on its place and a slider pinned at its stop commit nothing', async () => {
|
||
await mount(two())
|
||
await select()
|
||
const before = depth()
|
||
fireEvent.keyDown(handle(), { key: 'ArrowRight' })
|
||
fireEvent.keyDown(handle(), { key: 'ArrowLeft' })
|
||
fireEvent.keyDown(handle(), { key: 'Enter' })
|
||
fireEvent.keyDown(slider(), { key: 'PageUp' })
|
||
fireEvent.blur(slider())
|
||
expect(depth()).toBe(before)
|
||
expect(message()).not.toHaveTextContent('Défaire')
|
||
})
|
||
|
||
it('Escape deselecting from the handle or the slider keeps a focus', async () => {
|
||
await mount(two())
|
||
await select()
|
||
handle().focus()
|
||
fireEvent.keyDown(handle(), { key: 'Escape' })
|
||
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
|
||
expect(document.activeElement).not.toBe(document.body)
|
||
await select()
|
||
slider().focus()
|
||
fireEvent.keyDown(slider(), { key: 'Escape' })
|
||
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
|
||
expect(document.activeElement).not.toBe(document.body)
|
||
})
|
||
|
||
it('R-14: a read-only flip suspends a started mode; it resumes and commits after', async () => {
|
||
const view = await started()
|
||
const before = depth()
|
||
view.rerender(tab(true))
|
||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||
view.rerender(tab(false))
|
||
expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument()
|
||
fireEvent.click(
|
||
within(bar()).getByRole('button', { name: 'Valider la position' }),
|
||
)
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50.5 })
|
||
expect(depth()).toBe(before + 1)
|
||
})
|
||
|
||
it('a link circle keeps its handle (« Accès … ») but gets no size and no move mode', async () => {
|
||
await mount(withLink(two(), 'l'))
|
||
await select(2)
|
||
expect(screen.getByTestId('point-handle')).toHaveAccessibleName(/^Accès /)
|
||
expect(screen.queryByTestId('size-slider')).toBeNull()
|
||
expect(
|
||
screen.queryByRole('button', { name: 'Déplacer le point' }),
|
||
).toBeNull()
|
||
})
|
||
})
|
||
|
||
describe('A5 through the Point tool click', () => {
|
||
const sized = () =>
|
||
withPoints(
|
||
point('a', 20, 20, 7),
|
||
point('b', 40, 40, 7),
|
||
point('c', 60, 60, 9),
|
||
)
|
||
|
||
it('a click places the point at the most used size', async () => {
|
||
await mount(sized())
|
||
const user = userEvent.setup()
|
||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||
pressAt(screen.getByTestId('annotation-canvas'), 50, 80)
|
||
const panel = await screen.findByTestId('annotation-creation')
|
||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('7')
|
||
})
|
||
|
||
it('a size chosen on the slider before the click feeds it', async () => {
|
||
await mount(sized())
|
||
const user = userEvent.setup()
|
||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||
fireEvent.change(slider(), { target: { value: '9' } })
|
||
pressAt(screen.getByTestId('annotation-canvas'), 50, 80)
|
||
const panel = await screen.findByTestId('annotation-creation')
|
||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('9')
|
||
})
|
||
})
|
||
|
||
describe('fix round 1: no silent loss on the way out', () => {
|
||
const two = () => withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5))
|
||
|
||
it('a guarded navigation commits a keyboard series the handle still holds', async () => {
|
||
await mount(two())
|
||
await select()
|
||
const before = depth()
|
||
handle().focus()
|
||
fireEvent.keyDown(handle(), { key: 'ArrowRight' })
|
||
act(() => void guardDrawing(() => undefined))
|
||
expect(geometryOf('a')).toMatchObject({ cx: 50.5 })
|
||
expect(depth()).toBe(before + 1)
|
||
})
|
||
|
||
it('a pending size the focus already left is kept, not dropped', async () => {
|
||
await mount(two())
|
||
await select()
|
||
fireEvent.change(slider(), { target: { value: '7' } })
|
||
screen.getByTestId('annotation-canvas').focus()
|
||
act(() => void guardDrawing(() => undefined))
|
||
expect(useAnnotationWork.getState().preview).toMatchObject({
|
||
source: 'size',
|
||
})
|
||
})
|
||
|
||
it('a started move ended by a selection change is said, never silent', async () => {
|
||
await mount(two())
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
const mode = useAnnotationWork.getState().mode!
|
||
act(() =>
|
||
useAnnotationWork.setState({ mode: { ...mode, annotationId: 'b' } }),
|
||
)
|
||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||
expect(
|
||
await screen.findByText('Déplacement abandonné : la fiche a changé.'),
|
||
).toBeInTheDocument()
|
||
})
|
||
|
||
it('a view chip asks before a started move goes', async () => {
|
||
await mount(withLink(two(), 'l'))
|
||
await select()
|
||
await userEvent.setup().click(moveButton())
|
||
fireEvent.click(arrow('la droite'))
|
||
const views = screen.getByRole('group', { name: 'Vues' })
|
||
fireEvent.click(within(views).getByRole('button', { name: 'Tête' }))
|
||
expect(useAnnotationWork.getState().question?.work).toBe('move')
|
||
expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument()
|
||
})
|
||
})
|