feat(editor): « Placer au centre » in the add row while a tool is armed
A screen-reader user can create an annotation without the drawing: the command places the armed kind at the centre through the one placement function shared with Enter and the add buttons' keyboard path.
This commit is contained in:
1 parent
f05f3fa0e7
commit
922bd50a5b
7 files changed
+323
-35
No files matched your search
@@ -1166,5 +1166,50 @@ test.describe('editor annotations (A3)', () => {
|
|||||||
await expect(tool(page, 'zone')).toHaveAttribute('aria-pressed', 'true')
|
await expect(tool(page, 'zone')).toHaveAttribute('aria-pressed', 'true')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// « Placer au centre »: the fourth slot of the add row, reserved at all times.
|
||||||
|
const centre = (page: Page) => page.locator('[data-place-centre]')
|
||||||
|
const addRow = (page: Page) =>
|
||||||
|
page.locator('[data-add-kind], [data-place-centre]')
|
||||||
|
|
||||||
|
for (const width of [1024, 1180, 1280]) {
|
||||||
|
test(`at ${width} px: arming Point shows « Placer au centre » on the add row's line, nothing moves`, async ({
|
||||||
|
page,
|
||||||
|
requests,
|
||||||
|
}) => {
|
||||||
|
await page.setViewportSize({ width, height: 800 })
|
||||||
|
const { actor } = await openAnnotations(page)
|
||||||
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
|
await add(page, 'point').scrollIntoViewIfNeeded()
|
||||||
|
await expect(centre(page)).toBeHidden()
|
||||||
|
await expectNoShift(page, async () => {
|
||||||
|
await add(page, 'point').click()
|
||||||
|
await expect(centre(page)).toBeVisible()
|
||||||
|
})
|
||||||
|
const tops = await addRow(page).evaluateAll((els) =>
|
||||||
|
els.map((el) => Math.round(el.getBoundingClientRect().top)),
|
||||||
|
)
|
||||||
|
expect(tops, 'four buttons on one line').toHaveLength(4)
|
||||||
|
expect(new Set(tops).size, `tops ${tops.join(',')}`).toBe(1)
|
||||||
|
await centre(page).click()
|
||||||
|
await expect(creationDialog(page, 'point')).toBeVisible()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
test('at 1280 px: a double click on « Placer au centre » keeps its dialog, asks nothing', async ({
|
||||||
|
page,
|
||||||
|
requests,
|
||||||
|
}) => {
|
||||||
|
await page.setViewportSize({ width: 1280, height: 800 })
|
||||||
|
const { actor } = await openAnnotations(page)
|
||||||
|
requests.forbid(actor.account.email, actor.account.password)
|
||||||
|
await add(page, 'point').scrollIntoViewIfNeeded()
|
||||||
|
await add(page, 'point').click()
|
||||||
|
await centre(page).dblclick()
|
||||||
|
await expect(creationDialog(page, 'point')).toBeVisible()
|
||||||
|
await expect(
|
||||||
|
page.getByText(dict['editor.annotations.guard.creation']),
|
||||||
|
).toHaveCount(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -7,11 +7,8 @@ import type {
|
|||||||
} from '@faunosteo/core-wasm/types'
|
} from '@faunosteo/core-wasm/types'
|
||||||
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
import type { CommitContext } from '@/editor/annotations/annotationCommit'
|
||||||
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
import { useAnnotationRequest } from '@/editor/annotations/focusTarget'
|
||||||
import { keyboardPending, type NewKind } from '@/editor/annotations/creation'
|
import type { NewKind } from '@/editor/annotations/creation'
|
||||||
import {
|
import { creationTracing } from '@/editor/annotations/creationWork'
|
||||||
creationTracing,
|
|
||||||
placePending,
|
|
||||||
} from '@/editor/annotations/creationWork'
|
|
||||||
import { useCreationFollow } from '@/editor/annotations/useCreationFollow'
|
import { useCreationFollow } from '@/editor/annotations/useCreationFollow'
|
||||||
import {
|
import {
|
||||||
PENDING_ID,
|
PENDING_ID,
|
||||||
@@ -38,7 +35,11 @@ import {
|
|||||||
useLayerFollow,
|
useLayerFollow,
|
||||||
type OpenDialog,
|
type OpenDialog,
|
||||||
} from '@/editor/annotations/dialogOpening'
|
} from '@/editor/annotations/dialogOpening'
|
||||||
import { creationStart, usePlacement } from '@/editor/annotations/usePlacement'
|
import {
|
||||||
|
placeAtCentre,
|
||||||
|
TOOL_TARGET,
|
||||||
|
usePlacement,
|
||||||
|
} from '@/editor/annotations/usePlacement'
|
||||||
import {
|
import {
|
||||||
useGestureMessage,
|
useGestureMessage,
|
||||||
type GestureMessages,
|
type GestureMessages,
|
||||||
@@ -319,7 +320,7 @@ function CanvasColumn({
|
|||||||
disabled={!model.measured || noCategory || scene.frame === null}
|
disabled={!model.measured || noCategory || scene.frame === null}
|
||||||
linkDisabled={model.children.length === 0}
|
linkDisabled={model.children.length === 0}
|
||||||
armed={armedTool(scene.ui)}
|
armed={armedTool(scene.ui)}
|
||||||
announce={scene.ui.armedFrom === 'add'}
|
centre={centreOf(scene)}
|
||||||
onAdd={(kind) => guarded(() => addAtCentre(kind, scene))()}
|
onAdd={(kind) => guarded(() => addAtCentre(kind, scene))()}
|
||||||
onArm={(kind, button) => armFromAdd(kind, button, scene)}
|
onArm={(kind, button) => armFromAdd(kind, button, scene)}
|
||||||
/>
|
/>
|
||||||
@@ -469,11 +470,21 @@ function armFromAdd(
|
|||||||
|
|
||||||
/** « Ajouter … » (keyboard): the shape at the centre at the A5 size, then its dialog. */
|
/** « Ajouter … » (keyboard): the shape at the centre at the A5 size, then its dialog. */
|
||||||
function addAtCentre(kind: NewKind, scene: Scene) {
|
function addAtCentre(kind: NewKind, scene: Scene) {
|
||||||
const { frame, doc, viewId, ui } = scene
|
placeAtCentre(scene, kind, 'add')
|
||||||
if (!frame) return
|
}
|
||||||
const size = newPointSize(doc.annotations, viewId, frame, ui.size)
|
|
||||||
const start = creationStart(scene, 'add')
|
/**
|
||||||
placePending(start, keyboardPending(kind, frame, size))
|
* « Placer au centre »: available while a creation tool is armed and nothing is started
|
||||||
|
* (a redraw's lent tool is not an armed tool); null otherwise, for the reserved slot.
|
||||||
|
*/
|
||||||
|
function centreOf(scene: Scene): (() => void) | null {
|
||||||
|
const { ui, doc, model, frame, creation } = scene
|
||||||
|
const tool = armedTool(ui)
|
||||||
|
if (tool === 'select' || creation !== null || ui.tracing !== null) return null
|
||||||
|
if (frame === null || !model.measured || doc.categories.length === 0)
|
||||||
|
return null
|
||||||
|
if (tool === 'link' && model.children.length === 0) return null
|
||||||
|
return () => placeAtCentre(scene, TOOL_TARGET[tool], ui.armedFrom)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Board 02 A: the next point's size under a mouse pointer, while the point tool places. */
|
/** Board 02 A: the next point's size under a mouse pointer, while the point tool places. */
|
||||||
|
|||||||
@@ -14,13 +14,14 @@ const ARMED =
|
|||||||
* tool, or disarms it when armed, so the shape is placed where the drawing is pressed and its
|
* tool, or disarms it when armed, so the shape is placed where the drawing is pressed and its
|
||||||
* dialog opens itself; the second click of a double-click (`detail` 2) changes nothing; Enter
|
* dialog opens itself; the second click of a double-click (`detail` 2) changes nothing; Enter
|
||||||
* or Space (`detail` 0) keeps the C7 keyboard path: the shape at the centre of the frame at
|
* or Space (`detail` 0) keeps the C7 keyboard path: the shape at the centre of the frame at
|
||||||
* the A5 size, its dialog at once.
|
* the A5 size, its dialog at once. « Placer au centre » does the same for the armed tool,
|
||||||
|
* from a fourth slot reserved at all times so nothing moves when it appears.
|
||||||
*/
|
*/
|
||||||
export default function KeyboardAdd({
|
export default function KeyboardAdd({
|
||||||
disabled,
|
disabled,
|
||||||
linkDisabled,
|
linkDisabled,
|
||||||
armed,
|
armed,
|
||||||
announce,
|
centre,
|
||||||
onAdd,
|
onAdd,
|
||||||
onArm,
|
onArm,
|
||||||
}: {
|
}: {
|
||||||
@@ -30,8 +31,8 @@ export default function KeyboardAdd({
|
|||||||
linkDisabled: boolean
|
linkDisabled: boolean
|
||||||
/** The armed tool (`armedTool`): its button shows pressed. */
|
/** The armed tool (`armedTool`): its button shows pressed. */
|
||||||
armed: ToolId
|
armed: ToolId
|
||||||
/** An add button armed the tool: the region says so to a screen reader. */
|
/** « Placer au centre » when it can be used now, else null: its slot stays reserved. */
|
||||||
announce: boolean
|
centre: (() => void) | null
|
||||||
onAdd: (kind: NewKind) => void
|
onAdd: (kind: NewKind) => void
|
||||||
onArm: (kind: NewKind, button: HTMLElement) => void
|
onArm: (kind: NewKind, button: HTMLElement) => void
|
||||||
}) {
|
}) {
|
||||||
@@ -40,7 +41,7 @@ export default function KeyboardAdd({
|
|||||||
if (event.detail === 0) onAdd(kind)
|
if (event.detail === 0) onAdd(kind)
|
||||||
else if (event.detail === 1) onArm(kind, event.currentTarget)
|
else if (event.detail === 1) onArm(kind, event.currentTarget)
|
||||||
}
|
}
|
||||||
const armedKind = announce
|
const armedKind = centre
|
||||||
? KINDS.find((k) => TOOL_OF[k] === armed)
|
? KINDS.find((k) => TOOL_OF[k] === armed)
|
||||||
: undefined
|
: undefined
|
||||||
return (
|
return (
|
||||||
@@ -60,6 +61,16 @@ export default function KeyboardAdd({
|
|||||||
{t(`editor.annotations.add.${kind}`)}
|
{t(`editor.annotations.add.${kind}`)}
|
||||||
</Button>
|
</Button>
|
||||||
))}
|
))}
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
className={`min-h-11 xl:min-h-9${centre ? '' : ' invisible'}`}
|
||||||
|
data-place-centre=""
|
||||||
|
onClick={() => centre?.()}
|
||||||
|
>
|
||||||
|
{t('editor.annotations.place_centre')}
|
||||||
|
</Button>
|
||||||
{/* Always mounted: the region exists before its text (M-3). */}
|
{/* Always mounted: the region exists before its text (M-3). */}
|
||||||
<p role="status" className="sr-only">
|
<p role="status" className="sr-only">
|
||||||
{armedKind ? t(`editor.annotations.armed.${armedKind}`) : ''}
|
{armedKind ? t(`editor.annotations.armed.${armedKind}`) : ''}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import { endMode, PENDING_ID, useAnnotationWork } from './workStore'
|
|||||||
import type { ToolId, Tracing, UiAction, UiState } from './uiState'
|
import type { ToolId, Tracing, UiAction, UiState } from './uiState'
|
||||||
import type { GestureMessages } from './useGestureMessage'
|
import type { GestureMessages } from './useGestureMessage'
|
||||||
|
|
||||||
const TOOL_TARGET: Record<Exclude<ToolId, 'select'>, NewKind> = {
|
export const TOOL_TARGET: Record<Exclude<ToolId, 'select'>, NewKind> = {
|
||||||
point: 'point',
|
point: 'point',
|
||||||
zone: 'zone',
|
zone: 'zone',
|
||||||
link: 'detail_trigger',
|
link: 'detail_trigger',
|
||||||
@@ -81,7 +81,7 @@ function closeRedraw(input: PlacementInput, tracing: Tracing): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Where a creation on this view starts: F, the origin, a fresh form (A4). */
|
/** Where a creation on this view starts: F, the origin, a fresh form (A4). */
|
||||||
export const creationStart = (
|
const creationStart = (
|
||||||
{ viewId, frame, doc }: Pick<PlacementInput, 'viewId' | 'frame' | 'doc'>,
|
{ viewId, frame, doc }: Pick<PlacementInput, 'viewId' | 'frame' | 'doc'>,
|
||||||
origin: CreationStart['origin'],
|
origin: CreationStart['origin'],
|
||||||
): CreationStart => ({ viewId, frame, origin, form: emptyForm(doc) })
|
): CreationStart => ({ viewId, frame, origin, form: emptyForm(doc) })
|
||||||
@@ -95,21 +95,36 @@ function popTrace({ tracing, dispatch }: PlacementInput): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The screen-reader path: Enter on the drawing while an add tool is armed and nothing is
|
* The one placement at the centre: the kind's shape at the centre of the frame at the A5
|
||||||
* started places the kind's shape at the centre, as the C7 keyboard path does.
|
* size, its dialog at once. « Placer au centre », Enter on the drawing and the add buttons'
|
||||||
|
* keyboard path all end here; a stale strip hint goes first.
|
||||||
|
*/
|
||||||
|
export function placeAtCentre(
|
||||||
|
scene: Pick<PlacementInput, 'ui' | 'frame' | 'doc' | 'viewId' | 'dispatch'>,
|
||||||
|
kind: NewKind,
|
||||||
|
origin: CreationStart['origin'],
|
||||||
|
): void {
|
||||||
|
const { ui, frame, doc, viewId, dispatch } = scene
|
||||||
|
if (!frame || useAnnotationWork.getState().creation) return
|
||||||
|
dispatch({ type: 'hint', hint: null })
|
||||||
|
const size = newPointSize(doc.annotations, viewId, frame, ui.size)
|
||||||
|
placePending(
|
||||||
|
creationStart(scene, origin),
|
||||||
|
keyboardPending(kind, frame, size),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enter on the drawing while an add tool is armed and nothing is started places the kind's
|
||||||
|
* shape at the centre, as the C7 keyboard path does.
|
||||||
*/
|
*/
|
||||||
function placeAtCentreOnEnter(input: PlacementInput, event: KeyboardEvent) {
|
function placeAtCentreOnEnter(input: PlacementInput, event: KeyboardEvent) {
|
||||||
const { ui, frame, doc, viewId } = input
|
const { ui, frame } = input
|
||||||
if (event.key !== 'Enter' || ui.tool === 'select' || !frame) return
|
if (event.key !== 'Enter' || ui.tool === 'select' || !frame) return
|
||||||
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return
|
if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) return
|
||||||
if (useAnnotationWork.getState().creation) return
|
if (useAnnotationWork.getState().creation) return
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const kind = TOOL_TARGET[ui.tool]
|
placeAtCentre(input, TOOL_TARGET[ui.tool], ui.armedFrom)
|
||||||
const size = newPointSize(doc.annotations, viewId, frame, ui.size)
|
|
||||||
placePending(
|
|
||||||
creationStart(input, ui.armedFrom),
|
|
||||||
keyboardPending(kind, frame, size),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1767,12 +1767,13 @@ export const en: Dict = {
|
|||||||
'editor.annotations.add.point': 'Add a point',
|
'editor.annotations.add.point': 'Add a point',
|
||||||
'editor.annotations.add.zone': 'Add a zone',
|
'editor.annotations.add.zone': 'Add a zone',
|
||||||
'editor.annotations.add.detail_trigger': 'Add a link',
|
'editor.annotations.add.detail_trigger': 'Add a link',
|
||||||
|
'editor.annotations.place_centre': 'Place at the centre',
|
||||||
'editor.annotations.armed.point':
|
'editor.annotations.armed.point':
|
||||||
'Point tool on: tap or click the drawing where you want it, or press Enter on the drawing to place the point at the centre.',
|
'Point tool on: tap or click the drawing where you want it, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same).',
|
||||||
'editor.annotations.armed.zone':
|
'editor.annotations.armed.zone':
|
||||||
'Zone tool on: place the vertices on the drawing, or press Enter on the drawing to place a zone at the centre.',
|
'Zone tool on: place the vertices on the drawing, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same).',
|
||||||
'editor.annotations.armed.detail_trigger':
|
'editor.annotations.armed.detail_trigger':
|
||||||
'Link tool on: place the vertices on the drawing, or press Enter on the drawing to place a link at the centre.',
|
'Link tool on: place the vertices on the drawing, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same).',
|
||||||
'editor.annotations.new.point': 'New point',
|
'editor.annotations.new.point': 'New point',
|
||||||
'editor.annotations.new.zone': 'New zone',
|
'editor.annotations.new.zone': 'New zone',
|
||||||
'editor.annotations.new.detail_trigger': 'New link',
|
'editor.annotations.new.detail_trigger': 'New link',
|
||||||
|
|||||||
@@ -1833,12 +1833,13 @@ export const fr: Dict = {
|
|||||||
'editor.annotations.add.point': 'Ajouter un point',
|
'editor.annotations.add.point': 'Ajouter un point',
|
||||||
'editor.annotations.add.zone': 'Ajouter une zone',
|
'editor.annotations.add.zone': 'Ajouter une zone',
|
||||||
'editor.annotations.add.detail_trigger': 'Ajouter un accès',
|
'editor.annotations.add.detail_trigger': 'Ajouter un accès',
|
||||||
|
'editor.annotations.place_centre': 'Placer au centre',
|
||||||
'editor.annotations.armed.point':
|
'editor.annotations.armed.point':
|
||||||
"Outil Point actif : touchez ou cliquez sur le dessin à l'endroit voulu, ou appuyez sur Entrée dans le dessin pour placer le point au centre.",
|
"Outil Point actif : touchez ou cliquez sur le dessin à l'endroit voulu, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même).",
|
||||||
'editor.annotations.armed.zone':
|
'editor.annotations.armed.zone':
|
||||||
'Outil Zone actif : posez les sommets sur le dessin, ou appuyez sur Entrée dans le dessin pour placer une zone au centre.',
|
'Outil Zone actif : posez les sommets sur le dessin, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même).',
|
||||||
'editor.annotations.armed.detail_trigger':
|
'editor.annotations.armed.detail_trigger':
|
||||||
'Outil Accès actif : posez les sommets sur le dessin, ou appuyez sur Entrée dans le dessin pour placer un accès au centre.',
|
'Outil Accès actif : posez les sommets sur le dessin, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même).',
|
||||||
'editor.annotations.new.point': 'Nouveau point',
|
'editor.annotations.new.point': 'Nouveau point',
|
||||||
'editor.annotations.new.zone': 'Nouvelle zone',
|
'editor.annotations.new.zone': 'Nouvelle zone',
|
||||||
'editor.annotations.new.detail_trigger': 'Nouvel accès',
|
'editor.annotations.new.detail_trigger': 'Nouvel accès',
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
/** U2 trial adjustments, Task 6: « Ajouter … » arms its tool on a pointer press. */
|
/** U2 trial adjustments, Task 6: « Ajouter … » arms its tool on a pointer press. */
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
import {
|
import {
|
||||||
|
act,
|
||||||
cleanup,
|
cleanup,
|
||||||
|
fireEvent,
|
||||||
render,
|
render,
|
||||||
screen,
|
screen,
|
||||||
waitFor,
|
waitFor,
|
||||||
@@ -16,7 +18,7 @@ import { useLocaleStore } from '@/state/localeStore'
|
|||||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||||
import { LayeredTab } from '../helpers/annotationLayer'
|
import { LayeredTab } from '../helpers/annotationLayer'
|
||||||
import { addByKeyboard } from '../helpers/addByKeyboard'
|
import { addByKeyboard } from '../helpers/addByKeyboard'
|
||||||
import { openReady, pressAt, resetStore } from '../helpers/editorHarness'
|
import { openReady, pressAt, resetStore, store } from '../helpers/editorHarness'
|
||||||
|
|
||||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||||
@@ -313,6 +315,185 @@ describe('the screen-reader path', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const centreButton = () =>
|
||||||
|
screen.getByRole('button', { name: 'Placer au centre' })
|
||||||
|
/** No stylesheet in happy-dom: the hidden slot shows as its `invisible` class (CSS visibility). */
|
||||||
|
const centreSlot = () => document.querySelector('[data-place-centre]')!
|
||||||
|
const noCentre = () => expect(centreSlot()).toHaveClass('invisible')
|
||||||
|
|
||||||
|
describe('« Placer au centre »', () => {
|
||||||
|
it('is reachable with a creation tool armed, hidden with Select', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
noCentre()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
expect(centreSlot()).not.toHaveClass('invisible')
|
||||||
|
expect(centreButton()).toBeEnabled()
|
||||||
|
await user.click(tool('Sélectionner et déplacer'))
|
||||||
|
noCentre()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opens the dialog at the centre; Abandon returns to its opener', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
await user.click(centreButton())
|
||||||
|
await dialog('Nouveau point')
|
||||||
|
expect(ghost()).toHaveAttribute('cx', '50')
|
||||||
|
await abandon(user)
|
||||||
|
await waitFor(() => expect(tool('Point')).toHaveFocus())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('armed from « Ajouter une zone »: the zone dialog, focus back on it', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(add('une zone'))
|
||||||
|
await user.click(centreButton())
|
||||||
|
await dialog('Nouvelle zone')
|
||||||
|
expect(ghost().tagName).toBe('polygon')
|
||||||
|
await abandon(user)
|
||||||
|
await waitFor(() => expect(add('une zone')).toHaveFocus())
|
||||||
|
})
|
||||||
|
|
||||||
|
it('answers Enter, Space and a click with detail 0', async () => {
|
||||||
|
for (const press of ['{Enter}', ' ', 'click'] as const) {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
if (press === 'click') fireEvent.click(centreButton())
|
||||||
|
else {
|
||||||
|
centreButton().focus()
|
||||||
|
await user.keyboard(press)
|
||||||
|
}
|
||||||
|
await dialog('Nouveau point')
|
||||||
|
cleanup()
|
||||||
|
resetStore()
|
||||||
|
resetWork()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('is not available during a creation nor a tracing', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
await user.click(centreButton())
|
||||||
|
const shown = await dialog('Nouveau point')
|
||||||
|
noCentre()
|
||||||
|
await user.click(
|
||||||
|
within(shown).getByRole('button', { name: 'Replacer le point' }),
|
||||||
|
)
|
||||||
|
await waitFor(noDialog)
|
||||||
|
noCentre()
|
||||||
|
await user.click(tool('Zone'))
|
||||||
|
pressAt(canvas(), 30, 30)
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(useAnnotationWork.getState().creation).not.toBeNull(),
|
||||||
|
)
|
||||||
|
noCentre()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('is not available when nothing can be created', async () => {
|
||||||
|
const bare = JSON.parse(drawnText())
|
||||||
|
bare.categories = []
|
||||||
|
await openReady({ text: JSON.stringify(bare) })
|
||||||
|
render(<LayeredTab {...props} />)
|
||||||
|
noCentre()
|
||||||
|
expect(tool('Point')).toBeDisabled()
|
||||||
|
cleanup()
|
||||||
|
resetStore()
|
||||||
|
resetWork()
|
||||||
|
await mount()
|
||||||
|
expect(tool('Accès à une vue détaillée')).toBeDisabled()
|
||||||
|
noCentre()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('goes away when the last category is removed while Point is armed', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
expect(centreSlot()).not.toHaveClass('invisible')
|
||||||
|
act(() => {
|
||||||
|
store
|
||||||
|
.getState()
|
||||||
|
.commit({ op: 'remove', key: { kind: 'category', id: 'cat-a' } })
|
||||||
|
})
|
||||||
|
await waitFor(noCentre)
|
||||||
|
expect(tool('Point')).toHaveAttribute('aria-pressed', 'true')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('goes away when the last link child disappears while Link is armed', async () => {
|
||||||
|
const user = await mount(withDetail())
|
||||||
|
await user.click(tool('Accès à une vue détaillée'))
|
||||||
|
expect(centreSlot()).not.toHaveClass('invisible')
|
||||||
|
act(() => {
|
||||||
|
store
|
||||||
|
.getState()
|
||||||
|
.commit({ op: 'remove', key: { kind: 'view', id: 'view-det' } })
|
||||||
|
})
|
||||||
|
await waitFor(noCentre)
|
||||||
|
expect(tool('Accès à une vue détaillée')).toHaveAttribute(
|
||||||
|
'aria-pressed',
|
||||||
|
'true',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('is unavailable while the drawing could not be built, the Point tool armed', async () => {
|
||||||
|
await openReady()
|
||||||
|
const { preview } = store.getState()
|
||||||
|
vi.spyOn(preview!, 'canvas').mockReturnValue({
|
||||||
|
ok: false,
|
||||||
|
kind: 'svg_rejected',
|
||||||
|
})
|
||||||
|
render(<LayeredTab {...props} />)
|
||||||
|
await waitFor(() => expect(tool('Point')).toBeEnabled())
|
||||||
|
const user = userEvent.setup()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
expect(tool('Point')).toHaveAttribute('aria-pressed', 'true')
|
||||||
|
expect(canvas().querySelector('[data-anno-id]')).toBeNull()
|
||||||
|
noCentre()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('clears a stale hint', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
pressAt(canvas(), -5, 50)
|
||||||
|
expect(
|
||||||
|
await screen.findByText("Cliquez à l'intérieur du dessin."),
|
||||||
|
).toBeInTheDocument()
|
||||||
|
await user.click(centreButton())
|
||||||
|
await dialog('Nouveau point')
|
||||||
|
expect(screen.queryByText("Cliquez à l'intérieur du dessin.")).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Enter on « Ajouter un point » places a point while Zone is armed', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Zone'))
|
||||||
|
await addByKeyboard(user, add('un point'))
|
||||||
|
await dialog('Nouveau point')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the status reads the armed text from the column, not during a creation', async () => {
|
||||||
|
const user = await mount()
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
expect(status()).toHaveTextContent('Placer au centre')
|
||||||
|
await user.click(tool('Sélectionner et déplacer'))
|
||||||
|
await addByKeyboard(user, add('un point'))
|
||||||
|
const shown = await dialog('Nouveau point')
|
||||||
|
expect(status()).toBeEmptyDOMElement()
|
||||||
|
await user.click(
|
||||||
|
within(shown).getByRole('button', { name: 'Replacer le point' }),
|
||||||
|
)
|
||||||
|
await waitFor(noDialog)
|
||||||
|
expect(status()).toBeEmptyDOMElement()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('stays available with a selection, the strip unchanged', async () => {
|
||||||
|
const user = await mount(insert(drawnText(), point('pt-a', 50, 50, 5)))
|
||||||
|
const list = await screen.findByRole('list', {
|
||||||
|
name: 'Annotations de la vue',
|
||||||
|
})
|
||||||
|
await user.click(within(list).getAllByRole('button')[0])
|
||||||
|
const before = lead().textContent
|
||||||
|
await user.click(tool('Point'))
|
||||||
|
expect(centreButton()).toBeEnabled()
|
||||||
|
expect(lead().textContent).toBe(before)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('a redraw lends the zone tool', () => {
|
describe('a redraw lends the zone tool', () => {
|
||||||
it('« Ajouter une zone » is not armed, and arms a NEW zone when pressed', async () => {
|
it('« Ajouter une zone » is not armed, and arms a NEW zone when pressed', async () => {
|
||||||
const user = await mount(withZone())
|
const user = await mount(withZone())
|
||||||
@@ -335,4 +516,27 @@ describe('the dictionaries', () => {
|
|||||||
for (const kind of ['point', 'zone', 'detail_trigger'])
|
for (const kind of ['point', 'zone', 'detail_trigger'])
|
||||||
expect(dict[`editor.annotations.armed.${kind}`]).toBeTruthy()
|
expect(dict[`editor.annotations.armed.${kind}`]).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('word « Placer au centre » and its hint exactly, below the drawing', () => {
|
||||||
|
expect(fr['editor.annotations.place_centre']).toBe('Placer au centre')
|
||||||
|
expect(en['editor.annotations.place_centre']).toBe('Place at the centre')
|
||||||
|
expect(fr['editor.annotations.armed.point']).toBe(
|
||||||
|
"Outil Point actif : touchez ou cliquez sur le dessin à l'endroit voulu, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même).",
|
||||||
|
)
|
||||||
|
expect(fr['editor.annotations.armed.zone']).toBe(
|
||||||
|
'Outil Zone actif : posez les sommets sur le dessin, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même).',
|
||||||
|
)
|
||||||
|
expect(fr['editor.annotations.armed.detail_trigger']).toBe(
|
||||||
|
'Outil Accès actif : posez les sommets sur le dessin, ou choisissez « Placer au centre », sous le dessin (Entrée dans le dessin fait de même).',
|
||||||
|
)
|
||||||
|
expect(en['editor.annotations.armed.point']).toBe(
|
||||||
|
'Point tool on: tap or click the drawing where you want it, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same).',
|
||||||
|
)
|
||||||
|
expect(en['editor.annotations.armed.zone']).toBe(
|
||||||
|
'Zone tool on: place the vertices on the drawing, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same).',
|
||||||
|
)
|
||||||
|
expect(en['editor.annotations.armed.detail_trigger']).toBe(
|
||||||
|
'Link tool on: place the vertices on the drawing, or choose “Place at the centre”, below the drawing (Enter on the drawing does the same).',
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user