feat(editor): properties dialog over the column, transactional save

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)
This commit is contained in:
bchanot committed 2026-11-17 22:01:57 +01:00
1 parent e596e0765e
commit cd794f3c39
66 files changed
+3351 -1357

No files matched your search

@@ -0,0 +1,52 @@
/** U2 Task 6, R-3: only what is really missing, in the form's order (board 33 adjustment 3). */
import { describe, expect, it } from 'vitest'
import type { CreationForm } from '@/editor/annotations/creation'
import { missingFields } from '@/editor/annotations/missingFields'
const form = (patch: Partial<CreationForm> = {}): CreationForm => ({
fr: 'Grasset',
en: 'Stifle',
categoryId: 'cat-1',
laterality: 'bilateral',
opensViewId: '',
zoneId: '',
regionCode: '',
...patch,
})
describe('missingFields', () => {
it('a full point or zone misses nothing', () => {
expect(missingFields('point', form())).toEqual([])
expect(missingFields('zone', form())).toEqual([])
})
it('a chosen category is never listed; only the laterality is', () => {
expect(missingFields('point', form({ laterality: '' }))).toEqual([
'laterality',
])
})
it('a link with both names blank is fine; with one blank it names that one', () => {
const link = form({ fr: ' ', en: '', opensViewId: 'head' })
expect(missingFields('detail_trigger', link)).toEqual([])
const half = form({ fr: '', opensViewId: 'head' })
expect(missingFields('detail_trigger', half)).toEqual(['name_fr'])
})
it('names, category, laterality, opened view: in the form’s order', () => {
const empty = form({ fr: '', en: 'x', categoryId: '', laterality: '' })
expect(missingFields('detail_trigger', empty)).toEqual([
'name_fr',
'category',
'laterality',
'opens',
])
const blank = form({ fr: '', en: ' ', categoryId: '', laterality: '' })
expect(missingFields('point', blank)).toEqual([
'name_fr',
'name_en',
'category',
'laterality',
])
})
})
@@ -0,0 +1,497 @@
/** U2 Task 6: the properties dialog over the column (A1, A2, A3, A9, A10, R-3, R-14, R-16). */
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, Point } from '@faunosteo/core-wasm/types'
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
import { useLocaleStore } from '@/state/localeStore'
import { LayeredTab, layered } from '../helpers/annotationLayer'
import { drawnText, insert, point } from '../helpers/editorFixtures'
import { openReady, pressAt, resetStore, store } 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 = {
navigate: vi.fn(),
reloadSheet: vi.fn(),
section: 'drawing' as const,
visited: ['drawing'] as const,
onOpenSection: vi.fn(),
onBack: vi.fn(),
}
const SQUARE: Point[] = [
[20, 20],
[80, 20],
[80, 80],
[20, 80],
]
const annotationOf = (id: string) =>
store
.getState()
.previewState!.document.annotations.find((a: Annotation) => a.id === id)!
const depth = () => store.getState().undo.length
const zone = (id: string, patch: Partial<Annotation> = {}): Annotation =>
({
...(point(id, 0, 0, 1).value as Annotation),
kind: 'zone',
geometry: { type: 'polygon', points: SQUARE },
...patch,
}) as Annotation
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()
window.innerWidth = 1024
})
const tab = (readOnly = false) => (
<div data-editor-workspace>
<LayeredTab {...props} readOnly={readOnly} />
</div>
)
async function mount(text: string, readOnly = false) {
await openReady({ text })
const view = render(tab(readOnly))
const drawing = readOnly
? 'catalogue-canvas-drawing'
: 'annotation-canvas-drawing'
await waitFor(() =>
expect(screen.getByTestId(drawing).querySelector('svg')).not.toBeNull(),
)
return view
}
const rowOf = (id: string) =>
document.querySelector<HTMLElement>(
`[data-focus-key='{"kind":"annotation","id":"${id}"}']`,
)!
const strip = () => screen.getByTestId('edit-strip')
const dialog = () => screen.queryByRole('dialog')
const live = () => screen.getByTestId('live-region')
const marker = (id: string) =>
screen
.getByTestId('annotation-canvas-drawing')
.querySelector(`[data-anno-id="${id}"]`)!
async function selectRow(id: string) {
await userEvent.setup().click(rowOf(id))
await within(strip()).findByRole('button', { name: 'Propriétés' })
}
async function openProperties() {
await userEvent
.setup()
.click(within(strip()).getByRole('button', { name: 'Propriétés' }))
return screen.findByRole('dialog')
}
async function startEdit() {
const opened = await openProperties()
await userEvent
.setup()
.click(within(opened).getByRole('button', { name: 'Modifier' }))
return opened
}
const field = (label: string) =>
within(dialog()!).getByLabelText(label) as HTMLInputElement
describe('opening (A1)', () => {
it('a first click and Enter on a row only select; Enter on the selected row opens', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
expect(dialog()).toBeNull()
expect(rowOf('a')).toHaveAttribute('aria-current', 'true')
fireEvent.keyDown(rowOf('a'), { key: 'Enter', repeat: true })
expect(dialog()).toBeNull()
fireEvent.keyDown(rowOf('a'), { key: 'Enter' })
expect(await screen.findByRole('dialog', { name: 'N' })).toBeVisible()
})
it('a second click on the interior opens; with a chosen vertex it unchooses only', async () => {
await mount(insert(drawnText(), { kind: 'annotation', value: zone('z') }))
await selectRow('z')
useAnnotationWork.setState({
chosen: {
annotationId: 'z',
vertex: 1,
base: store.getState().documentText,
},
})
pressAt(marker('z'), 50, 50)
expect(useAnnotationWork.getState().chosen).toBeNull()
expect(dialog()).toBeNull()
await new Promise((resolve) => setTimeout(resolve, 450))
pressAt(marker('z'), 50, 50)
expect(await screen.findByRole('dialog')).toBeVisible()
})
it('« Propriétés » opens it; ✕ closes it and the focus goes back to the button', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
const opened = await openProperties()
await userEvent
.setup()
.click(within(opened).getByRole('button', { name: 'Fermer' }))
await waitFor(() => expect(dialog()).toBeNull())
await waitFor(() =>
expect(document.activeElement).toBe(
within(strip()).getByRole('button', { name: 'Propriétés' }),
),
)
// The selection stays after the close.
expect(rowOf('a')).toHaveAttribute('aria-current', 'true')
})
})
describe('the read mode (board 31 A, B)', () => {
const rows = () =>
within(dialog()!)
.getAllByRole('term')
.map((term) => term.textContent)
it('a point: names, category, laterality, findings zone and view; no colour, no region', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await openProperties()
expect(rows()).toEqual([
'Nom (FR)',
'Nom (EN)',
'Catégorie',
'Latéralité',
'Zone de constats',
'Vue',
])
expect(within(dialog()!).getByTestId('annotation-read')).toHaveTextContent(
'Point',
)
})
it('a zone with its own colour and a region shows both', async () => {
const text = insert(drawnText(), {
kind: 'annotation',
value: zone('z', { color: '#aa0000' }),
})
const regions = JSON.parse(text)
const code = regions.vertebral_config.regions[0]?.code ?? null
const value = zone('z', {
color: '#aa0000',
vertebral_region_code: code,
} as Partial<Annotation>)
await mount(insert(drawnText(), { kind: 'annotation', value } as never))
await selectRow('z')
await openProperties()
expect(rows()).toContain('Couleur')
if (code !== null) expect(rows()).toContain('Région vertébrale')
expect(within(dialog()!).getByText('#aa0000')).toBeInTheDocument()
})
it('« Marquer comme relu » is one change and one undo (A10)', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
const opened = await openProperties()
const before = depth()
await userEvent
.setup()
.click(within(opened).getByRole('button', { name: 'Marquer comme relu' }))
expect(annotationOf('a').review_status).toBe('reviewed')
expect(depth()).toBe(before + 1)
expect(
within(opened).getByRole('button', { name: 'Remettre à confirmer' }),
).toBeInTheDocument()
act(() => void store.getState().undoStep())
expect(annotationOf('a').review_status).toBe('to_confirm')
})
it('the issues block names the inherited out-of-frame point', async () => {
await mount(insert(drawnText(), point('a', 150, 150, 5)))
await selectRow('a')
const opened = await openProperties()
expect(
within(opened).getByTestId('annotation-geometry-issues'),
).toHaveAttribute('role', 'alert')
})
it('« Modifier la forme » closes it, keeps the selection, focuses the first handle', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
const opened = await openProperties()
await userEvent
.setup()
.click(within(opened).getByRole('button', { name: 'Modifier la forme' }))
await waitFor(() => expect(dialog()).toBeNull())
await waitFor(() =>
expect(document.activeElement).toBe(screen.getByTestId('point-handle')),
)
expect(rowOf('a')).toHaveAttribute('aria-current', 'true')
})
})
describe('the edit form (board 31 C, R-3)', () => {
it('category and both names saved: ONE history entry, the read mode back', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
const user = userEvent.setup()
const before = depth()
await user.clear(field('Nom (FR)'))
await user.type(field('Nom (FR)'), 'Grasset')
await user.clear(field('Nom (EN)'))
await user.type(field('Nom (EN)'), 'Stifle')
const category = within(dialog()!).getByLabelText(
'Catégorie',
) as HTMLSelectElement
const other = [...category.options].find((o) => !o.selected)
if (other) await user.selectOptions(category, other.value)
expect(depth()).toBe(before)
await user.click(
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
)
expect(depth()).toBe(before + 1)
expect(annotationOf('a').name).toEqual({ fr: 'Grasset', en: 'Stifle' })
if (other) expect(annotationOf('a').category_id).toBe(other.value)
expect(
within(dialog()!).getByText('Modifications enregistrées'),
).toBeInTheDocument()
})
it('the save merges onto the current annotation: a move made meanwhile stays', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
const user = userEvent.setup()
await user.type(field('Nom (FR)'), 'x')
const moved = {
...annotationOf('a'),
geometry: { type: 'circle', cx: 40, cy: 50, r: 5 },
}
act(
() =>
void store.getState().commit({
op: 'update',
key: { kind: 'annotation', id: 'a' },
element: { kind: 'annotation', value: moved as Annotation },
}),
)
await user.click(
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
)
expect(annotationOf('a').geometry).toMatchObject({ cx: 40 })
expect(annotationOf('a').name?.fr).toBe('Nx')
})
it('a blank name: named under its field and in the summary, focused, nothing written', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
const user = userEvent.setup()
const before = store.getState().documentText
await user.clear(field('Nom (EN)'))
await user.click(
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
)
expect(
within(dialog()!).getByText('Saisissez le nom en anglais.'),
).toBeInTheDocument()
expect(
within(dialog()!).getByText('À compléter : Nom (EN).'),
).toHaveAttribute('role', 'alert')
expect(within(dialog()!).queryByText(/Choisissez/)).toBeNull()
expect(document.activeElement).toBe(field('Nom (EN)'))
expect(store.getState().documentText).toBe(before)
})
it('« Annuler » with changes asks; « Abandonner » writes nothing', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
const user = userEvent.setup()
const before = store.getState().documentText
await user.type(field('Nom (FR)'), 'x')
await user.click(within(dialog()!).getByRole('button', { name: 'Annuler' }))
expect(
within(dialog()!).getByText('Abandonner les modifications ?'),
).toBeInTheDocument()
await user.click(
within(dialog()!).getByRole('button', { name: 'Abandonner' }),
)
expect(store.getState().documentText).toBe(before)
expect(
within(dialog()!).getByRole('button', { name: 'Modifier' }),
).toBeInTheDocument()
})
it('« Couleur » sits in the form with the category’s placeholder (A9)', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
expect(field('Couleur')).toHaveAttribute(
'placeholder',
'Celle de la catégorie',
)
})
})
describe('a read-only flip (R-14, Review Focus 3)', () => {
it('the dialog stays with its draft, read-only, nothing committed; editable on the way back', async () => {
const view = await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
const user = userEvent.setup()
await user.type(field('Nom (FR)'), 'x')
const before = store.getState().documentText
view.rerender(tab(true))
expect(dialog()).not.toBeNull()
expect(field('Nom (FR)')).toHaveValue('Nx')
expect(field('Nom (FR)')).toHaveAttribute('readonly')
expect(within(dialog()!).getByLabelText('Catégorie')).toBeDisabled()
expect(
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
).toBeDisabled()
expect(store.getState().documentText).toBe(before)
view.rerender(tab(false))
expect(field('Nom (FR)')).toHaveValue('Nx')
expect(field('Nom (FR)')).not.toHaveAttribute('readonly')
await user.click(
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
)
expect(annotationOf('a').name?.fr).toBe('Nx')
})
it('a started move mode is suspended and resumes with its position', async () => {
const view = await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
const user = userEvent.setup()
await user.click(screen.getByRole('button', { name: 'Déplacer le point' }))
fireEvent.click(
screen.getByRole('button', { name: 'Déplacer vers la droite' }),
)
view.rerender(tab(true))
expect(useAnnotationWork.getState().mode?.started).toBe(true)
view.rerender(tab(false))
await user.click(
screen.getByRole('button', { name: 'Valider la position' }),
)
expect(annotationOf('a').geometry).toMatchObject({ cx: 50.5 })
})
})
describe('a read-only sheet at 1 024 px and wider (R-16)', () => {
it('the strip says « fiche en lecture seule »; « Propriétés » opens values only', async () => {
window.innerWidth = 1280
await mount(insert(drawnText(), point('a', 50, 50, 5)), true)
await userEvent.setup().click(rowOf('a'))
expect(
await within(strip()).findByTestId('edit-strip-detail'),
).toHaveTextContent('Point · fiche en lecture seule')
expect(screen.queryByTestId('point-handle')).toBeNull()
expect(screen.queryByTestId('size-slider')).toBeNull()
const opened = await openProperties()
expect(within(opened).getByTestId('annotation-read')).toBeInTheDocument()
expect(
within(opened).queryByRole('button', { name: 'Modifier' }),
).toBeNull()
expect(
within(opened).queryByRole('button', { name: 'Supprimer' }),
).toBeNull()
})
it('below 1 024 px the twin reads it inline, with no strip', async () => {
window.innerWidth = 800
await mount(insert(drawnText(), point('a', 50, 50, 5)), true)
await userEvent.setup().click(rowOf('a'))
expect(await screen.findByTestId('annotation-read')).toBeInTheDocument()
expect(screen.getByTestId('annotation-selection-tag')).toBeInTheDocument()
expect(screen.queryByTestId('edit-strip')).toBeNull()
})
})
describe('the layer (history)', () => {
it('an annotation that vanished closes the dialog and is said', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await openProperties()
act(
() =>
void store
.getState()
.commit({ op: 'remove', key: { kind: 'annotation', id: 'a' } }),
)
await waitFor(() => expect(dialog()).toBeNull())
await waitFor(() =>
expect(live()).toHaveTextContent("Cette annotation n'existe plus"),
)
expect(layered.nav?.state.annotation).toBeNull()
})
it('a layer for an annotation of another view shows that view and selects it', async () => {
const detail = insert(drawnText(), {
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 text = insert(
insert(detail, point('a', 50, 50, 5)),
point('b', 40, 40, 5, 'view-det'),
)
await mount(text)
act(() => layered.nav!.openAnnotation('b'))
await waitFor(() =>
expect(rowOf('b')).toHaveAttribute('aria-current', 'true'),
)
expect(
screen.getByRole('button', { name: 'Tête', pressed: true }),
).toBeInTheDocument()
})
it('a deletion from the dialog closes it, unsaid as a vanish', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
const opened = await openProperties()
const user = userEvent.setup()
await user.click(within(opened).getByRole('button', { name: 'Supprimer' }))
const ask = await screen.findByRole('dialog', { name: /Supprimer/ })
await user.click(within(ask).getByRole('button', { name: 'Supprimer' }))
await waitFor(() => expect(screen.queryAllByRole('dialog')).toHaveLength(0))
expect(live()).not.toHaveTextContent("n'existe plus")
})
})
@@ -27,6 +27,7 @@ import {
point,
svgBytes,
} from '../helpers/editorFixtures'
import { LayeredTab } from '../helpers/annotationLayer'
import {
USER,
VERSION,
@@ -61,8 +62,6 @@ const props = {
const named = (id: string, cx: number, cy: number, r: number) =>
point(id, cx, cy, r)
const annotations = () => store.getState().previewState!.document.annotations
const nameOf = (id: string) =>
annotations().find((a: Annotation) => a.id === id)?.name?.fr
const geometryOf = (id: string) =>
annotations().find((a: Annotation) => a.id === id)?.geometry
/** The selection as the overlay draws it (U2 Task 5: no coordinate field in the panel). */
@@ -106,7 +105,7 @@ const text = () => insert(drawnText(), named('anno-a', 50, 50, 5))
async function mount(options: { text?: string; readOnly?: boolean } = {}) {
await openReady({ text: options.text ?? text() })
render(<AnnotationsTab {...props} readOnly={options.readOnly ?? false} />)
render(<LayeredTab {...props} readOnly={options.readOnly ?? false} />)
const drawing = options.readOnly
? 'catalogue-canvas-drawing'
: 'annotation-canvas-drawing'
@@ -121,7 +120,17 @@ async function selectFromList(name: RegExp | string = /N/) {
})
await userEvent.setup().click(within(list).getAllByRole('button')[0])
void name
return screen.findByTestId('annotation-properties')
// A1: a row selects only; the strip names the selection (the dialog stays closed).
await screen.findByRole('button', { name: 'Propriétés' })
return screen.getByTestId('edit-strip')
}
/** « Propriétés » in the strip: the properties dialog of the selection (A1). */
async function openProperties() {
await userEvent
.setup()
.click(screen.getByRole('button', { name: 'Propriétés' }))
return screen.findByRole('dialog')
}
describe('selection and the list', () => {
@@ -165,11 +174,11 @@ describe('an edit on the drawing (U2 Task 5: the numeric group left the panel)',
it('a refused place keeps the stored shape, then a place inside the frame repairs it', async () => {
await mount({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
const panel = await selectFromList()
const strip = await selectFromList()
const before = store.getState().documentText
expect(
within(panel).getByTestId('annotation-geometry-issues'),
).toBeInTheDocument()
// The issue shows in the strip's notice (U2 Task 6: the panel left).
const issue = () => within(strip).queryByRole('alert')
expect(issue()).toBeInTheDocument()
mouseDrag(pointHandle(), [150, 150], [50, 150])
expect(store.getState().documentText).toBe(before)
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
@@ -181,7 +190,7 @@ describe('an edit on the drawing (U2 Task 5: the numeric group left the panel)',
cy: 50,
r: 5,
})
expect(screen.queryByTestId('annotation-geometry-issues')).toBeNull()
expect(issue()).toBeNull()
})
it('Escape drops a pending series: the stored shape shows again', async () => {
@@ -231,8 +240,9 @@ describe('the keyboard creation path', () => {
laterality: 'unpaired',
geometry: { type: 'circle', cx: 50, cy: 50 },
})
// A7: the new point selected (the strip offers its properties).
expect(
await screen.findByTestId('annotation-properties'),
await screen.findByRole('button', { name: 'Propriétés' }),
).toBeInTheDocument()
})
@@ -308,7 +318,7 @@ describe('the point tool and the corrected position (C26)', () => {
})
expect(panel).not.toBeInTheDocument()
expect(screen.queryByTestId('overlay-click-cross')).toBeNull()
await screen.findByTestId('annotation-properties')
await screen.findByRole('button', { name: 'Propriétés' })
expect(shownCircle()).toHaveAttribute('cx', '15')
})
@@ -1001,7 +1011,7 @@ describe('« Désélectionner » (R1, A6)', () => {
const panel = await selectFromList()
const before = snapshot()
await userEvent.setup().click(button(panel))
expect(screen.queryByTestId('annotation-properties')).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
expect(screen.getByTestId('annotation-overview')).toBeInTheDocument()
expect(document.activeElement).toBe(rowOf('anno-a'))
expect(announce).toHaveBeenCalledWith('Aucune annotation sélectionnée.')
@@ -1020,22 +1030,22 @@ describe('« Désélectionner » (R1, A6)', () => {
.getByTestId('annotation-canvas-drawing')
.querySelector('[data-anno-id="anno-a"]')!,
)
const reopened = await screen.findByTestId('annotation-properties')
await userEvent.setup().click(button(reopened))
await screen.findByRole('button', { name: 'Propriétés' })
await userEvent.setup().click(button(screen.getByTestId('edit-strip')))
expect(document.activeElement).toBe(screen.getByTestId('annotation-canvas'))
expect(screen.queryByTestId('annotation-properties')).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).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('Nom (FR)'))
await user.type(within(panel).getByLabelText('Nom (FR)'), 'Nuque{Enter}')
expect(nameOf('anno-a')).toBe('Nuque')
await user.click(button(panel))
const handle = screen.getByTestId('point-handle')
fireEvent.keyDown(handle, { key: 'ArrowRight' })
fireEvent.keyDown(handle, { key: 'Enter' })
expect(geometryOf('anno-a')).toMatchObject({ cx: 50.5 })
await userEvent.setup().click(button(panel))
act(() => void store.getState().undoStep())
expect(nameOf('anno-a')).toBe('N')
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
})
it('read-only: no « Supprimer », it deselects and focuses the ro- row', async () => {
@@ -1045,7 +1055,7 @@ describe('« Désélectionner » (R1, A6)', () => {
within(panel).queryByRole('button', { name: 'Supprimer' }),
).toBeNull()
await userEvent.setup().click(button(panel))
expect(screen.queryByTestId('annotation-properties')).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
const row = document.querySelector(
'[data-focus-key=\'{"kind":"annotation","id":"anno-a"}\']',
)
@@ -1053,38 +1063,27 @@ describe('« Désélectionner » (R1, A6)', () => {
expect(announce).toHaveBeenCalledTimes(1)
})
it('commits a valid typed value once when the field is not blurred', async () => {
it('commits a pending key series once when the handle is not blurred', async () => {
await mountSpy()
const panel = await selectFromList()
const user = userEvent.setup()
const name = within(panel).getByLabelText('Nom (FR)')
await user.clear(name)
await user.type(name, 'Nuque')
const handle = screen.getByTestId('point-handle')
handle.focus()
fireEvent.keyDown(handle, { key: 'ArrowRight' })
const depth = store.getState().undo.length
await user.click(button(panel))
expect(nameOf('anno-a')).toBe('Nuque')
await userEvent.setup().click(button(panel))
expect(geometryOf('anno-a')).toMatchObject({ cx: 50.5 })
expect(store.getState().undo.length).toBe(depth + 1)
})
it('a refused typed value: the panel closes, the document is unchanged', async () => {
await mountSpy()
const panel = await selectFromList()
const user = userEvent.setup()
const before = store.getState().documentText
// A blank name is refused (both names are required).
await user.clear(within(panel).getByLabelText('Nom (FR)'))
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'))
await screen.findByRole('button', { name: 'Properties' })
await userEvent
.setup()
.click(button(screen.getByTestId('edit-strip'), 'Deselect'))
expect(announce).toHaveBeenCalledWith('No annotation selected.')
})
@@ -1101,10 +1100,9 @@ describe('« Désélectionner » (R1, A6)', () => {
name: 'Remplacer par un polygone',
}),
)
const open = await screen.findByTestId('annotation-properties')
expect(
within(open).queryByRole('button', { name: 'Désélectionner' }),
).toBeNull()
await screen.findByRole('button', { name: 'Annuler le tracé' })
expect(screen.queryByRole('button', { name: 'Désélectionner' })).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
})
})
@@ -1173,8 +1171,9 @@ describe('a tap on the drawing (D6b)', () => {
expect(drawing(readOnly).querySelector('svg')).not.toBeNull(),
)
}
// U2 Task 6: a selection shows « Propriétés » in the strip (the panel left).
const isDeselected = () =>
screen.queryByTestId('annotation-properties') === null
screen.queryByRole('button', { name: 'Propriétés' }) === null
async function selected(options: { text?: string } = {}) {
await mountSpy(options)
await selectFromList()
@@ -1252,7 +1251,9 @@ describe('a tap on the drawing (D6b)', () => {
} as Annotation
await mountSpy({ text: insert(view, { kind: 'annotation', value: link }) })
tap(marker('link-a'))
expect(screen.getByTestId('annotation-properties')).toBeInTheDocument()
expect(screen.getByTestId('edit-strip-title')).toHaveAttribute(
'data-selection',
)
expect(announce).not.toHaveBeenCalled()
})
@@ -1575,47 +1576,31 @@ describe('a tap on the drawing (D6b)', () => {
it('undo after a tap deselect undoes the earlier edit, redo restores it', async () => {
await selected()
const user = userEvent.setup()
const name = screen.getByLabelText('Nom (FR)')
await user.clear(name)
await user.type(name, 'Nuque{Enter}')
const handle = screen.getByTestId('point-handle')
fireEvent.keyDown(handle, { key: 'ArrowRight' })
fireEvent.keyDown(handle, { key: 'Enter' })
tap(rect())
act(() => void store.getState().undoStep())
expect(nameOf('anno-a')).toBe('N')
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
act(() => void store.getState().redoStep())
expect(nameOf('anno-a')).toBe('Nuque')
expect(geometryOf('anno-a')).toMatchObject({ cx: 50.5 })
})
it('commits a typed valid value once and deselects when the press blurs the field', async () => {
it('commits a pending key series once and deselects when the press blurs the handle', async () => {
await selected()
const user = userEvent.setup()
const name = screen.getByLabelText('Nom (FR)')
await user.clear(name)
await user.type(name, 'Nuque')
const handle = screen.getByTestId('point-handle')
act(() => handle.focus())
fireEvent.keyDown(handle, { key: 'ArrowRight' })
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.
// What mousedown does: the focus moves to the box, the series commits on the blur.
act(() => box().focus())
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
fireEvent.click(rect())
expect(nameOf('anno-a')).toBe('Nuque')
expect(geometryOf('anno-a')).toMatchObject({ cx: 50.5 })
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()
const user = userEvent.setup()
const before = store.getState().documentText
// A blank name is refused (both names are required).
await user.clear(screen.getByLabelText('Nom (FR)'))
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)
})
})
describe('the strip', () => {
@@ -1765,7 +1750,10 @@ describe('the strip', () => {
]),
})
await selectFromList()
const issues = within(screen.getByTestId('annotation-properties'))
const dialog = await openProperties()
const issues = within(
within(dialog).getByTestId('annotation-geometry-issues'),
)
.getAllByRole('listitem')
.map((item) => item.textContent)
// The core gives one frame fault per annotation: « +n » is shown by the strip below.
@@ -1805,10 +1793,13 @@ describe('the strip', () => {
await selectFromList()
drag(marker('anno-a'), [60, 40])
expect(line()).toHaveTextContent('Point déplacé')
const name = screen.getByLabelText('Nom (FR)')
// A commit that is no gesture: the review toggle of the properties dialog (A10).
const user = userEvent.setup()
await user.clear(name)
await user.type(name, 'Nuque{Enter}')
const dialog = await openProperties()
await user.click(
within(dialog).getByRole('button', { name: 'Marquer comme relu' }),
)
await user.click(within(dialog).getByRole('button', { name: 'Fermer' }))
expect(line()).not.toHaveTextContent('Point déplacé')
drag(marker('anno-a'), [40, 40])
expect(line()).toHaveTextContent('Point déplacé')
@@ -65,7 +65,12 @@ function cited() {
describe('the layer order', () => {
it('reference, citations, finding: asked top down', () => {
expect(LAYERS_TOP_DOWN).toEqual(['reference', 'citations', 'finding'])
expect(LAYERS_TOP_DOWN).toEqual([
'reference',
'citations',
'finding',
'annotation',
])
mount()
const order: string[] = []
for (const layer of ['finding', 'citations', 'reference'] as const) {
+29 -13
View File
@@ -112,7 +112,14 @@ const shown = (selector: string) =>
[...document.querySelectorAll<HTMLElement>(selector)].find(
(element) => !element.closest('[hidden]'),
)
const panel = () => shown('[data-testid="annotation-properties"]')
/**
* The visible selection (U2 Task 6: the properties left the side panel): the strip's
* « Propriétés », or the phone twin's inline read body.
*/
const panel = () =>
shown('[data-properties-button]') ?? shown('[data-testid="annotation-read"]')
/** The shown body's right column: the overview (A3). */
const aside = () => shown('[data-annotation-aside]')!
const rowOf = (id: string) =>
shown(`[data-focus-key='{"kind":"annotation","id":"${id}"}']`)
const live = () => document.querySelector('[aria-live="polite"]')!
@@ -147,7 +154,17 @@ async function openCitations(user: ReturnType<typeof userEvent.setup>) {
await user.click(screen.getByRole('button', { name: '1 référence' }))
expect(citations()).not.toBeNull()
}
const inPanel = (name: string) => within(panel()!).getByRole('button', { name })
const inStrip = (name: string) =>
within(shown('[data-testid="edit-strip"]')!).getByRole('button', { name })
/** « Propriétés », then a button of the properties dialog. */
async function inDialog(
user: ReturnType<typeof userEvent.setup>,
name: string,
) {
await user.click(inStrip('Propriétés'))
const dialog = await screen.findByRole('dialog')
return within(dialog).getByRole('button', { name })
}
describe('Escape deselects', () => {
it('from the canvas box: deselected, the focus stays, announced', async () => {
@@ -162,10 +179,10 @@ describe('Escape deselects', () => {
)
})
it('from a button of the panel: deselected, the focus on the row', async () => {
it('from a button of the side column: deselected, the focus on the row', async () => {
const user = await mount()
await select(user)
inPanel('Marquer comme relu').focus()
rowOf('anno-a')!.focus()
escape(document.activeElement!)
expect(panel()).toBeUndefined()
expect(document.activeElement).toBe(rowOf('anno-a'))
@@ -174,9 +191,8 @@ describe('Escape deselects', () => {
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()
within(aside()).getAllByRole('button')[0]!.focus()
escape(document.activeElement!)
expect(document.activeElement).toBe(rowOf('anno-b'))
})
@@ -206,7 +222,7 @@ describe('Escape leaves alone', () => {
it('a text field', async () => {
const user = await mount()
await select(user)
const field = within(panel()!).getByLabelText('Nom (FR)')
const field = within(aside()).getByLabelText('Filtrer par nom')
field.focus()
escape(field)
expect(panel()).toBeDefined()
@@ -256,7 +272,7 @@ describe('Escape leaves alone', () => {
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'))
await user.click(inStrip('Remplacer par un polygone'))
const bar = await screen.findByTestId('tracing-commands')
bar.focus()
escape(bar)
@@ -264,7 +280,7 @@ describe('Escape leaves alone', () => {
expect(screen.queryByTestId('tracing-commands')).toBeNull(),
)
expect(panel()).toBeDefined()
await user.click(inPanel('Remplacer par un polygone'))
await user.click(inStrip('Remplacer par un polygone'))
await screen.findByTestId('tracing-commands')
canvasBox().focus()
escape(canvasBox())
@@ -277,8 +293,8 @@ describe('Escape leaves alone', () => {
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')!
await user.click(await inDialog(user, 'Supprimer'))
const dialog = document.querySelectorAll('dialog[open]')[1]!
expect(dialog).not.toBeNull()
escape(dialog)
expect(panel()).toBeDefined()
@@ -289,7 +305,7 @@ 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'))
await user.click(await inDialog(user, 'Supprimer'))
expect(document.querySelector('dialog[open]')).not.toBeNull()
document.body.focus()
escape(document.body)
@@ -367,7 +383,7 @@ describe('Escape and the other layers', () => {
escape(document.body)
expect(panel()).toBeUndefined()
const hidden = [
...document.querySelectorAll('[data-testid="annotation-properties"]'),
...document.querySelectorAll('[data-properties-button]'),
].filter((element) => element.closest('[hidden]'))
expect(hidden).toHaveLength(1)
})
@@ -123,7 +123,7 @@ describe('focus requests', () => {
await waitFor(() => expect(document.activeElement).toBe(item))
})
it('Annotations: selects the annotation and focuses the properties heading', async () => {
it('Annotations (R-5): selects the annotation and focuses its row, no dialog', async () => {
const text = insert(baseText(), point('anno-b', 20, 20, 3))
await openReady({ text })
render(
@@ -134,16 +134,16 @@ describe('focus requests', () => {
/>,
)
// anno-b and anno-a share a name: the circle's centre tells which one is selected.
const properties = await screen.findByTestId('annotation-properties')
expect(properties).toBeInTheDocument()
// U2 Task 5: no coordinate field in the panel; the overlay draws the selection.
await screen.findByRole('button', { name: 'Propriétés' })
expect(
screen.getByTestId('overlay-selection').querySelector('circle'),
).toHaveAttribute('cx', '20')
await waitFor(() =>
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
const row = document.querySelector(
'[data-focus-key=\'{"kind":"annotation","id":"anno-b"}\']',
)
expect(properties).toContainElement(document.activeElement as HTMLElement)
await waitFor(() => expect(document.activeElement).toBe(row))
expect(row).toHaveAttribute('aria-current', 'true')
expect(screen.queryByRole('dialog')).toBeNull()
})
it('Références and Régions: focus the named row', async () => {
@@ -58,16 +58,15 @@ const disabled = (button: HTMLElement) =>
button.getAttribute('aria-disabled') === 'true'
const geometry = () =>
store.getState().previewState?.document.annotations[0].geometry
const nameFr = () =>
store.getState().previewState?.document.annotations[0].name?.fr
const nameFr = () => store.getState().previewState?.document.name.fr
/**
* A committed field (it writes on its blur): the sheet's French name on Général. U2 Task 6
* took the annotation's committed fields out of the drawing (one dialog save).
*/
async function selectAnnotation(user: ReturnType<typeof userEvent.setup>) {
const list = await screen.findByRole('list', {
name: 'Annotations de la vue',
})
await user.click(within(list).getAllByRole('button')[0])
const panel = await screen.findByTestId('annotation-properties')
return within(panel).getByLabelText('Nom (FR)') as HTMLInputElement
await user.click(screen.getByRole('tab', { name: 'Général' }))
return (await screen.findByLabelText('Nom (FR)')) as HTMLInputElement
}
describe('the buttons', () => {
@@ -420,3 +420,32 @@ describe('final review: read-back values are capped', () => {
expect(sanitizeView(onFindings(sparse))?.finding).toBeNull()
})
})
/** U2 Task 6: the annotation dialog's layer in an entry. */
describe('the annotation layer in the history', () => {
it('is read back on the drawing of Annotations only, with an id within the cap', () => {
const raw = {
tab: 'annotations',
section: 'drawing',
annotation: { id: 'a1' },
}
expect(sanitizeView(raw)?.annotation).toEqual({ id: 'a1' })
expect(layerCount(sanitizeView(raw)!)).toBe(1)
expect(sanitizeView({ ...raw, section: 'views' })?.annotation).toBeNull()
expect(sanitizeView({ ...raw, tab: 'general' })?.annotation).toBeNull()
expect(
sanitizeView({ ...raw, annotation: { id: 7 } })?.annotation,
).toBeNull()
const long = { ...raw, annotation: { id: 'x'.repeat(200) } }
expect(sanitizeView(long)?.annotation).toBeNull()
})
it('opened pushes, closed goes back to the drawing below', () => {
const drawing = view('annotations')
const dialog = view('annotations', { annotation: { id: 'a1' } })
expect(sameView(drawing, dialog)).toBe(false)
expect(planWrite(entry({ view: drawing }), dialog, false)).toBe('push')
const top = entry({ view: dialog, below: drawing })
expect(planWrite(top, drawing, false)).toBe('back')
})
})
@@ -476,3 +476,68 @@ describe('the drawing guard (R-12): a move mode and the navigations', () => {
expect(useAnnotationWork.getState().mode).toBeNull()
})
})
/** U2 Task 6: the annotation properties dialog is a layer of the browser history. */
describe('the annotation layer and the history', () => {
function AnnotationPage({ dirty }: { dirty: boolean }) {
const nav = useEditorNavigation('annotations')
navigate = useNavigate()
location = useLocation()
useEditorHistory(nav, owner, defaultView('annotations'))
return (
<>
<button onClick={() => nav.openAnnotation('a1')}>open</button>
<button onClick={() => nav.closeAnnotation()}>close</button>
<button
onClick={() =>
nav.guards.register('annotation', () =>
dirty ? { allowed: false } : { allowed: true },
)
}
>
guard
</button>
<p data-testid="layer">{JSON.stringify(nav.state.annotation)}</p>
</>
)
}
const layer = () => JSON.parse(screen.getByTestId('layer').textContent!)
const mountPage = (dirty = false) =>
render(
<MemoryRouter initialEntries={['/x']}>
<AnnotationPage dirty={dirty} />
</MemoryRouter>,
)
it('opening pushes; Back closes it, Forward opens it again', async () => {
const user = userEvent.setup()
mountPage()
await user.click(screen.getByRole('button', { name: 'open' }))
expect(layer()).toEqual({ id: 'a1' })
expect(entry().view.annotation).toEqual({ id: 'a1' })
expect(entry().below?.annotation).toBeNull()
act(() => navigate(-1))
expect(layer()).toBeNull()
act(() => navigate(1))
expect(layer()).toEqual({ id: 'a1' })
})
it('a user close goes back to the drawing entry below', async () => {
const user = userEvent.setup()
mountPage()
await user.click(screen.getByRole('button', { name: 'open' }))
await user.click(screen.getByRole('button', { name: 'close' }))
await waitFor(() => expect(entry().view.annotation).toBeNull())
expect(layer()).toBeNull()
})
it('a dirty form keeps the dialog on a Back: its view is pushed again', async () => {
const user = userEvent.setup()
mountPage(true)
await user.click(screen.getByRole('button', { name: 'guard' }))
await user.click(screen.getByRole('button', { name: 'open' }))
act(() => navigate(-1))
expect(layer()).toEqual({ id: 'a1' })
expect(entry().view.annotation).toEqual({ id: 'a1' })
})
})
@@ -247,7 +247,8 @@ describe('findings and canvas state across a tab change', () => {
await user.click(tab('Général'))
await user.click(tab('Annotations'))
await stillSelected()
expect(drawing.getByTestId('annotation-properties')).toBeVisible()
// U2 Task 6: the selection's strip offers its properties (the panel left the column).
expect(drawing.getByRole('button', { name: 'Propriétés' })).toBeVisible()
})
it('the unmeasured hint opens the views section and « Retour au dessin » restores the same canvas', async () => {
@@ -343,3 +343,42 @@ describe('final review', () => {
expect(state.reference).toBeNull()
})
})
/** U2 Task 6: the annotation properties dialog is a layer of the drawing. */
describe('the annotation layer', () => {
it('open_annotation shows the dialog over the drawing, close_annotation takes it away', () => {
const base = run(initialNavigation('general'), {
type: 'open_section',
section: 'views',
})
const opened = run(base, { type: 'open_annotation', id: 'a1' })
expect(opened.tab).toBe('annotations')
expect(opened.section).toBe('drawing')
expect(opened.annotation).toEqual({ id: 'a1' })
expect(viewOf(opened).annotation).toEqual({ id: 'a1' })
expect(run(opened, { type: 'close_annotation' }).annotation).toBeNull()
})
it('every move away from the drawing leaves it: a tab, a section, « Aller à »', () => {
const opened = run(initialNavigation('annotations'), {
type: 'open_annotation',
id: 'a1',
})
const moves = [
{ type: 'select_tab', tab: 'general' },
{ type: 'open_section', section: 'views' },
{ type: 'go_to', target: targetOfKey({ kind: 'sheet' }) },
{ type: 'open_finding', key: finding },
{ type: 'show_all_references', filter: finding },
] as const
for (const move of moves) expect(run(opened, move).annotation).toBeNull()
})
it('restore_view puts it back', () => {
const base = initialNavigation('annotations')
const view = { ...viewOf(base), annotation: { id: 'a2' } }
expect(run(base, { type: 'restore_view', view }).annotation).toEqual({
id: 'a2',
})
})
})
+13 -6
View File
@@ -432,10 +432,18 @@ describe('ids stay unique', () => {
.find((candidate) => !candidate.closest('[hidden]'))!
await user.click(within(twin).getAllByRole('button')[0])
expect(duplicateIds()).toEqual([])
expect(document.getElementById('ro-annotation-name-fr')).not.toBeNull()
expect(document.getElementById('annotation-name-fr')).not.toBeNull()
expect(screen.getByTestId('annotation-read')).toBeInTheDocument()
cross(1280)
expect(duplicateIds()).toEqual([])
// The properties dialog's edit form, kept through a flip (R-14): its own ids.
await user.click(screen.getByRole('button', { name: 'Propriétés' }))
const dialog = await screen.findByRole('dialog')
await user.click(within(dialog).getByRole('button', { name: 'Modifier' }))
expect(document.getElementById('annotation-edit-fr')).not.toBeNull()
expect(duplicateIds()).toEqual([])
cross(800)
expect(document.getElementById('annotation-edit-fr')).not.toBeNull()
expect(duplicateIds()).toEqual([])
})
})
@@ -459,11 +467,10 @@ describe('focus requests', () => {
[...document.querySelectorAll(`[data-testid="${id}"]`)].filter(
(element) => !element.closest('[hidden]'),
)
await waitFor(() =>
expect(visible('annotation-properties')).toHaveLength(1),
)
// Below 1 024 px the twin reads it inline (R-16; U2 Task 6: no properties panel).
await waitFor(() => expect(visible('annotation-read')).toHaveLength(1))
cross(1280)
expect(visible('annotation-properties')).toHaveLength(0)
expect(visible('annotation-read')).toHaveLength(0)
expect(visible('annotation-overview')).toHaveLength(1)
})
})
+7 -9
View File
@@ -129,17 +129,17 @@ describe.each([
).toBeInTheDocument()
})
it('a row selects the annotation; « Toutes les annotations » returns with focus on its row', async () => {
it('a row selects the annotation and stays marked (A3); « Désélectionner » focuses its row', async () => {
await mount(readOnly)
const user = userEvent.setup()
await user.click(rows()[1])
expect(
await within(body()).findByTestId('annotation-properties'),
).toBeVisible()
await user.click(
screen.getByRole('button', { name: 'Toutes les annotations' }),
await waitFor(() =>
expect(rows()[1]).toHaveAttribute('aria-current', 'true'),
)
expect(overview()).toBeVisible()
expect(within(body()).queryByRole('dialog')).toBeNull()
await user.click(screen.getByRole('button', { name: 'Désélectionner' }))
expect(rows()[1]).not.toHaveAttribute('aria-current')
await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
})
@@ -150,9 +150,7 @@ describe.each([
within(overview()).getByRole('searchbox', { name: 'Filtrer par nom' })
await user.type(field(), 'epaule')
await user.click(rows()[0])
await user.click(
screen.getByRole('button', { name: 'Toutes les annotations' }),
)
await user.click(screen.getByRole('button', { name: 'Désélectionner' }))
expect(field()).toHaveValue('epaule')
expect(rows()).toHaveLength(1)
expect(rows()[0]).toHaveTextContent('Épaule')
+16 -10
View File
@@ -167,7 +167,9 @@ async function select(index = 0) {
name: 'Annotations de la vue',
})
await userEvent.setup().click(within(list).getAllByRole('button')[index])
return screen.findByTestId('annotation-properties')
// 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 = () =>
@@ -316,7 +318,9 @@ describe('the move mode (A11, R-12, R-13)', () => {
fireEvent.keyDown(arrow('la droite'), { key: 'Escape' })
expect(useAnnotationWork.getState().mode).toBeNull()
expect(screen.queryByTestId('move-mode-bar')).toBeNull()
expect(screen.getByTestId('annotation-properties')).toBeInTheDocument()
expect(
screen.getByRole('button', { name: 'Propriétés' }),
).toBeInTheDocument()
})
it('a click on another annotation selects nothing during the mode', async () => {
@@ -480,15 +484,17 @@ describe('review fixes: no silent loss, no empty commit, no lost focus', () => {
}
const question = () => useAnnotationWork.getState().question?.work ?? null
it('« Toutes les annotations », a tool and « Ajouter un point » ask first', async () => {
it('Enter on the selected row, a tool and « Ajouter un point » ask first', async () => {
await started()
const panel = screen.getByTestId('annotation-properties')
fireEvent.click(
within(panel).getByRole('button', { name: 'Toutes les annotations' }),
)
// 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.getByTestId('annotation-properties')).toBeInTheDocument()
expect(screen.queryByRole('dialog')).toBeNull()
act(() => useAnnotationWork.setState({ question: null }))
fireEvent.click(screen.getByRole('button', { name: 'Point' }))
expect(question()).toBe('move')
@@ -526,12 +532,12 @@ describe('review fixes: no silent loss, no empty commit, no lost focus', () => {
await select()
handle().focus()
fireEvent.keyDown(handle(), { key: 'Escape' })
expect(screen.queryByTestId('annotation-properties')).toBeNull()
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.queryByTestId('annotation-properties')).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
expect(document.activeElement).not.toBe(document.body)
})
+6 -3
View File
@@ -267,7 +267,7 @@ describe('« Aller à » an annotation while something is in progress', () => {
expect(announce).toHaveBeenCalledWith(
expect.stringContaining('création est en cours'),
)
expect(screen.queryByTestId('annotation-properties')).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
})
it('an open zone tracing is kept: the strip tracing commands take the focus', async () => {
@@ -285,11 +285,14 @@ describe('« Aller à » an annotation while something is in progress', () => {
)
})
it('with nothing in progress the annotation is selected and its heading focused', async () => {
it('with nothing in progress the annotation is selected and its row focused (R-5)', async () => {
const { consumed } = await withProgress(async () => undefined)
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'found'))
await waitFor(() =>
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
expect(document.activeElement).toHaveAttribute(
'data-focus-key',
JSON.stringify({ kind: 'annotation', id: 'anno-a' }),
),
)
})
})
@@ -116,7 +116,9 @@ async function select(index = 0) {
name: 'Annotations de la vue',
})
await userEvent.setup().click(within(list).getAllByRole('button')[index])
return screen.findByTestId('annotation-properties')
// 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 mouse = {
@@ -737,7 +739,7 @@ describe('I-3: the click a touch tap synthesises is absorbed', () => {
await mount(squareText())
await select()
tapOn(screen.getByTestId('annotation-canvas'), 'touch')
expect(screen.queryByTestId('annotation-properties')).toBeNull()
expect(screen.queryByRole('button', { name: 'Propriétés' })).toBeNull()
clickAtTap(addPoint())
expect(creation()).toBeNull()
clickAtTap(addPoint())
+97
View File
@@ -234,3 +234,100 @@ describe('Dialog focus return', () => {
expect(screen.getByRole('button', { name: 'Sibling' })).toHaveFocus()
})
})
/** U2 Task 6 (A2, R-6): the panel over an anchor box, the keyboard fallback, the veil. */
describe('Dialog anchored over a column', () => {
const rect = (box: Partial<DOMRect>) =>
({ left: 0, top: 0, width: 0, height: 0, ...box }) as DOMRect
function anchorAt(box: Partial<DOMRect>) {
const element = document.createElement('aside')
element.getBoundingClientRect = () => rect(box)
document.body.append(element)
return { current: element }
}
const panel = () => screen.getByTestId('dialog-panel')
const withViewport = (value: unknown) =>
Object.defineProperty(window, 'visualViewport', {
configurable: true,
value,
})
it('sits at the anchor’s left and width, from its top, down to 12 px above the bottom', () => {
withViewport(undefined)
window.innerHeight = 800
const anchor = anchorAt({ left: 900, top: 140, width: 352 })
render(
<Dialog open anchor={anchor} onClose={() => {}} title="X">
body
</Dialog>,
)
expect(panel().style.left).toBe('900px')
expect(panel().style.width).toBe('352px')
expect(panel().style.top).toBe('140px')
expect(panel().style.maxHeight).toBe('648px')
})
it('never starts above 12 px when the column’s top is scrolled away', () => {
withViewport(undefined)
window.innerHeight = 800
const anchor = anchorAt({ left: 900, top: -300, width: 352 })
render(
<Dialog open anchor={anchor} onClose={() => {}} title="X">
body
</Dialog>,
)
expect(panel().style.top).toBe('12px')
expect(panel().style.maxHeight).toBe('776px')
})
it('a tablet keyboard leaving under 320 px: the visual viewport’s top and height', () => {
window.innerHeight = 800
withViewport({
height: 350,
offsetTop: 0,
addEventListener: () => undefined,
removeEventListener: () => undefined,
})
const anchor = anchorAt({ left: 900, top: 140, width: 352 })
render(
<Dialog open anchor={anchor} onClose={() => {}} title="X">
body
</Dialog>,
)
expect(panel().style.top).toBe('12px')
expect(panel().style.height).toBe('326px')
expect(panel().style.left).toBe('900px')
withViewport(undefined)
})
it('without an anchor box the panel is centred, as before', () => {
render(
<Dialog open anchor={{ current: null }} onClose={() => {}} title="X">
body
</Dialog>,
)
expect(panel().style.left).toBe('')
expect(panel().className).toContain('max-w-md')
})
it('the veil of an anchored dialog ignores clicks; a centred one still asks', async () => {
withViewport(undefined)
const onClose = vi.fn()
const anchor = anchorAt({ left: 900, top: 140, width: 352 })
const { unmount } = render(
<Dialog open anchor={anchor} onClose={onClose} title="X">
body
</Dialog>,
)
await userEvent.click(screen.getByTestId('dialog-backdrop'))
expect(onClose).not.toHaveBeenCalled()
unmount()
render(
<Dialog open onClose={onClose} title="X">
body
</Dialog>,
)
await userEvent.click(screen.getByTestId('dialog-backdrop'))
expect(onClose).toHaveBeenCalled()
})
})