Files
faunosteo/apps/app/tests/unit/editor-point-edit.test.tsx
T
bchanot 4d2c64f57f feat(editor): creation on the drawing then the creation dialog
U2 Task 7 (A2, A4, A5, A7, A12, A15; R-3, R-4, R-12, R-13, R-14).
The work store's `creation` owns the new shape, its form, its view and
F: a click with the point tool, a closed tracing or a keyboard
« Ajouter … » opens « Nouveau point / zone / accès », a modal without
a history layer over the right column, mounted beside EditOnly so a
read-only flip keeps it (« Créer », « Replacer », « Reprendre » off).
A new zone or link is a creation from its first vertex. The ghost
takes the form's category colour; the point tool previews under a
mouse; the canvas carries data-creating (other markers dimmed,
unselectable). « Replacer le point » / « Reprendre le tracé » hide the
dialog and keep the form; the strip offers « Revenir aux propriétés »,
« Retirer le dernier sommet », « Abandonner ». « Créer »: one insert,
tool back to « Sélectionner », the new element selected, « Point
créé · Défaire », focus on its row. ✕, Échap, « Abandonner » and Back
always ask « Abandonner la création ? » (DiscardConfirm inside the
dialog; DrawingGuardDialog elsewhere); answerDrawing drops the
creation. Undo, its shortcuts and the line's « Défaire » are inactive
during a creation. missingFields replaces formProblem (MissingSummary
shared with the edit form); the C26 notice has no numbers.
CreationPanel, formProblem, withGeometry and the keys required.fields,
required.names and create_cancel are gone; GeometryGroup is imported
by RepairDialog only.

Removed or rewritten assertions:
- tab « holds a point at the frame centre »: « Centre x » = 50 ->
  the ghost circle cx = 50; plus tool back to Sélectionner, « Point
  créé », one undo step.
- tab « refuses a creation without laterality »: the general line
  « Choisissez la catégorie et la latéralité » -> only « Choisissez
  une latéralité. » and « À compléter : Latéralité. », focus on it.
- tab « applies the geometry group to a pending zone »: removed (A8,
  no coordinate field) -> « places a triangle at the centre: the ghost
  shows it, Créer inserts it »; vertex edits after Créer are the e2e
  keyboard test.
- tab C26 « proposes C »: « x = 15, y = 15 » in the notice -> the R-4
  text, the notice inside the dialog; cancel test « Centre x » = 0 ->
  ghost cx = 0.
- tab « offers the correction when the core refuses a pending point »
  (typed cx 98): removed, no typed coordinate is possible; the verdict
  path stays covered by the C26 click tests and correctionFor units.
- tab H5 « a typed radius shows the core issue »: removed (A8); the
  size refusal is the slider's (Task 4 tests).
- tab H6 « a second click moves the pending point »: -> « Replacer le
  point », then the click moves the ghost, the form kept.
- tab H7 « Centre x/y » = 30/50 -> ghost cx/cy.
- tab tracing Enter: « x du sommet 3 » -> ghost points; « drops the
  tracing on Escape » -> Escape asks first (board 32 row 3), Continuer
  keeps, Abandonner drops; new « Annuler le tracé acts at once ».
- keep-alive « a pending creation is kept and focused » and « a
  tracing … is kept and focused »: the tab now asks first (R-12) ->
  « Continuer » keeps the tracing / the form, « Abandonner » goes.
- sections « its panel takes the focus » -> its dialog's
  [data-creation-focus] takes it.
- no-loss « pending creation with its name » (hidden with the body) ->
  the dialog stays across the crossing, read-only, Créer off (R-14).
- point-edit A5 « Rayon » = 7 / 9 -> ghost r = 7 / 9.
- e2e editor-annotations keyboard test « numeric position » (cx field
  250) -> UX_TESTS Keyboard: zone added, vertex added and removed,
  moved by the move mode, validated, saved. The « Fermer le tracé »
  step runs under expectNoShift again (shortcut removed).
- e2e editor-geometry C26: the proposed x, y read from the notice
  text -> from the overlay's correction circle; the R-4 text checked
  in the dialog.
- e2e editor-deselect « Escape cancels the tracing only » -> Escape
  asks, « Abandonner » cancels it, the selection kept.
- e2e editor-shell-crossing « keeps its tool and its pending
  creation » (field hidden) -> the dialog stays read-only, Créer off,
  then editable on widening.
2026-11-17 23:32:42 +01:00

675 lines
24 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 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' }))
await screen.findByTestId('annotation-creation')
// A8: no « Rayon » field; the ghost under the dialog has the size.
expect(
screen.getByTestId('overlay-ghost').querySelector('circle'),
).toHaveAttribute('r', '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('another row or a view row of the overview asks first (A3: the column stays shown)', async () => {
await started()
const list = screen.getByRole('list', { name: 'Annotations de la vue' })
const rows = within(list).getAllByRole('button')
const other = rows.find(
(row) => row.getAttribute('aria-current') !== 'true',
)!
fireEvent.click(other)
expect(question()).toBe('move')
expect(useAnnotationWork.getState().mode?.started).toBe(true)
expect(within(list).getByRole('button', { current: true })).not.toBe(other)
act(() => useAnnotationWork.setState({ question: null }))
const views = screen
.getByRole('heading', { name: 'Vues' })
.closest('section')!
fireEvent.click(within(views).getAllByRole('button')[0]!)
expect(question()).toBe('move')
expect(screen.getByTestId('move-mode-bar')).toBeInTheDocument()
})
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)
await screen.findByTestId('annotation-creation')
expect(
screen.getByTestId('overlay-ghost').querySelector('circle'),
).toHaveAttribute('r', '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)
await screen.findByTestId('annotation-creation')
expect(
screen.getByTestId('overlay-ghost').querySelector('circle'),
).toHaveAttribute('r', '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()
})
})