diff --git a/apps/app/src/components/editor/annotations/SceneStrip.tsx b/apps/app/src/components/editor/annotations/SceneStrip.tsx index 845ab40d..65c3f461 100644 --- a/apps/app/src/components/editor/annotations/SceneStrip.tsx +++ b/apps/app/src/components/editor/annotations/SceneStrip.tsx @@ -75,11 +75,12 @@ export default function SceneStrip({ doc, { t, locale, chosenVertex }, ) + const access = showsAccessCommands(work.target, chosenVertex) const commandsKey = commandsKeyOf( scene, mode !== null, work.target, - chosenVertex, + { chosen: chosenVertex, access }, frame, ) return ( @@ -87,7 +88,12 @@ export default function SceneStrip({ lead={lead} notice={notice} commands={ - + } commandsKey={commandsKey} /> @@ -109,7 +115,7 @@ function commandsKeyOf( { ui, tracing, creation }: Scene, moving: boolean, target: Annotation | null, - chosen: number | null, + { chosen, access }: { chosen: number | null; access: boolean }, frame: FrameWork | null, ) { if (frame) return frameKeyOf(frame) @@ -117,7 +123,7 @@ function commandsKeyOf( if (creation?.resumed) return `creation-${creation.pending.geometry.type}` if (tracing) return 'tracing' if (moving) return 'move' - if (showsAccessCommands(target, chosen)) return 'access' + if (access) return 'access' if (target?.geometry?.type === 'polygon') return `zone-${chosen !== null}` if (target?.kind === 'point') return 'point' if (ui.selectedId !== null) return `selected-${target?.kind}` @@ -176,11 +182,18 @@ interface AccessStripProps { } /** The selection's own commands: a polygon's, a movable point's (R-10: a link circle none). */ -function ShapeCommands({ scene, work }: { scene: Scene; work: Work }) { +function ShapeCommands({ + scene, + work, + access, +}: { + scene: Scene + work: Work + access: boolean +}) { const t = useT() const { doc, viewId, frame, dispatch, selected, model } = scene - const chosen = useChosenVertex(work.target?.id) - if (work.target && showsAccessCommands(work.target, chosen)) { + if (work.target && access) { return } if (work.target?.geometry?.type === 'polygon') { @@ -248,10 +261,12 @@ function SceneCommands({ scene, work, moving, + access, }: { scene: Scene work: Work moving: boolean + access: boolean }) { const { ui, doc, viewId, frame, dispatch, selected, creation, tracing } = scene @@ -259,8 +274,6 @@ function SceneCommands({ dispatch({ type: 'select', id: null }), ) const framing = useAnnotationWork((s) => s.frame) - const chosen = useChosenVertex(selected?.id) - const accessOwnsProperties = showsAccessCommands(work.target, chosen) if (framing) return // The dialog shown: its own actions; hidden after it was shown: board 04 C. if (creation?.dialog) return null @@ -299,14 +312,12 @@ function SceneCommands({ if (selected) { return ( <> - + {/* During the move mode only the mode's own exits (its bar). */} {!moving && ( scene.onOpen(selected.id, 'button') + access ? undefined : () => scene.onOpen(selected.id, 'button') } onDeselect={byButton} /> diff --git a/apps/app/tests/unit/editor-access-commands.test.tsx b/apps/app/tests/unit/editor-access-commands.test.tsx index 96498d4c..f446fa35 100644 --- a/apps/app/tests/unit/editor-access-commands.test.tsx +++ b/apps/app/tests/unit/editor-access-commands.test.tsx @@ -219,6 +219,41 @@ describe('a selected access', () => { }) }) +describe('the head access', () => { + // A polygon access in an ordinary category (Articulations), not in cat-access. + const HEAD: Point[] = [ + [30, 10], + [70, 15], + [85, 45], + [60, 60], + [25, 40], + ] + + it('gets the same access commands', async () => { + const joints = insert(withAccess({ type: 'polygon', points: HEAD }), { + kind: 'category', + value: { + id: 'cat-joints', + name: { fr: 'Articulations', en: 'Joints' }, + color: null, + }, + }) + const text = joints.replace( + /("id":\s*"l"[^]*?"category_id":\s*")cat-a/, + '$1cat-joints', + ) + await mount(text) + const strip = await select() + expect(annotationOf('l').category_id).toBe('cat-joints') + for (const name of ["Déplacer l'accès", 'Propriétés', 'Désélectionner']) { + expect(within(strip).getByRole('button', { name })).toBeInTheDocument() + } + expect( + within(strip).queryByRole('button', { name: 'Supprimer' }), + ).toBeNull() + }) +}) + describe('AccessCommands', () => { it('renders only the commands whose handler is given', () => { const onOpen = vi.fn() diff --git a/apps/app/tests/unit/editor-point-edit.test.tsx b/apps/app/tests/unit/editor-point-edit.test.tsx index 6f167b13..17deece0 100644 --- a/apps/app/tests/unit/editor-point-edit.test.tsx +++ b/apps/app/tests/unit/editor-point-edit.test.tsx @@ -633,7 +633,7 @@ describe('review fixes: no silent loss, no empty commit, no lost focus', () => { expect(depth()).toBe(before + 1) }) - it('a link circle keeps its handle (« Accès … ») but gets no size and no move mode', async () => { + it('a link circle keeps its handle, gets no size slider, and the access move', async () => { await mount(withLink(two(), 'l')) await select(2) expect(screen.getByTestId('point-handle')).toHaveAccessibleName(/^Accès /) @@ -641,6 +641,39 @@ describe('review fixes: no silent loss, no empty commit, no lost focus', () => { expect( screen.queryByRole('button', { name: 'Déplacer le point' }), ).toBeNull() + expect( + screen.getByRole('button', { name: "Déplacer l'accès" }), + ).toBeInTheDocument() + }) + + it("« Déplacer l'accès » moves the circle by the step; « Valider la position » commits once", async () => { + await mount(withLink(two(), 'l')) + await select(2) + const before = depth() + fireEvent.click(screen.getByRole('button', { name: "Déplacer l'accès" })) + fireEvent.click(arrow('la droite')) + fireEvent.click(arrow('le bas')) + expect(geometryOf('l')).toMatchObject({ cx: 70, cy: 70, r: 6 }) + expect(depth()).toBe(before) + fireEvent.click( + within(bar()).getByRole('button', { name: 'Valider la position' }), + ) + expect(geometryOf('l')).toMatchObject({ cx: 70.5, cy: 70.5, r: 6 }) + expect(depth()).toBe(before + 1) + }) + + it('a move past the frame edge is refused by the core: nothing is committed', async () => { + await mount(withLink(two(), 'l', { cx: 93, cy: 50, r: 6 })) + await select(2) + const before = depth() + fireEvent.click(screen.getByRole('button', { name: "Déplacer l'accès" })) + for (let i = 0; i < 40; i++) fireEvent.click(arrow('la droite')) + fireEvent.click( + within(bar()).getByRole('button', { name: 'Valider la position' }), + ) + expect(geometryOf('l')).toMatchObject({ cx: 93, cy: 50, r: 6 }) + expect(depth()).toBe(before) + expect(message()).toHaveTextContent('Déplacement refusé') }) })