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:
1 parent
db3f306523
commit
9a0fe3784c
12 files changed
+234
-58
No files matched your search
@@ -748,7 +748,8 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet
|
|||||||
- [ ] V1-2.6 UX U2 implementation (contract `.claude/tasks/contracts/2026-11-17-v1-2-6-u2-implementation.md`, plan rev 3, subagent-driven): [ ] T1 core min radius · [ ] T2 press machine · [ ] T3 strip + message, no shift · [ ] T4 points, move mode, guard · [ ] T5 zones, redraw, R-18 · [ ] T6 properties dialog · [ ] T7 creation · [ ] T8 touch, loupe · [ ] T9 docs · [ ] T10 gates, verifier, security · [ ] STOP owner trial on `pnpm db:trial` before closure
|
- [ ] V1-2.6 UX U2 implementation (contract `.claude/tasks/contracts/2026-11-17-v1-2-6-u2-implementation.md`, plan rev 3, subagent-driven): [ ] T1 core min radius · [ ] T2 press machine · [ ] T3 strip + message, no shift · [ ] T4 points, move mode, guard · [ ] T5 zones, redraw, R-18 · [ ] T6 properties dialog · [ ] T7 creation · [ ] T8 touch, loupe · [ ] T9 docs · [ ] T10 gates, verifier, security · [ ] STOP owner trial on `pnpm db:trial` before closure
|
||||||
- [ ] `shortcut:` the « − » bubble for a mouse is 28 × 22 px, read off board 05 (R-9 gives only the touch size), `apps/app/src/editor/annotations/handleSize.ts`. Upgrade: the owner's value at the trial (U2 Task 5).
|
- [ ] `shortcut:` the « − » bubble for a mouse is 28 × 22 px, read off board 05 (R-9 gives only the touch size), `apps/app/src/editor/annotations/handleSize.ts`. Upgrade: the owner's value at the trial (U2 Task 5).
|
||||||
- [ ] No `scroll-padding-top` under the sticky top bar (pre-existing, WCAG 2.4.11): a keyboard focus on the header's « Défaire », « Refaire » or « Enregistrer » while scrolled can stay hidden under it; axe target-size flags them once a list click scrolled the page (U2 Task 5 review M-3).
|
- [ ] No `scroll-padding-top` under the sticky top bar (pre-existing, WCAG 2.4.11): a keyboard focus on the header's « Défaire », « Refaire » or « Enregistrer » while scrolled can stay hidden under it; axe target-size flags them once a list click scrolled the page (U2 Task 5 review M-3).
|
||||||
- [x] At the page's end, a side panel that shortens (the issue list leaving it) clamps the scroll and moves the canvas by its height (11 px in `editor-geometry.spec.ts`, which starts from the top for that reason). Gone with Task 6: the column keeps the overview, the issue is in the strip and the dialog; the scroll-to-top removed, the spec green (U2 Task 5 fix round 1, closed by Task 6).
|
- [x] At the page's end, a side panel that shortens (the issue list leaving it) clamps the scroll and moves the canvas by its height (11 px in `editor-geometry.spec.ts`, which starts from the top for that reason). Gone with Task 6: the column keeps the overview, the issue is in the strip and the dialog. `editor-geometry.spec.ts` now runs the accepted repair (the issue leaving) from the page's end under `expectNoShift`, buttons pressed in place, scroll position unchanged (U2 Task 5 fix round 1, closed by Task 6 fix round 1).
|
||||||
|
- [ ] `shortcut:` the creation panel still shows the general lines `editor.annotations.required.fields` / `.names`, which R-3 removes (`apps/app/src/components/editor/annotations/CreationPanel.tsx`, `formProblem` in `creation.ts`). Upgrade: Task 7's creation dialog uses `missingFields` and the `editor.annotations.missing.*` keys, then the two keys and `formProblem` go (U2 Task 6 review Minor 6).
|
||||||
- [ ] `shortcut:` the close of a zone tracing (« Fermer le tracé ») is checked out of `expectNoShift` in `editor-annotations.spec.ts` « the drawing never moves »: the creation panel still replaces the overview in the side column until Task 7. Upgrade: wrap it again once the creation is a dialog (U2 Task 6, `aside-content` exemption removed).
|
- [ ] `shortcut:` the close of a zone tracing (« Fermer le tracé ») is checked out of `expectNoShift` in `editor-annotations.spec.ts` « the drawing never moves »: the creation panel still replaces the overview in the side column until Task 7. Upgrade: wrap it again once the creation is a dialog (U2 Task 6, `aside-content` exemption removed).
|
||||||
- [ ] Test anomaly A (owner 2026-11-09, separate from U1/U2): fictitious fingerprints `'a'.repeat(64)` from worker stand-ins (`packages/supabase/tests/sandbox/sheet-fixtures.ts:115` openRound, `sheets-concurrency.sandbox.ts:168`, `sheets-perf.sandbox.ts:169`); 7 published/deprecated sandbox versions fail `check_published`. Fix: real fingerprint through the core (as e2e `fingerprintOf`, `apps/app/e2e/support/catalogue.ts:88`); never weaken the publish gate or the reader check. Needs its own go. Census 2026-11-17 (R4 Task 3, read-only): 4 of 164 catalogue entries fail, the four current « Cheval sandbox » versions (2 at v1, 2 at v2), all `fingerprint_mismatch`; R4 cards show them with the integrity line.
|
- [ ] Test anomaly A (owner 2026-11-09, separate from U1/U2): fictitious fingerprints `'a'.repeat(64)` from worker stand-ins (`packages/supabase/tests/sandbox/sheet-fixtures.ts:115` openRound, `sheets-concurrency.sandbox.ts:168`, `sheets-perf.sandbox.ts:169`); 7 published/deprecated sandbox versions fail `check_published`. Fix: real fingerprint through the core (as e2e `fingerprintOf`, `apps/app/e2e/support/catalogue.ts:88`); never weaken the publish gate or the reader check. Needs its own go. Census 2026-11-17 (R4 Task 3, read-only): 4 of 164 catalogue entries fail, the four current « Cheval sandbox » versions (2 at v1, 2 at v2), all `fingerprint_mismatch`; R4 cards show them with the integrity line.
|
||||||
- [ ] Test anomaly B (owner 2026-11-09, separate from U1/U2): `packages/supabase/tests/sandbox/sheets-admin.sandbox.ts:181-195` creates the historical working copy and never archives it; slot taken → `admin.spec.ts:717` fails x4. Fix test independence and cleanup; the existing copy `8c315a12-20d4-4432-9db3-7cb88b27a5b4` stays untouched until the owner authorises. Linked: RR-13, the admin.spec confirmation line above.
|
- [ ] Test anomaly B (owner 2026-11-09, separate from U1/U2): `packages/supabase/tests/sandbox/sheets-admin.sandbox.ts:181-195` creates the historical working copy and never archives it; slot taken → `admin.spec.ts:717` fails x4. Fix test independence and cleanup; the existing copy `8c315a12-20d4-4432-9db3-7cb88b27a5b4` stays untouched until the owner authorises. Linked: RR-13, the admin.spec confirmation line above.
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
shapeWith,
|
shapeWith,
|
||||||
standardShape,
|
standardShape,
|
||||||
openProperties,
|
openProperties,
|
||||||
|
scrollToTop,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
|
|
||||||
// V1-2.6 geometry and adversarial cases (contract C7, C8, C21; owner 2026-11-04): a click
|
// V1-2.6 geometry and adversarial cases (contract C7, C8, C21; owner 2026-11-04): a click
|
||||||
@@ -211,8 +212,8 @@ test.describe('editor geometry (adversarial)', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// A partial move (still out of the frame): refused by the core, the point restored.
|
// A partial move (still out of the frame): refused by the core, the point restored.
|
||||||
// Nothing around the drawing moves (A14), wherever the page is scrolled: the issue
|
// Nothing around the drawing moves (A14), from the page's top here.
|
||||||
// lives in the strip and the dialog, the side column keeps the overview (U2 Task 6).
|
await scrollToTop(page)
|
||||||
await expectNoShift(page, () => move.click())
|
await expectNoShift(page, () => move.click())
|
||||||
await dragInMode(page, { x: 250, y: 250 }, { x: 260, y: 260 })
|
await dragInMode(page, { x: 250, y: 250 }, { x: 260, y: 260 })
|
||||||
await expectNoShift(page, async () => {
|
await expectNoShift(page, async () => {
|
||||||
@@ -226,13 +227,20 @@ test.describe('editor geometry (adversarial)', () => {
|
|||||||
await expect(shownShape(page)).toHaveAttribute('cx', '110')
|
await expect(shownShape(page)).toHaveAttribute('cx', '110')
|
||||||
await expect(verification).toContainText(String(errorsBefore))
|
await expect(verification).toContainText(String(errorsBefore))
|
||||||
|
|
||||||
// Far enough inside: kept, the issue gone, one error less.
|
// Far enough inside, from the page's end: kept, the issue gone, one error less. The
|
||||||
await expectNoShift(page, () => move.click())
|
// issue leaving no longer shortens the page (it lives in the strip and the dialog, the
|
||||||
|
// side column keeps the overview, U2 Task 6), so the scroll clamp moves nothing. The
|
||||||
|
// buttons are pressed in place (no scroll into view), the page stays at its end.
|
||||||
|
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight))
|
||||||
|
const end = await page.evaluate(() => window.scrollY)
|
||||||
|
expect(end, 'the page scrolls: its end is not its top').toBeGreaterThan(0)
|
||||||
|
await expectNoShift(page, () => move.dispatchEvent('click'))
|
||||||
await dragInMode(page, { x: 250, y: 250 }, { x: 290, y: 290 })
|
await dragInMode(page, { x: 250, y: 250 }, { x: 290, y: 290 })
|
||||||
await expectNoShift(page, async () => {
|
await expectNoShift(page, async () => {
|
||||||
await confirm.click()
|
await confirm.dispatchEvent('click')
|
||||||
await expect(notice).not.toContainText(issue)
|
await expect(notice).not.toContainText(issue)
|
||||||
})
|
})
|
||||||
|
expect(await page.evaluate(() => window.scrollY)).toBe(end)
|
||||||
expect(Math.abs((await shownNumber(page, 'cx')) - 150)).toBeLessThan(2)
|
expect(Math.abs((await shownNumber(page, 'cx')) - 150)).toBeLessThan(2)
|
||||||
const after = (await verification.innerText()).replace(/\D/g, '')
|
const after = (await verification.innerText()).replace(/\D/g, '')
|
||||||
expect(Number(after || 0)).toBeLessThan(errorsBefore)
|
expect(Number(after || 0)).toBeLessThan(errorsBefore)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import type { CDPSession, Page, TestInfo } from '@playwright/test'
|
|||||||
import { expect, expectAccessible, test } from '../support/browser'
|
import { expect, expectAccessible, test } from '../support/browser'
|
||||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||||
import {
|
import {
|
||||||
clickDrawing,
|
|
||||||
clientOf,
|
clientOf,
|
||||||
editorActor,
|
editorActor,
|
||||||
openEditor,
|
openEditor,
|
||||||
@@ -60,6 +59,27 @@ const dialog = (page: Page) => page.getByRole('dialog')
|
|||||||
const box = async (page: Page, selector: string) =>
|
const box = async (page: Page, selector: string) =>
|
||||||
(await page.locator(selector).locator('visible=true').first().boundingBox())!
|
(await page.locator(selector).locator('visible=true').first().boundingBox())!
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts the clicks and double clicks the document receives, from now on, in the capture
|
||||||
|
* phase before any other listener: a wait on the click itself, never on a delay.
|
||||||
|
*/
|
||||||
|
async function countClicks(page: Page) {
|
||||||
|
await page.evaluate(() => {
|
||||||
|
const scope = window as unknown as { __clicks: Record<string, number> }
|
||||||
|
scope.__clicks = { click: 0, dblclick: 0 }
|
||||||
|
for (const type of ['click', 'dblclick'])
|
||||||
|
document.addEventListener(type, () => (scope.__clicks[type] += 1), true)
|
||||||
|
})
|
||||||
|
return (type: 'click' | 'dblclick') =>
|
||||||
|
page.evaluate(
|
||||||
|
(kind) =>
|
||||||
|
(window as unknown as { __clicks: Record<string, number> }).__clicks[
|
||||||
|
kind
|
||||||
|
],
|
||||||
|
type,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
type TouchPoint = { x: number; y: number }
|
type TouchPoint = { x: number; y: number }
|
||||||
const touch = (
|
const touch = (
|
||||||
cdp: CDPSession,
|
cdp: CDPSession,
|
||||||
@@ -185,9 +205,11 @@ test.describe('the properties dialog (U2 Task 6)', () => {
|
|||||||
await pickAnnotation(page, dict, ZONE)
|
await pickAnnotation(page, dict, ZONE)
|
||||||
const before = await shownPoints(page)
|
const before = await shownPoints(page)
|
||||||
const inside = await clientOf(page, 250, 250)
|
const inside = await clientOf(page, 250, 250)
|
||||||
|
const clicks = await countClicks(page)
|
||||||
await page.mouse.dblclick(inside.x, inside.y)
|
await page.mouse.dblclick(inside.x, inside.y)
|
||||||
await expect(dialog(page)).toBeVisible()
|
// The second click and the dblclick have landed (on the veil): the dialog stays.
|
||||||
await page.waitForTimeout(500)
|
await expect.poll(() => clicks('dblclick')).toBe(1)
|
||||||
|
expect(await clicks('click')).toBe(2)
|
||||||
await expect(dialog(page)).toBeVisible()
|
await expect(dialog(page)).toBeVisible()
|
||||||
await page.keyboard.press('Escape')
|
await page.keyboard.press('Escape')
|
||||||
await expect(dialog(page)).toHaveCount(0)
|
await expect(dialog(page)).toHaveCount(0)
|
||||||
@@ -252,13 +274,17 @@ test.describe('the properties dialog by touch (U2 Task 6, Review Focus 5)', () =
|
|||||||
await pickAnnotation(page, dict, ZONE)
|
await pickAnnotation(page, dict, ZONE)
|
||||||
const cdp = await context.newCDPSession(page)
|
const cdp = await context.newCDPSession(page)
|
||||||
const inside = await clientOf(page, 250, 250)
|
const inside = await clientOf(page, 250, 250)
|
||||||
|
const clicks = await countClicks(page)
|
||||||
await touch(cdp, 'touchStart', [inside])
|
await touch(cdp, 'touchStart', [inside])
|
||||||
await touch(cdp, 'touchEnd', [])
|
await touch(cdp, 'touchEnd', [])
|
||||||
await expect(dialog(page)).toBeVisible()
|
// The click the browser synthesises after the tap has landed: the dialog stays open.
|
||||||
await page.waitForTimeout(500)
|
await expect.poll(() => clicks('click')).toBe(1)
|
||||||
await expect(dialog(page)).toBeVisible()
|
await expect(dialog(page)).toBeVisible()
|
||||||
await expect(selectionTag(page)).toContainText(ZONE)
|
await expect(selectionTag(page)).toContainText(ZONE)
|
||||||
await clickDrawing(page, 900, 600).catch(() => undefined)
|
// A stray click on the veil, over the drawing (R-6): it lands, nothing closes.
|
||||||
|
const stray = await clientOf(page, 900, 600)
|
||||||
|
await page.mouse.click(stray.x, stray.y)
|
||||||
|
await expect.poll(() => clicks('click')).toBe(2)
|
||||||
await expect(dialog(page)).toBeVisible()
|
await expect(dialog(page)).toBeVisible()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
selectionTag,
|
selectionTag,
|
||||||
shownPoints,
|
shownPoints,
|
||||||
toolButton,
|
toolButton,
|
||||||
|
scrollToTop,
|
||||||
} from '../support/editor'
|
} from '../support/editor'
|
||||||
import { expectNoShift } from '../support/layout'
|
import { expectNoShift } from '../support/layout'
|
||||||
|
|
||||||
@@ -133,6 +134,8 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
|||||||
const actor = await openThoracic(page)
|
const actor = await openThoracic(page)
|
||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
await pickAnnotation(page, dict, THORACIC)
|
await pickAnnotation(page, dict, THORACIC)
|
||||||
|
// The row sits low in the equine list: the click left the drawing out of view.
|
||||||
|
await scrollToTop(page)
|
||||||
await expect(selectionTag(page)).toContainText('Vertèbres thoraciques')
|
await expect(selectionTag(page)).toContainText('Vertèbres thoraciques')
|
||||||
await expect(handle(page, 'Sommet 9')).toBeAttached()
|
await expect(handle(page, 'Sommet 9')).toBeAttached()
|
||||||
// R-18: at fit zoom some segments are too short for their « + ».
|
// R-18: at fit zoom some segments are too short for their « + ».
|
||||||
@@ -225,6 +228,8 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
|||||||
const actor = await openThoracic(page)
|
const actor = await openThoracic(page)
|
||||||
requests.forbid(actor.account.email, actor.account.password)
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
await pickAnnotation(page, dict, THORACIC)
|
await pickAnnotation(page, dict, THORACIC)
|
||||||
|
// The row sits low in the equine list: the click left the drawing out of view.
|
||||||
|
await scrollToTop(page)
|
||||||
const stored = await shownPoints(page)
|
const stored = await shownPoints(page)
|
||||||
|
|
||||||
// Accepted: four clicks, « Fermer le tracé », one commit, every property kept.
|
// Accepted: four clicks, « Fermer le tracé », one commit, every property kept.
|
||||||
@@ -284,6 +289,8 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => {
|
|||||||
// Thoraciques selected: zoomed at C7-T1 so that its vertex handles leave room, a click
|
// Thoraciques selected: zoomed at C7-T1 so that its vertex handles leave room, a click
|
||||||
// inside both shapes still selects the point (the selection's interior comes after).
|
// inside both shapes still selects the point (the selection's interior comes after).
|
||||||
await pickAnnotation(page, dict, THORACIC)
|
await pickAnnotation(page, dict, THORACIC)
|
||||||
|
// The row sits low in the equine list: the click left the drawing out of view.
|
||||||
|
await scrollToTop(page)
|
||||||
const at = await clientOf(page, 870, 515)
|
const at = await clientOf(page, 870, 515)
|
||||||
await page.mouse.move(at.x, at.y)
|
await page.mouse.move(at.x, at.y)
|
||||||
await page.keyboard.down('Control')
|
await page.keyboard.down('Control')
|
||||||
|
|||||||
@@ -764,8 +764,14 @@ export async function pickAnnotation(
|
|||||||
const list = annotationList(page, dict)
|
const list = annotationList(page, dict)
|
||||||
await expect(list).toBeVisible()
|
await expect(list).toBeVisible()
|
||||||
await list.getByRole('button', { name }).click()
|
await list.getByRole('button', { name }).click()
|
||||||
// The click scrolled the page to the row, lower in the column: the drawing the next
|
}
|
||||||
// steps press on is brought back into view (the overview no longer shortens the page).
|
|
||||||
|
/**
|
||||||
|
* Back to the page's top: a row click low in the overview leaves the page scrolled there
|
||||||
|
* (the column no longer shortens on a selection, U2 Task 6), with the drawing or the strip
|
||||||
|
* out of view for the steps that press on them by coordinates.
|
||||||
|
*/
|
||||||
|
export async function scrollToTop(page: Page) {
|
||||||
await page.evaluate(() => window.scrollTo(0, 0))
|
await page.evaluate(() => window.scrollTo(0, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ export default function AnnotationDialog(props: AnnotationDialogProps) {
|
|||||||
open={visible && annotation !== undefined}
|
open={visible && annotation !== undefined}
|
||||||
layer
|
layer
|
||||||
anchor={props.anchor}
|
anchor={props.anchor}
|
||||||
|
veilCloses={false}
|
||||||
title={title}
|
title={title}
|
||||||
returnFocus={props.returnFocus}
|
returnFocus={props.returnFocus}
|
||||||
onClose={() => (layer.close() ? undefined : 'kept')}
|
onClose={() => (layer.close() ? undefined : 'kept')}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useState } from 'react'
|
|||||||
import type {
|
import type {
|
||||||
AnatomicalSheetDocument,
|
AnatomicalSheetDocument,
|
||||||
Annotation,
|
Annotation,
|
||||||
|
Laterality,
|
||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import { FormActions } from '@/components/editor/findings/DiscardConfirm'
|
import { FormActions } from '@/components/editor/findings/DiscardConfirm'
|
||||||
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
|
import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice'
|
||||||
@@ -66,34 +67,66 @@ const normalized = (draft: Draft): Draft => ({
|
|||||||
const sameDraft = (a: Draft, b: Draft) =>
|
const sameDraft = (a: Draft, b: Draft) =>
|
||||||
JSON.stringify(normalized(a)) === JSON.stringify(normalized(b))
|
JSON.stringify(normalized(a)) === JSON.stringify(normalized(b))
|
||||||
|
|
||||||
/** The names as saved: trimmed, or none for a link left with both blank. */
|
/** Whether the user changed a field of the draft since the form opened. */
|
||||||
function namesOf(annotation: Annotation, draft: Draft) {
|
type Changed = (key: keyof Draft) => boolean
|
||||||
const name = { fr: draft.fr.trim(), en: draft.en.trim() }
|
|
||||||
const none = name.fr === '' && name.en === ''
|
/**
|
||||||
return annotation.kind === 'detail_trigger' && none ? null : name
|
* Each name on its own: the draft's when the user changed it, else the CURRENT one (an EN
|
||||||
|
* refreshed meanwhile is kept when only FR was edited).
|
||||||
|
*/
|
||||||
|
function namesOf(current: Annotation, now: Draft, changed: Changed) {
|
||||||
|
return {
|
||||||
|
fr: changed('fr') ? now.fr : (current.name?.fr ?? ''),
|
||||||
|
en: changed('en') ? now.en : (current.name?.en ?? ''),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Category, laterality and colour: the changed ones from the draft. */
|
||||||
|
function commonOf(current: Annotation, now: Draft, changed: Changed) {
|
||||||
|
return {
|
||||||
|
category_id: changed('categoryId') ? now.categoryId : current.category_id,
|
||||||
|
// Not blank here: `missingFields` refused the save before.
|
||||||
|
laterality: changed('laterality')
|
||||||
|
? (now.laterality as Laterality)
|
||||||
|
: current.laterality,
|
||||||
|
color: changed('color') ? nullable(now.color) : current.color,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CURRENT annotation with only the fields the user changed (`first` → `draft`): a
|
* The CURRENT annotation with only the fields the user changed (`first` → `draft`): a
|
||||||
* change made meanwhile elsewhere (a drag, a review toggle) is never overwritten.
|
* change made meanwhile elsewhere (a drag, a review toggle, a refresh) is never
|
||||||
|
* overwritten. Typed per kind, so a misspelt field fails to compile.
|
||||||
*/
|
*/
|
||||||
function merged(current: Annotation, first: Draft, draft: Draft): Annotation {
|
function merged(current: Annotation, first: Draft, draft: Draft): Annotation {
|
||||||
const was = normalized(first)
|
const was = normalized(first)
|
||||||
const now = normalized(draft)
|
const now = normalized(draft)
|
||||||
const changed = (key: keyof Draft) => was[key] !== now[key]
|
const changed: Changed = (key) => was[key] !== now[key]
|
||||||
const value: Record<string, unknown> = { ...current }
|
const named = changed('fr') || changed('en')
|
||||||
if (changed('fr') || changed('en')) value.name = namesOf(current, draft)
|
const names = namesOf(current, now, changed)
|
||||||
if (changed('categoryId')) value.category_id = draft.categoryId
|
const common = commonOf(current, now, changed)
|
||||||
if (changed('laterality')) value.laterality = draft.laterality
|
|
||||||
if (changed('color')) value.color = nullable(draft.color.trim())
|
|
||||||
if (current.kind === 'detail_trigger') {
|
if (current.kind === 'detail_trigger') {
|
||||||
if (changed('opensViewId')) value.opens_view_id = draft.opensViewId
|
const none = names.fr === '' && names.en === ''
|
||||||
} else {
|
return {
|
||||||
if (changed('zoneId')) value.finding_zone_id = nullable(draft.zoneId)
|
...current,
|
||||||
if (changed('regionCode'))
|
...common,
|
||||||
value.vertebral_region_code = nullable(draft.regionCode)
|
name: named ? (none ? null : names) : current.name,
|
||||||
|
opens_view_id: changed('opensViewId')
|
||||||
|
? now.opensViewId
|
||||||
|
: current.opens_view_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...current,
|
||||||
|
...common,
|
||||||
|
name: named ? names : current.name,
|
||||||
|
finding_zone_id: changed('zoneId')
|
||||||
|
? nullable(now.zoneId)
|
||||||
|
: current.finding_zone_id,
|
||||||
|
vertebral_region_code: changed('regionCode')
|
||||||
|
? nullable(now.regionCode)
|
||||||
|
: current.vertebral_region_code,
|
||||||
}
|
}
|
||||||
return value as unknown as Annotation
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The annotation as the document holds it now, read by id at the save. */
|
/** The annotation as the document holds it now, read by id at the save. */
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ function useCreation(props: CreationPanelProps) {
|
|||||||
const [messages, setMessages] = useState<string[]>([])
|
const [messages, setMessages] = useState<string[]>([])
|
||||||
const settle = (attempt: Attempt) => {
|
const settle = (attempt: Attempt) => {
|
||||||
const { dispatch, pending } = props
|
const { dispatch, pending } = props
|
||||||
|
// shortcut: the general lines `editor.annotations.required.{fields,names}` (R-3 removes
|
||||||
|
// them) stay until Task 7. Upgrade: the creation dialog names each field through
|
||||||
|
// `missingFields` and the `editor.annotations.missing.*` keys, as the edit form does.
|
||||||
setMessages(
|
setMessages(
|
||||||
messagesOf(attempt, (p) => t(`editor.annotations.required.${p}`)),
|
messagesOf(attempt, (p) => t(`editor.annotations.required.${p}`)),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ export interface DialogProps {
|
|||||||
* under a lighter veil that ignores clicks (R-6). Without a box, the panel is centred.
|
* under a lighter veil that ignores clicks (R-6). Without a box, the panel is centred.
|
||||||
*/
|
*/
|
||||||
anchor?: RefObject<HTMLElement | null>
|
anchor?: RefObject<HTMLElement | null>
|
||||||
|
/**
|
||||||
|
* False: a click on the veil does nothing, even centred (R-6: the annotation dialogs, so
|
||||||
|
* the tap that opened one never closes it). An anchored dialog's veil never closes.
|
||||||
|
*/
|
||||||
|
veilCloses?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const SIZE: Record<NonNullable<DialogProps['size']>, string> = {
|
const SIZE: Record<NonNullable<DialogProps['size']>, string> = {
|
||||||
@@ -83,6 +88,7 @@ function DialogSurface({
|
|||||||
children,
|
children,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
anchor,
|
anchor,
|
||||||
|
veilCloses = true,
|
||||||
}: Omit<DialogProps, 'open'>) {
|
}: Omit<DialogProps, 'open'>) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const reduced = useReducedMotion()
|
const reduced = useReducedMotion()
|
||||||
@@ -107,7 +113,7 @@ function DialogSurface({
|
|||||||
exit={{ opacity: 0 }}
|
exit={{ opacity: 0 }}
|
||||||
transition={{ duration: reduced ? 0 : 0.15 }}
|
transition={{ duration: reduced ? 0 : 0.15 }}
|
||||||
// R-6: over a column, the tap that opened the dialog never closes it.
|
// R-6: over a column, the tap that opened the dialog never closes it.
|
||||||
onClick={place ? undefined : onClose}
|
onClick={place || !veilCloses ? undefined : onClose}
|
||||||
/>
|
/>
|
||||||
<motion.div
|
<motion.div
|
||||||
data-testid="dialog-panel"
|
data-testid="dialog-panel"
|
||||||
|
|||||||
@@ -70,9 +70,10 @@ function showAnnotation(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* « Aller à » an annotation on the drawing (R-5): shows its view, selects it, then focuses
|
* « Aller à » an annotation on the drawing (R-5): shows its view, selects it, then focuses
|
||||||
* its row (the drawing when a filter hides it) once it has rendered; no dialog opens (A1). While a creation or a tracing is in progress
|
* its row (the drawing when a filter hides it) once it has rendered; no dialog opens
|
||||||
* the request is kept: nothing is dispatched (it would drop the work), the panel or the
|
* (A1). While a creation or a tracing is in progress the request is kept: nothing is
|
||||||
* strip's tracing commands take the focus and the live region says why.
|
* dispatched (it would drop the work), the panel or the strip's tracing commands take the
|
||||||
|
* focus and the live region says why.
|
||||||
*/
|
*/
|
||||||
export function useAnnotationRequest(
|
export function useAnnotationRequest(
|
||||||
focus: FocusRequest | undefined,
|
focus: FocusRequest | undefined,
|
||||||
|
|||||||
@@ -57,6 +57,23 @@ const zone = (id: string, patch: Partial<Annotation> = {}): Annotation =>
|
|||||||
...patch,
|
...patch,
|
||||||
}) as Annotation
|
}) 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 {
|
function stubCtm(): void {
|
||||||
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
|
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
|
||||||
Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', {
|
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 () => {
|
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 mount(insert(drawnText(), { kind: 'annotation', value: zone('z') }))
|
||||||
await selectRow('z')
|
await selectRow('z')
|
||||||
useAnnotationWork.setState({
|
act(() =>
|
||||||
chosen: {
|
useAnnotationWork.setState({
|
||||||
annotationId: 'z',
|
chosen: {
|
||||||
vertex: 1,
|
annotationId: 'z',
|
||||||
base: store.getState().documentText,
|
vertex: 1,
|
||||||
},
|
base: store.getState().documentText,
|
||||||
})
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
pressAt(marker('z'), 50, 50)
|
pressAt(marker('z'), 50, 50)
|
||||||
expect(useAnnotationWork.getState().chosen).toBeNull()
|
expect(useAnnotationWork.getState().chosen).toBeNull()
|
||||||
expect(dialog()).toBeNull()
|
expect(dialog()).toBeNull()
|
||||||
@@ -159,6 +178,39 @@ describe('opening (A1)', () => {
|
|||||||
expect(await screen.findByRole('dialog')).toBeVisible()
|
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 () => {
|
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 mount(insert(drawnText(), point('a', 50, 50, 5)))
|
||||||
await selectRow('a')
|
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 () => {
|
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', {
|
const value = zone('z', {
|
||||||
color: '#aa0000',
|
color: '#aa0000',
|
||||||
vertebral_region_code: code,
|
vertebral_region_code: 'C',
|
||||||
} as Partial<Annotation>)
|
} 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 selectRow('z')
|
||||||
await openProperties()
|
await openProperties()
|
||||||
expect(rows()).toContain('Couleur')
|
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('#aa0000')).toBeInTheDocument()
|
||||||
|
expect(within(dialog()!).getByText('Cervicales')).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('an unnamed link: its opened view, « Vue ouverte », no findings zone', async () => {
|
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)', () => {
|
describe('the edit form (board 31 C, R-3)', () => {
|
||||||
it('category and both names saved: ONE history entry, the read mode back', async () => {
|
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 selectRow('a')
|
||||||
await startEdit()
|
await startEdit()
|
||||||
const user = userEvent.setup()
|
const user = userEvent.setup()
|
||||||
@@ -315,15 +362,14 @@ describe('the edit form (board 31 C, R-3)', () => {
|
|||||||
const category = within(dialog()!).getByLabelText(
|
const category = within(dialog()!).getByLabelText(
|
||||||
'Catégorie',
|
'Catégorie',
|
||||||
) as HTMLSelectElement
|
) as HTMLSelectElement
|
||||||
const other = [...category.options].find((o) => !o.selected)
|
await user.selectOptions(category, 'cat-b')
|
||||||
if (other) await user.selectOptions(category, other.value)
|
|
||||||
expect(depth()).toBe(before)
|
expect(depth()).toBe(before)
|
||||||
await user.click(
|
await user.click(
|
||||||
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
|
within(dialog()!).getByRole('button', { name: 'Enregistrer' }),
|
||||||
)
|
)
|
||||||
expect(depth()).toBe(before + 1)
|
expect(depth()).toBe(before + 1)
|
||||||
expect(annotationOf('a').name).toEqual({ fr: 'Grasset', en: 'Stifle' })
|
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(
|
expect(
|
||||||
within(dialog()!).getByText('Modifications enregistrées'),
|
within(dialog()!).getByText('Modifications enregistrées'),
|
||||||
).toBeInTheDocument()
|
).toBeInTheDocument()
|
||||||
@@ -354,6 +400,27 @@ describe('the edit form (board 31 C, R-3)', () => {
|
|||||||
expect(annotationOf('a').name?.fr).toBe('Nx')
|
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 () => {
|
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 mount(insert(drawnText(), point('a', 50, 50, 5)))
|
||||||
await selectRow('a')
|
await selectRow('a')
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest'
|
import { afterEach, describe, it, expect, vi } from 'vitest'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
@@ -251,6 +251,13 @@ describe('Dialog anchored over a column', () => {
|
|||||||
configurable: true,
|
configurable: true,
|
||||||
value,
|
value,
|
||||||
})
|
})
|
||||||
|
const height = window.innerHeight
|
||||||
|
const viewport = Object.getOwnPropertyDescriptor(window, 'visualViewport')
|
||||||
|
afterEach(() => {
|
||||||
|
window.innerHeight = height
|
||||||
|
if (viewport) Object.defineProperty(window, 'visualViewport', viewport)
|
||||||
|
else withViewport(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
it('sits at the anchor’s left and width, from its top, down to 12 px above the bottom', () => {
|
it('sits at the anchor’s left and width, from its top, down to 12 px above the bottom', () => {
|
||||||
withViewport(undefined)
|
withViewport(undefined)
|
||||||
@@ -297,7 +304,6 @@ describe('Dialog anchored over a column', () => {
|
|||||||
expect(panel().style.top).toBe('12px')
|
expect(panel().style.top).toBe('12px')
|
||||||
expect(panel().style.height).toBe('326px')
|
expect(panel().style.height).toBe('326px')
|
||||||
expect(panel().style.left).toBe('900px')
|
expect(panel().style.left).toBe('900px')
|
||||||
withViewport(undefined)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('without an anchor box the panel is centred, as before', () => {
|
it('without an anchor box the panel is centred, as before', () => {
|
||||||
@@ -330,4 +336,15 @@ describe('Dialog anchored over a column', () => {
|
|||||||
await userEvent.click(screen.getByTestId('dialog-backdrop'))
|
await userEvent.click(screen.getByTestId('dialog-backdrop'))
|
||||||
expect(onClose).toHaveBeenCalled()
|
expect(onClose).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('a centred dialog whose veil must not close (R-6) ignores its clicks too', async () => {
|
||||||
|
const onClose = vi.fn()
|
||||||
|
render(
|
||||||
|
<Dialog open veilCloses={false} onClose={onClose} title="X">
|
||||||
|
body
|
||||||
|
</Dialog>,
|
||||||
|
)
|
||||||
|
await userEvent.click(screen.getByTestId('dialog-backdrop'))
|
||||||
|
expect(onClose).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user