feat(editor): selected access commands and opening on a second click
This commit is contained in:
1 parent
251a517b99
commit
2ae42503ae
7 files changed
+411
-18
No files matched your search
@@ -0,0 +1,84 @@
|
|||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import { useT } from '@/i18n/useT'
|
||||||
|
import EditorGlyph from '../EditorGlyph'
|
||||||
|
import { PropertiesButton } from './SelectionCommands'
|
||||||
|
|
||||||
|
const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9'
|
||||||
|
|
||||||
|
export interface AccessCommandsProps {
|
||||||
|
onOpen?: (button: HTMLElement) => void
|
||||||
|
onRecrop?: (button: HTMLElement) => void
|
||||||
|
onMove?: () => void
|
||||||
|
onRedraw?: () => void
|
||||||
|
onProperties?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The strip's commands of a selected access (A2, D14): « Ouvrir la vue », « Recadrer la
|
||||||
|
* vue », « Déplacer l'accès », « Redessiner » for a polygon, « Propriétés » (deletion
|
||||||
|
* stays there). A command whose handler is absent is not rendered, so each task that
|
||||||
|
* wires one leaves a working strip.
|
||||||
|
*/
|
||||||
|
export default function AccessCommands({
|
||||||
|
onOpen,
|
||||||
|
onRecrop,
|
||||||
|
onMove,
|
||||||
|
onRedraw,
|
||||||
|
onProperties,
|
||||||
|
}: AccessCommandsProps) {
|
||||||
|
const t = useT()
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{onOpen && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
className={COMMAND}
|
||||||
|
onClick={(event) => onOpen(event.currentTarget)}
|
||||||
|
>
|
||||||
|
{t('editor.annotations.view.open')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{onRecrop && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
className={COMMAND}
|
||||||
|
onClick={(event) => onRecrop(event.currentTarget)}
|
||||||
|
>
|
||||||
|
{t('editor.annotations.view.recrop')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{onMove && (
|
||||||
|
<Button
|
||||||
|
// R-12: the focus comes back here when the mode ends (useModeFocusReturn).
|
||||||
|
data-move-entry=""
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
className={COMMAND}
|
||||||
|
onClick={onMove}
|
||||||
|
>
|
||||||
|
<EditorGlyph name="move" size={16} />
|
||||||
|
{t('editor.annotations.move.access')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{onRedraw && (
|
||||||
|
<Button
|
||||||
|
// M-6: the focus comes back here when the redraw ends (useModeFocusReturn).
|
||||||
|
data-redraw-entry=""
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
className={COMMAND}
|
||||||
|
onClick={onRedraw}
|
||||||
|
>
|
||||||
|
<EditorGlyph name="zone" size={16} />
|
||||||
|
{t('editor.annotations.redraw')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{onProperties && <PropertiesButton onClick={onProperties} />}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import { useT } from '@/i18n/useT'
|
|||||||
import { useLocaleStore } from '@/state/localeStore'
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
import type { Scene, Work } from './EditableAnnotations'
|
import type { Scene, Work } from './EditableAnnotations'
|
||||||
import AccessShapeChoice from './AccessShapeChoice'
|
import AccessShapeChoice from './AccessShapeChoice'
|
||||||
|
import AccessCommands from './AccessCommands'
|
||||||
import CreationCommands from './CreationCommands'
|
import CreationCommands from './CreationCommands'
|
||||||
import EditStrip, { type StripNotice } from './EditStrip'
|
import EditStrip, { type StripNotice } from './EditStrip'
|
||||||
import {
|
import {
|
||||||
@@ -29,6 +30,7 @@ import {
|
|||||||
useModeFocusReturn,
|
useModeFocusReturn,
|
||||||
} from './PointCommands'
|
} from './PointCommands'
|
||||||
import FrameCommands from './FrameCommands'
|
import FrameCommands from './FrameCommands'
|
||||||
|
import MoveModeBar from './MoveModeBar'
|
||||||
import SelectionCommands from './SelectionCommands'
|
import SelectionCommands from './SelectionCommands'
|
||||||
import TracingCommands from './TracingCommands'
|
import TracingCommands from './TracingCommands'
|
||||||
import ViewCommands from './ViewCommands'
|
import ViewCommands from './ViewCommands'
|
||||||
@@ -115,6 +117,7 @@ function commandsKeyOf(
|
|||||||
if (creation?.resumed) return `creation-${creation.pending.geometry.type}`
|
if (creation?.resumed) return `creation-${creation.pending.geometry.type}`
|
||||||
if (tracing) return 'tracing'
|
if (tracing) return 'tracing'
|
||||||
if (moving) return 'move'
|
if (moving) return 'move'
|
||||||
|
if (showsAccessCommands(target, chosen)) return 'access'
|
||||||
if (target?.geometry?.type === 'polygon') return `zone-${chosen !== null}`
|
if (target?.geometry?.type === 'polygon') return `zone-${chosen !== null}`
|
||||||
if (target?.kind === 'point') return 'point'
|
if (target?.kind === 'point') return 'point'
|
||||||
if (ui.selectedId !== null) return `selected-${target?.kind}`
|
if (ui.selectedId !== null) return `selected-${target?.kind}`
|
||||||
@@ -127,10 +130,59 @@ function frameKeyOf(frame: FrameWork) {
|
|||||||
return frame.box === null ? 'frame-draw' : 'frame-adjust'
|
return frame.box === null ? 'frame-draw' : 'frame-adjust'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A selected access offers its own commands (A2), unless a vertex of its polygon is chosen:
|
||||||
|
* then the vertex commands show, as for a zone.
|
||||||
|
*/
|
||||||
|
function showsAccessCommands(
|
||||||
|
target: Annotation | null,
|
||||||
|
chosen: number | null,
|
||||||
|
): boolean {
|
||||||
|
if (target?.kind !== 'detail_trigger' || chosen !== null) return false
|
||||||
|
return isEditable(target.geometry)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The access's commands, or the move mode's bar while it runs on the access. */
|
||||||
|
function AccessStrip({ annotation, work, scene }: AccessStripProps) {
|
||||||
|
const inMode = useAnnotationWork(
|
||||||
|
(s) => s.mode?.kind === 'move' && s.mode.annotationId === annotation.id,
|
||||||
|
)
|
||||||
|
const { edit } = work
|
||||||
|
if (inMode) {
|
||||||
|
return (
|
||||||
|
<MoveModeBar
|
||||||
|
onStep={edit.stepMove}
|
||||||
|
onConfirm={edit.confirmMove}
|
||||||
|
onCancel={edit.cancelMove}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const polygon = annotation.geometry?.type === 'polygon'
|
||||||
|
return (
|
||||||
|
<AccessCommands
|
||||||
|
onMove={edit.startMove}
|
||||||
|
onRedraw={
|
||||||
|
polygon ? () => beginRedraw(annotation.id, scene.dispatch) : undefined
|
||||||
|
}
|
||||||
|
onProperties={() => scene.onOpen(annotation.id, 'button')}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AccessStripProps {
|
||||||
|
annotation: Annotation
|
||||||
|
work: Work
|
||||||
|
scene: Scene
|
||||||
|
}
|
||||||
|
|
||||||
/** The selection's own commands: a polygon's, a movable point's (R-10: a link circle none). */
|
/** 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 }: { scene: Scene; work: Work }) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const { doc, viewId, frame, dispatch, selected, model } = scene
|
const { doc, viewId, frame, dispatch, selected, model } = scene
|
||||||
|
const chosen = useChosenVertex(work.target?.id)
|
||||||
|
if (work.target && showsAccessCommands(work.target, chosen)) {
|
||||||
|
return <AccessStrip annotation={work.target} work={work} scene={scene} />
|
||||||
|
}
|
||||||
if (work.target?.geometry?.type === 'polygon') {
|
if (work.target?.geometry?.type === 'polygon') {
|
||||||
const edit = work.edit
|
const edit = work.edit
|
||||||
return (
|
return (
|
||||||
@@ -207,6 +259,8 @@ function SceneCommands({
|
|||||||
dispatch({ type: 'select', id: null }),
|
dispatch({ type: 'select', id: null }),
|
||||||
)
|
)
|
||||||
const framing = useAnnotationWork((s) => s.frame)
|
const framing = useAnnotationWork((s) => s.frame)
|
||||||
|
const chosen = useChosenVertex(selected?.id)
|
||||||
|
const accessOwnsProperties = showsAccessCommands(work.target, chosen)
|
||||||
if (framing) return <FrameCommands frame={framing} bounds={frame} />
|
if (framing) return <FrameCommands frame={framing} bounds={frame} />
|
||||||
// The dialog shown: its own actions; hidden after it was shown: board 04 C.
|
// The dialog shown: its own actions; hidden after it was shown: board 04 C.
|
||||||
if (creation?.dialog) return null
|
if (creation?.dialog) return null
|
||||||
@@ -249,7 +303,11 @@ function SceneCommands({
|
|||||||
{/* During the move mode only the mode's own exits (its bar). */}
|
{/* During the move mode only the mode's own exits (its bar). */}
|
||||||
{!moving && (
|
{!moving && (
|
||||||
<SelectionCommands
|
<SelectionCommands
|
||||||
onProperties={() => scene.onOpen(selected.id, 'button')}
|
onProperties={
|
||||||
|
accessOwnsProperties
|
||||||
|
? undefined
|
||||||
|
: () => scene.onOpen(selected.id, 'button')
|
||||||
|
}
|
||||||
onDeselect={byButton}
|
onDeselect={byButton}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -4,32 +4,41 @@ import EditorGlyph from '../EditorGlyph'
|
|||||||
|
|
||||||
const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9'
|
const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9'
|
||||||
|
|
||||||
|
/** « Propriétés »: opens the dialog (A1). */
|
||||||
|
export function PropertiesButton({ onClick }: { onClick: () => void }) {
|
||||||
|
const t = useT()
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
// The focus comes back here when the dialog it opened closes (board 32).
|
||||||
|
data-properties-button=""
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
className={COMMAND}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
<EditorGlyph name="properties" size={16} />
|
||||||
|
{t('editor.annotations.properties')}
|
||||||
|
</Button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The strip's commands of any selection, after its own (boards 33 C to E): « Propriétés »
|
* The strip's commands of any selection, after its own (boards 33 C to E): « Propriétés »
|
||||||
* opens the dialog (A1), « Désélectionner » leaves the selection.
|
* unless the selection's own commands already hold it (an access), « Désélectionner »
|
||||||
|
* leaves the selection.
|
||||||
*/
|
*/
|
||||||
export default function SelectionCommands({
|
export default function SelectionCommands({
|
||||||
onProperties,
|
onProperties,
|
||||||
onDeselect,
|
onDeselect,
|
||||||
}: {
|
}: {
|
||||||
onProperties: () => void
|
onProperties?: () => void
|
||||||
onDeselect: () => void
|
onDeselect: () => void
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
{onProperties && <PropertiesButton onClick={onProperties} />}
|
||||||
// The focus comes back here when the dialog it opened closes (board 32).
|
|
||||||
data-properties-button=""
|
|
||||||
type="button"
|
|
||||||
size="sm"
|
|
||||||
variant="secondary"
|
|
||||||
className={COMMAND}
|
|
||||||
onClick={onProperties}
|
|
||||||
>
|
|
||||||
<EditorGlyph name="properties" size={16} />
|
|
||||||
{t('editor.annotations.properties')}
|
|
||||||
</Button>
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -14,12 +14,13 @@ import MoveModeBar from './MoveModeBar'
|
|||||||
|
|
||||||
const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9'
|
const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9'
|
||||||
|
|
||||||
/** The move mode's title: « Déplacer le sommet », « … la zone » or « … le point ». */
|
/** The move mode's title: « Déplacer le sommet », « … la zone », « … l'accès » or « … le point ». */
|
||||||
export function moveTitleKey(
|
export function moveTitleKey(
|
||||||
mode: ModeWork,
|
mode: ModeWork,
|
||||||
kind: Annotation['kind'] | undefined,
|
kind: Annotation['kind'] | undefined,
|
||||||
) {
|
) {
|
||||||
if (mode.vertex !== null) return 'editor.annotations.move.vertex'
|
if (mode.vertex !== null) return 'editor.annotations.move.vertex'
|
||||||
|
if (kind === 'detail_trigger') return 'editor.annotations.move.access'
|
||||||
return kind === 'zone'
|
return kind === 'zone'
|
||||||
? 'editor.annotations.move.zone'
|
? 'editor.annotations.move.zone'
|
||||||
: 'editor.annotations.move.point'
|
: 'editor.annotations.move.point'
|
||||||
@@ -46,7 +47,8 @@ export interface ZoneCommandsProps {
|
|||||||
/**
|
/**
|
||||||
* The strip's commands for a selected polygon (board 05): « Déplacer la zone » (« Déplacer
|
* The strip's commands for a selected polygon (board 05): « Déplacer la zone » (« Déplacer
|
||||||
* le sommet » while a vertex is chosen) and « Redessiner »; during the move mode, its bar
|
* le sommet » while a vertex is chosen) and « Redessiner »; during the move mode, its bar
|
||||||
* (board 06 B). A link traced as a polygon gets « Redessiner » only (no move label).
|
* (board 06 B). An access has its own commands (AccessCommands) until a vertex is
|
||||||
|
* chosen: then these.
|
||||||
*/
|
*/
|
||||||
export default function ZoneCommands({
|
export default function ZoneCommands({
|
||||||
annotation,
|
annotation,
|
||||||
@@ -70,7 +72,7 @@ export default function ZoneCommands({
|
|||||||
const moveKey = chosen === null ? 'move.zone' : 'move.vertex'
|
const moveKey = chosen === null ? 'move.zone' : 'move.vertex'
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{annotation.kind === 'zone' && (
|
{(annotation.kind === 'zone' || chosen !== null) && (
|
||||||
<Button
|
<Button
|
||||||
// R-12: the focus comes back here when the mode ends (useModeFocusReturn).
|
// R-12: the focus comes back here when the mode ends (useModeFocusReturn).
|
||||||
data-move-entry=""
|
data-move-entry=""
|
||||||
|
|||||||
@@ -1880,6 +1880,7 @@ export const en: Dict = {
|
|||||||
'editor.annotations.strip.close_refused': 'Closing refused',
|
'editor.annotations.strip.close_refused': 'Closing refused',
|
||||||
'editor.annotations.strip.zoom_hint':
|
'editor.annotations.strip.zoom_hint':
|
||||||
'Zoom in to add a vertex on short segments.',
|
'Zoom in to add a vertex on short segments.',
|
||||||
|
'editor.annotations.move.access': 'Move the access',
|
||||||
'editor.annotations.move.zone': 'Move zone',
|
'editor.annotations.move.zone': 'Move zone',
|
||||||
'editor.annotations.move.vertex': 'Move vertex',
|
'editor.annotations.move.vertex': 'Move vertex',
|
||||||
'editor.annotations.redraw': 'Redraw',
|
'editor.annotations.redraw': 'Redraw',
|
||||||
@@ -1926,6 +1927,7 @@ export const en: Dict = {
|
|||||||
'editor.annotations.frame.placed': 'Frame placed at the centre.',
|
'editor.annotations.frame.placed': 'Frame placed at the centre.',
|
||||||
'editor.annotations.view.new': 'New detail view',
|
'editor.annotations.view.new': 'New detail view',
|
||||||
'editor.annotations.view.parent': 'Parent view',
|
'editor.annotations.view.parent': 'Parent view',
|
||||||
|
'editor.annotations.view.open': 'Open the view',
|
||||||
'editor.annotations.view.recrop': 'Recrop the view',
|
'editor.annotations.view.recrop': 'Recrop the view',
|
||||||
'editor.annotations.frame.draw_hint':
|
'editor.annotations.frame.draw_hint':
|
||||||
'Drag on the drawing, or click for a default frame.',
|
'Drag on the drawing, or click for a default frame.',
|
||||||
|
|||||||
@@ -1950,6 +1950,7 @@ export const fr: Dict = {
|
|||||||
'editor.annotations.strip.close_refused': 'Fermeture refusée',
|
'editor.annotations.strip.close_refused': 'Fermeture refusée',
|
||||||
'editor.annotations.strip.zoom_hint':
|
'editor.annotations.strip.zoom_hint':
|
||||||
'Zoomez pour ajouter un sommet sur les segments courts.',
|
'Zoomez pour ajouter un sommet sur les segments courts.',
|
||||||
|
'editor.annotations.move.access': "Déplacer l'accès",
|
||||||
'editor.annotations.move.zone': 'Déplacer la zone',
|
'editor.annotations.move.zone': 'Déplacer la zone',
|
||||||
'editor.annotations.move.vertex': 'Déplacer le sommet',
|
'editor.annotations.move.vertex': 'Déplacer le sommet',
|
||||||
'editor.annotations.redraw': 'Redessiner',
|
'editor.annotations.redraw': 'Redessiner',
|
||||||
@@ -1996,6 +1997,7 @@ export const fr: Dict = {
|
|||||||
'editor.annotations.frame.placed': 'Cadre posé au centre.',
|
'editor.annotations.frame.placed': 'Cadre posé au centre.',
|
||||||
'editor.annotations.view.new': 'Nouvelle vue de détail',
|
'editor.annotations.view.new': 'Nouvelle vue de détail',
|
||||||
'editor.annotations.view.parent': 'Vue parente',
|
'editor.annotations.view.parent': 'Vue parente',
|
||||||
|
'editor.annotations.view.open': 'Ouvrir la vue',
|
||||||
'editor.annotations.view.recrop': 'Recadrer la vue',
|
'editor.annotations.view.recrop': 'Recadrer la vue',
|
||||||
'editor.annotations.frame.draw_hint':
|
'editor.annotations.frame.draw_hint':
|
||||||
'Glissez sur le dessin, ou cliquez pour un cadre par défaut.',
|
'Glissez sur le dessin, ou cliquez pour un cadre par défaut.',
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
/** U2 Task 16: the commands a selected access (detail_trigger) offers (A2, D14). */
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import {
|
||||||
|
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 AccessCommands from '@/components/editor/annotations/AccessCommands'
|
||||||
|
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||||
|
import { LayeredTab } from '../helpers/annotationLayer'
|
||||||
|
import { resetWork } from '@/editor/annotations/workStore'
|
||||||
|
import { useLocaleStore } from '@/state/localeStore'
|
||||||
|
import { drawnText, insert } 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 = {
|
||||||
|
readOnly: false,
|
||||||
|
navigate: vi.fn(),
|
||||||
|
reloadSheet: vi.fn(),
|
||||||
|
section: 'drawing' as const,
|
||||||
|
visited: ['drawing'] as const,
|
||||||
|
onOpenSection: vi.fn(),
|
||||||
|
onBack: vi.fn(),
|
||||||
|
}
|
||||||
|
|
||||||
|
const annotations = () => store.getState().previewState!.document.annotations
|
||||||
|
const annotationOf = (id: string) =>
|
||||||
|
annotations().find((a: Annotation) => a.id === id)!
|
||||||
|
const pointsOf = (id: string) => {
|
||||||
|
const geometry = annotationOf(id).geometry
|
||||||
|
return geometry?.type === 'polygon' ? geometry.points : null
|
||||||
|
}
|
||||||
|
const depth = () => store.getState().undo.length
|
||||||
|
|
||||||
|
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()
|
||||||
|
})
|
||||||
|
|
||||||
|
const SQUARE: Point[] = [
|
||||||
|
[20, 20],
|
||||||
|
[80, 20],
|
||||||
|
[80, 80],
|
||||||
|
[20, 80],
|
||||||
|
]
|
||||||
|
|
||||||
|
const tab = (readOnly = false) => (
|
||||||
|
<div data-editor-workspace>
|
||||||
|
<AnnotationsTab {...props} readOnly={readOnly} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
async function mount(text: string, ui = tab()) {
|
||||||
|
await openReady({ text })
|
||||||
|
const view = render(ui)
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(
|
||||||
|
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||||||
|
).not.toBeNull(),
|
||||||
|
)
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
|
||||||
|
async function select(index = 0) {
|
||||||
|
const list = await screen.findByRole('list', {
|
||||||
|
name: 'Annotations de la vue',
|
||||||
|
})
|
||||||
|
await userEvent.setup().click(within(list).getAllByRole('button')[index])
|
||||||
|
// 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 SIDE: Annotation['geometry'] = { type: 'circle', cx: 50, cy: 50, r: 10 }
|
||||||
|
|
||||||
|
const access = (geometry: object): Annotation =>
|
||||||
|
({
|
||||||
|
id: 'l',
|
||||||
|
view_id: 'view-main',
|
||||||
|
category_id: 'cat-a',
|
||||||
|
laterality: 'unpaired',
|
||||||
|
geometry,
|
||||||
|
review_status: 'to_confirm',
|
||||||
|
color: null,
|
||||||
|
kind: 'detail_trigger',
|
||||||
|
name: null,
|
||||||
|
opens_view_id: 'view-det',
|
||||||
|
}) as Annotation
|
||||||
|
|
||||||
|
const withAccess = (geometry: object) =>
|
||||||
|
insert(
|
||||||
|
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',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
{ kind: 'annotation', value: access(geometry) },
|
||||||
|
)
|
||||||
|
|
||||||
|
const names = () =>
|
||||||
|
within(screen.getByTestId('edit-strip'))
|
||||||
|
.getAllByRole('button')
|
||||||
|
.map((b) => b.textContent)
|
||||||
|
|
||||||
|
describe('a selected access', () => {
|
||||||
|
it('a polygon offers the move and the properties, never a delete', async () => {
|
||||||
|
await mount(withAccess({ type: 'polygon', points: SQUARE }))
|
||||||
|
const strip = await select()
|
||||||
|
const has = (name: string) => within(strip).queryByRole('button', { name })
|
||||||
|
expect(has("Déplacer l'accès")).not.toBeNull()
|
||||||
|
expect(has('Propriétés')).not.toBeNull()
|
||||||
|
expect(has('Ouvrir la vue')).toBeNull()
|
||||||
|
expect(has('Recadrer la vue')).toBeNull()
|
||||||
|
expect(has('Supprimer')).toBeNull()
|
||||||
|
expect(has('Déplacer la zone')).toBeNull()
|
||||||
|
expect(names()).toContain('Désélectionner')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a circle gets the same commands', async () => {
|
||||||
|
await mount(withAccess(SIDE))
|
||||||
|
const strip = await select()
|
||||||
|
expect(
|
||||||
|
within(strip).getByRole('button', { name: "Déplacer l'accès" }),
|
||||||
|
).toBeInTheDocument()
|
||||||
|
expect(
|
||||||
|
within(strip).getByRole('button', { name: 'Propriétés' }),
|
||||||
|
).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("« Déplacer l'accès » runs the move mode, « Valider la position » commits once", async () => {
|
||||||
|
await mount(withAccess({ type: 'polygon', points: SQUARE }))
|
||||||
|
await select()
|
||||||
|
const before = depth()
|
||||||
|
await userEvent
|
||||||
|
.setup()
|
||||||
|
.click(screen.getByRole('button', { name: "Déplacer l'accès" }))
|
||||||
|
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||||
|
"Déplacer l'accès",
|
||||||
|
)
|
||||||
|
const bar = screen.getByTestId('move-mode-bar')
|
||||||
|
fireEvent.click(
|
||||||
|
within(bar).getByRole('button', { name: 'Déplacer vers la droite' }),
|
||||||
|
)
|
||||||
|
fireEvent.click(
|
||||||
|
within(bar).getByRole('button', { name: 'Valider la position' }),
|
||||||
|
)
|
||||||
|
expect(pointsOf('l')).toEqual(SQUARE.map(([x, y]) => [x + 0.5, y]))
|
||||||
|
expect(depth()).toBe(before + 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('« Propriétés » opens the properties dialog', async () => {
|
||||||
|
await mount(
|
||||||
|
withAccess({ type: 'polygon', points: SQUARE }),
|
||||||
|
<div data-editor-workspace>
|
||||||
|
<LayeredTab {...props} readOnly={false} />
|
||||||
|
</div>,
|
||||||
|
)
|
||||||
|
await select()
|
||||||
|
await userEvent
|
||||||
|
.setup()
|
||||||
|
.click(screen.getByRole('button', { name: 'Propriétés' }))
|
||||||
|
expect(await screen.findByRole('dialog')).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a chosen vertex shows the vertex commands, as for a zone', async () => {
|
||||||
|
await mount(withAccess({ type: 'polygon', points: SQUARE }))
|
||||||
|
await select()
|
||||||
|
pressAt(
|
||||||
|
screen
|
||||||
|
.getByRole('button', { name: /^Sommet 2 de/ })
|
||||||
|
.querySelector('[data-handle]')!,
|
||||||
|
80,
|
||||||
|
20,
|
||||||
|
)
|
||||||
|
const strip = screen.getByTestId('edit-strip')
|
||||||
|
expect(
|
||||||
|
within(strip).getByRole('button', { name: 'Déplacer le sommet' }),
|
||||||
|
).toBeInTheDocument()
|
||||||
|
expect(
|
||||||
|
within(strip).queryByRole('button', { name: "Déplacer l'accès" }),
|
||||||
|
).toBeNull()
|
||||||
|
expect(
|
||||||
|
within(strip).getByRole('button', { name: 'Propriétés' }),
|
||||||
|
).toBeInTheDocument()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('AccessCommands', () => {
|
||||||
|
it('renders only the commands whose handler is given', () => {
|
||||||
|
const onOpen = vi.fn()
|
||||||
|
const onProperties = vi.fn()
|
||||||
|
render(<AccessCommands onOpen={onOpen} onProperties={onProperties} />)
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: 'Ouvrir la vue' }))
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: 'Propriétés' }))
|
||||||
|
expect(onOpen).toHaveBeenCalledTimes(1)
|
||||||
|
expect(onProperties).toHaveBeenCalledTimes(1)
|
||||||
|
expect(screen.queryByRole('button', { name: 'Recadrer la vue' })).toBeNull()
|
||||||
|
expect(
|
||||||
|
screen.queryByRole('button', { name: "Déplacer l'accès" }),
|
||||||
|
).toBeNull()
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in new issue
Block a user