fix(editor): veil ignores clicks, names merged apart, honest tests

U2 Task 6 fix round 1 (review minors 1 to 9).

- R-6: `Dialog` takes `veilCloses`; the annotation dialog passes false,
  so its veil ignores clicks centred too. Other dialogs unchanged.
- Save merges each name on its own (an EN refreshed meanwhile survives
  an FR-only edit); the merged annotation is typed per kind, no cast.
- Tests: the category change and the region row really run (a second
  category and a region in the fixture); EN kept under an FR edit;
  focus to the drawing when a filter hides the row; a centred veil
  ignores a click; act() around the store write; ui.Dialog restores
  innerHeight and visualViewport after each test.
- e2e: `pickAnnotation` no longer scrolls; `scrollToTop` is explicit
  where a low row leaves the drawing out of view (editor-zones x3,
  editor-geometry). editor-geometry runs the accepted repair from the
  page's end, buttons pressed in place, scroll unchanged. The touch
  and double-click tests wait on the clicks themselves; the stray
  click on the veil can fail.
- CreationPanel's `required.fields` recorded as a shortcut for Task 7;
  TODO lines updated. focusTarget comment wrapped.
This commit is contained in:
bchanot committed 2026-11-17 22:47:02 +01:00
1 parent db3f306523
commit 9a0fe3784c
12 files changed
+234 -58

No files matched your search

@@ -57,6 +57,23 @@ const zone = (id: string, patch: Partial<Annotation> = {}): Annotation =>
...patch,
}) as Annotation
/** The drawn sheet with a second category `cat-b` and the region `C`. */
function richText(): string {
const both = insert(drawnText(), {
kind: 'category',
value: { id: 'cat-b', name: { fr: 'Os', en: 'Bone' }, color: null },
})
return insert(both, {
kind: 'region',
value: {
code: 'C',
name: { fr: 'Cervicales', en: 'Cervical' },
count: 7,
count_range: null,
},
})
}
function stubCtm(): void {
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', {
@@ -144,13 +161,15 @@ describe('opening (A1)', () => {
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,
},
})
act(() =>
useAnnotationWork.setState({
chosen: {
annotationId: 'z',
vertex: 1,
base: store.getState().documentText,
},
}),
)
pressAt(marker('z'), 50, 50)
expect(useAnnotationWork.getState().chosen).toBeNull()
expect(dialog()).toBeNull()
@@ -159,6 +178,39 @@ describe('opening (A1)', () => {
expect(await screen.findByRole('dialog')).toBeVisible()
})
it('closed, the focus goes to the drawing when a filter hides the row (board 32)', async () => {
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
fireEvent.change(screen.getByLabelText('Filtrer par nom'), {
target: { value: 'zzz-no-match' },
})
fireEvent.keyDown(document.body, { key: 'Escape' })
pressAt(marker('a'), 50, 50)
await within(strip()).findByRole('button', { name: 'Propriétés' })
await new Promise((resolve) => setTimeout(resolve, 450))
pressAt(marker('a'), 50, 50)
const opened = await screen.findByRole('dialog')
await userEvent
.setup()
.click(within(opened).getByRole('button', { name: 'Fermer' }))
await waitFor(() => expect(dialog()).toBeNull())
await waitFor(() =>
expect(document.activeElement).toBe(
screen.getByTestId('annotation-canvas'),
),
)
})
it('centred (below 1 024 px), its veil ignores a click too (R-6)', async () => {
window.innerWidth = 900
await mount(insert(drawnText(), point('a', 50, 50, 5)))
await selectRow('a')
await openProperties()
expect(screen.getByTestId('dialog-panel').style.left).toBe('')
await userEvent.setup().click(screen.getByTestId('dialog-backdrop'))
expect(dialog()).not.toBeNull()
})
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')
@@ -201,22 +253,17 @@ describe('the read mode (board 31 A, B)', () => {
})
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,
vertebral_region_code: 'C',
} as Partial<Annotation>)
await mount(insert(drawnText(), { kind: 'annotation', value } as never))
await mount(insert(richText(), { 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(rows()).toContain('Région vertébrale')
expect(within(dialog()!).getByText('#aa0000')).toBeInTheDocument()
expect(within(dialog()!).getByText('Cervicales')).toBeInTheDocument()
})
it('an unnamed link: its opened view, « Vue ouverte », no findings zone', async () => {
@@ -303,7 +350,7 @@ describe('the read mode (board 31 A, B)', () => {
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 mount(insert(richText(), point('a', 50, 50, 5)))
await selectRow('a')
await startEdit()
const user = userEvent.setup()
@@ -315,15 +362,14 @@ describe('the edit form (board 31 C, R-3)', () => {
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)
await user.selectOptions(category, 'cat-b')
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(annotationOf('a').category_id).toBe('cat-b')
expect(
within(dialog()!).getByText('Modifications enregistrées'),
).toBeInTheDocument()
@@ -354,6 +400,27 @@ describe('the edit form (board 31 C, R-3)', () => {
expect(annotationOf('a').name?.fr).toBe('Nx')
})
it('editing FR only keeps an EN changed meanwhile (each name merged on its own)', 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 renamed = { ...annotationOf('a'), name: { fr: 'N', en: 'Fresh' } }
act(
() =>
void store.getState().commit({
op: 'update',
key: { kind: 'annotation', id: 'a' },
element: { kind: 'annotation', value: renamed as Annotation },
}),
)
await user.click(
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
)
expect(annotationOf('a').name).toEqual({ fr: 'Nx', en: 'Fresh' })
})
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')