From 9a0fe3784c2f6a13fde03565149e290ca28bfb19 Mon Sep 17 00:00:00 2001 From: bchanot Date: Tue, 17 Nov 2026 22:47:02 +0100 Subject: [PATCH] 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. --- .claude/tasks/TODO.md | 3 +- apps/app/e2e/shell/editor-geometry.spec.ts | 18 ++- apps/app/e2e/shell/editor-properties.spec.ts | 38 ++++++- apps/app/e2e/shell/editor-zones.spec.ts | 7 ++ apps/app/e2e/support/editor.ts | 10 +- .../editor/annotations/AnnotationDialog.tsx | 1 + .../editor/annotations/AnnotationEditForm.tsx | 69 ++++++++--- .../editor/annotations/CreationPanel.tsx | 3 + apps/app/src/components/ui/Dialog.tsx | 8 +- .../app/src/editor/annotations/focusTarget.ts | 7 +- .../unit/editor-annotation-dialog.test.tsx | 107 ++++++++++++++---- apps/app/tests/unit/ui.Dialog.test.tsx | 21 +++- 12 files changed, 234 insertions(+), 58 deletions(-) diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index b206eba0..941fa747 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -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 - [ ] `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). - - [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). - [ ] 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. diff --git a/apps/app/e2e/shell/editor-geometry.spec.ts b/apps/app/e2e/shell/editor-geometry.spec.ts index d978bd7d..581203f3 100644 --- a/apps/app/e2e/shell/editor-geometry.spec.ts +++ b/apps/app/e2e/shell/editor-geometry.spec.ts @@ -22,6 +22,7 @@ import { shapeWith, standardShape, openProperties, + scrollToTop, } from '../support/editor' // 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. - // Nothing around the drawing moves (A14), wherever the page is scrolled: the issue - // lives in the strip and the dialog, the side column keeps the overview (U2 Task 6). + // Nothing around the drawing moves (A14), from the page's top here. + await scrollToTop(page) await expectNoShift(page, () => move.click()) await dragInMode(page, { x: 250, y: 250 }, { x: 260, y: 260 }) await expectNoShift(page, async () => { @@ -226,13 +227,20 @@ test.describe('editor geometry (adversarial)', () => { await expect(shownShape(page)).toHaveAttribute('cx', '110') await expect(verification).toContainText(String(errorsBefore)) - // Far enough inside: kept, the issue gone, one error less. - await expectNoShift(page, () => move.click()) + // Far enough inside, from the page's end: kept, the issue gone, one error less. The + // 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 expectNoShift(page, async () => { - await confirm.click() + await confirm.dispatchEvent('click') await expect(notice).not.toContainText(issue) }) + expect(await page.evaluate(() => window.scrollY)).toBe(end) expect(Math.abs((await shownNumber(page, 'cx')) - 150)).toBeLessThan(2) const after = (await verification.innerText()).replace(/\D/g, '') expect(Number(after || 0)).toBeLessThan(errorsBefore) diff --git a/apps/app/e2e/shell/editor-properties.spec.ts b/apps/app/e2e/shell/editor-properties.spec.ts index f4e6f3c5..cd4ca5ec 100644 --- a/apps/app/e2e/shell/editor-properties.spec.ts +++ b/apps/app/e2e/shell/editor-properties.spec.ts @@ -3,7 +3,6 @@ import type { CDPSession, Page, TestInfo } from '@playwright/test' import { expect, expectAccessible, test } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { - clickDrawing, clientOf, editorActor, openEditor, @@ -60,6 +59,27 @@ const dialog = (page: Page) => page.getByRole('dialog') const box = async (page: Page, selector: string) => (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 } + 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 }).__clicks[ + kind + ], + type, + ) +} + type TouchPoint = { x: number; y: number } const touch = ( cdp: CDPSession, @@ -185,9 +205,11 @@ test.describe('the properties dialog (U2 Task 6)', () => { await pickAnnotation(page, dict, ZONE) const before = await shownPoints(page) const inside = await clientOf(page, 250, 250) + const clicks = await countClicks(page) await page.mouse.dblclick(inside.x, inside.y) - await expect(dialog(page)).toBeVisible() - await page.waitForTimeout(500) + // The second click and the dblclick have landed (on the veil): the dialog stays. + await expect.poll(() => clicks('dblclick')).toBe(1) + expect(await clicks('click')).toBe(2) await expect(dialog(page)).toBeVisible() await page.keyboard.press('Escape') 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) const cdp = await context.newCDPSession(page) const inside = await clientOf(page, 250, 250) + const clicks = await countClicks(page) await touch(cdp, 'touchStart', [inside]) await touch(cdp, 'touchEnd', []) - await expect(dialog(page)).toBeVisible() - await page.waitForTimeout(500) + // The click the browser synthesises after the tap has landed: the dialog stays open. + await expect.poll(() => clicks('click')).toBe(1) await expect(dialog(page)).toBeVisible() 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() }) }) diff --git a/apps/app/e2e/shell/editor-zones.spec.ts b/apps/app/e2e/shell/editor-zones.spec.ts index e95521b5..b9a8b03c 100644 --- a/apps/app/e2e/shell/editor-zones.spec.ts +++ b/apps/app/e2e/shell/editor-zones.spec.ts @@ -13,6 +13,7 @@ import { selectionTag, shownPoints, toolButton, + scrollToTop, } from '../support/editor' import { expectNoShift } from '../support/layout' @@ -133,6 +134,8 @@ test.describe('editor zones on the drawing (U2 Task 5)', () => { const actor = await openThoracic(page) requests.forbid(actor.account.email, actor.account.password) 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(handle(page, 'Sommet 9')).toBeAttached() // 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) requests.forbid(actor.account.email, actor.account.password) 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) // 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 // inside both shapes still selects the point (the selection's interior comes after). 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) await page.mouse.move(at.x, at.y) await page.keyboard.down('Control') diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts index 3b0c765e..f00e993d 100644 --- a/apps/app/e2e/support/editor.ts +++ b/apps/app/e2e/support/editor.ts @@ -764,8 +764,14 @@ export async function pickAnnotation( const list = annotationList(page, dict) await expect(list).toBeVisible() 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)) } diff --git a/apps/app/src/components/editor/annotations/AnnotationDialog.tsx b/apps/app/src/components/editor/annotations/AnnotationDialog.tsx index d6131fe3..137c99cc 100644 --- a/apps/app/src/components/editor/annotations/AnnotationDialog.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationDialog.tsx @@ -262,6 +262,7 @@ export default function AnnotationDialog(props: AnnotationDialogProps) { open={visible && annotation !== undefined} layer anchor={props.anchor} + veilCloses={false} title={title} returnFocus={props.returnFocus} onClose={() => (layer.close() ? undefined : 'kept')} diff --git a/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx b/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx index 015f67db..cc1748b4 100644 --- a/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationEditForm.tsx @@ -2,6 +2,7 @@ import { useState } from 'react' import type { AnatomicalSheetDocument, Annotation, + Laterality, } from '@faunosteo/core-wasm/types' import { FormActions } from '@/components/editor/findings/DiscardConfirm' import ReadOnlyNotice from '@/components/editor/findings/ReadOnlyNotice' @@ -66,34 +67,66 @@ const normalized = (draft: Draft): Draft => ({ const sameDraft = (a: Draft, b: Draft) => JSON.stringify(normalized(a)) === JSON.stringify(normalized(b)) -/** The names as saved: trimmed, or none for a link left with both blank. */ -function namesOf(annotation: Annotation, draft: Draft) { - const name = { fr: draft.fr.trim(), en: draft.en.trim() } - const none = name.fr === '' && name.en === '' - return annotation.kind === 'detail_trigger' && none ? null : name +/** Whether the user changed a field of the draft since the form opened. */ +type Changed = (key: keyof Draft) => boolean + +/** + * 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 - * 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 { const was = normalized(first) const now = normalized(draft) - const changed = (key: keyof Draft) => was[key] !== now[key] - const value: Record = { ...current } - if (changed('fr') || changed('en')) value.name = namesOf(current, draft) - if (changed('categoryId')) value.category_id = draft.categoryId - if (changed('laterality')) value.laterality = draft.laterality - if (changed('color')) value.color = nullable(draft.color.trim()) + const changed: Changed = (key) => was[key] !== now[key] + const named = changed('fr') || changed('en') + const names = namesOf(current, now, changed) + const common = commonOf(current, now, changed) if (current.kind === 'detail_trigger') { - if (changed('opensViewId')) value.opens_view_id = draft.opensViewId - } else { - if (changed('zoneId')) value.finding_zone_id = nullable(draft.zoneId) - if (changed('regionCode')) - value.vertebral_region_code = nullable(draft.regionCode) + const none = names.fr === '' && names.en === '' + return { + ...current, + ...common, + 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. */ diff --git a/apps/app/src/components/editor/annotations/CreationPanel.tsx b/apps/app/src/components/editor/annotations/CreationPanel.tsx index f68c1858..79b961d5 100644 --- a/apps/app/src/components/editor/annotations/CreationPanel.tsx +++ b/apps/app/src/components/editor/annotations/CreationPanel.tsx @@ -47,6 +47,9 @@ function useCreation(props: CreationPanelProps) { const [messages, setMessages] = useState([]) const settle = (attempt: Attempt) => { 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( messagesOf(attempt, (p) => t(`editor.annotations.required.${p}`)), ) diff --git a/apps/app/src/components/ui/Dialog.tsx b/apps/app/src/components/ui/Dialog.tsx index ac3a0361..60dc259f 100644 --- a/apps/app/src/components/ui/Dialog.tsx +++ b/apps/app/src/components/ui/Dialog.tsx @@ -27,6 +27,11 @@ export interface DialogProps { * under a lighter veil that ignores clicks (R-6). Without a box, the panel is centred. */ anchor?: RefObject + /** + * 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, string> = { @@ -83,6 +88,7 @@ function DialogSurface({ children, size = 'md', anchor, + veilCloses = true, }: Omit) { const t = useT() const reduced = useReducedMotion() @@ -107,7 +113,7 @@ function DialogSurface({ exit={{ opacity: 0 }} transition={{ duration: reduced ? 0 : 0.15 }} // R-6: over a column, the tap that opened the dialog never closes it. - onClick={place ? undefined : onClose} + onClick={place || !veilCloses ? undefined : onClose} /> = {}): 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) - 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') diff --git a/apps/app/tests/unit/ui.Dialog.test.tsx b/apps/app/tests/unit/ui.Dialog.test.tsx index 2a4f8436..a8c3cc6e 100644 --- a/apps/app/tests/unit/ui.Dialog.test.tsx +++ b/apps/app/tests/unit/ui.Dialog.test.tsx @@ -1,4 +1,4 @@ -import { describe, it, expect, vi } from 'vitest' +import { afterEach, describe, it, expect, vi } from 'vitest' import { useState } from 'react' import { fireEvent, render, screen, waitFor } from '@testing-library/react' import userEvent from '@testing-library/user-event' @@ -251,6 +251,13 @@ describe('Dialog anchored over a column', () => { configurable: true, 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', () => { withViewport(undefined) @@ -297,7 +304,6 @@ describe('Dialog anchored over a column', () => { 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', () => { @@ -330,4 +336,15 @@ describe('Dialog anchored over a column', () => { await userEvent.click(screen.getByTestId('dialog-backdrop')) expect(onClose).toHaveBeenCalled() }) + + it('a centred dialog whose veil must not close (R-6) ignores its clicks too', async () => { + const onClose = vi.fn() + render( + + body + , + ) + await userEvent.click(screen.getByTestId('dialog-backdrop')) + expect(onClose).not.toHaveBeenCalled() + }) })