feat(editor): vertex handles, insert and remove, zone move, redraw
U2 Task 5. A selected polygon gets its vertex, « + » and « − » handles (R-9, hidden « + » under two hit radii, R-18 zoom hint in the strip), the handle cap at 40 (R-7), vertex drag and keys, the move mode on the zone or the chosen vertex, « Redessiner » as a redraw mode kept in step with its tracing (R-12 guard, R-13 drop), close radius in CSS px (R-11). The numeric group leaves the properties panel (D1). Removed or rewritten assertions (numeric group -> replacement): - tab « shows its exact stored numbers » (Centre x field) -> the overlay selection circle's cx attribute, same exact value. - tab « a numeric edit » x3 -> « an edit on the drawing »: Enter on the handle without a step commits nothing, a step + Enter commits once; a refused handle drag keeps the stored shape then a drag inside the frame repairs it (issues gone); Escape drops a pending series. - tab C26 « Centre x 15 » -> overlay cx 15. - tab C32 unmeasured « Centre x as text » -> no handle, no field. - tab « adds and removes a vertex as part of the whole group » -> « + » then « − » on the drawing; « never offers to remove below three » -> « − » aria-disabled at 3. - tab H8 « refused Remplacer drops the tracing » -> keeps it open with « Fermeture refusée » (board 33 A); « refused vertex add/remove stay non appliqué » -> a refused vertex drag restores the shape exactly. - tab Désélectionner and D6b (typed Centre x committed, refused, undone) x6 and strip « a new commit replaces the message » -> the same with the Nom (FR) field (a blank name is the refused value). - focus-request « Centre x 20 » -> overlay cx 20. - escape « strip commands keep their Escape » -> a redraw: Escape on the strip or the box cancels it (R-12 row 4); kept for a new zone tracing. - keep-alive « Remplacer tracing kept across Aller à » -> ended by a tab when empty, asked once a vertex is placed (R-12). - e2e annotations: numeric cx edit + undo/redo -> handle keys + undo/ redo; jitter/drag and Task 4 point reads -> overlay attributes (the stored place during the mode -> overlay-old-place); keyboard-only cy and vertex x typed -> handle and vertex keys. - e2e deselect: Centre x typed/refused/committed -> Nom (FR). - e2e geometry, shell-crossing: Centre x/cy reads -> overlay attributes. - e2e journey: cx +3 and vertex x +4 typed -> 3 and 4 arrow steps + Enter; a far typed value + revert -> a far handle drag refused. - e2e equine latency: typed cx rounds -> handle arrow + Enter rounds.
This commit is contained in:
1 parent
ba8e766fe8
commit
6211046537
44 files changed
+3790
-1050
No files matched your search
@@ -0,0 +1,120 @@
|
||||
/** U2 Task 5: the polygon arithmetic of the vertex handles (R-7, R-9). */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Point } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
HANDLE_CAP,
|
||||
MIN_VERTICES,
|
||||
insertMidpoint,
|
||||
isNoOpMove,
|
||||
moveVertex,
|
||||
removeVertex,
|
||||
showsInsert,
|
||||
} from '@/editor/annotations/polygonEdit'
|
||||
|
||||
const square: Point[] = [
|
||||
[0, 0],
|
||||
[10, 0],
|
||||
[10, 10],
|
||||
[0, 10],
|
||||
]
|
||||
|
||||
describe('the limits', () => {
|
||||
it('caps the handles at 40 vertices and keeps 3 at least', () => {
|
||||
expect(HANDLE_CAP).toBe(40)
|
||||
expect(MIN_VERTICES).toBe(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('insertMidpoint', () => {
|
||||
it.each([
|
||||
[0, [5, 0], 1],
|
||||
[2, [5, 10], 3],
|
||||
// The last segment wraps to the first vertex.
|
||||
[3, [0, 5], 4],
|
||||
] as const)('after %i adds %j at %i', (after, middle, at) => {
|
||||
const next = insertMidpoint(square, after)!
|
||||
expect(next).toHaveLength(5)
|
||||
expect(next[at]).toEqual(middle)
|
||||
})
|
||||
|
||||
it('rounds the midpoint to the 0.01 grid', () => {
|
||||
const odd: Point[] = [
|
||||
[0, 0],
|
||||
[0.015, 0.025],
|
||||
[5, 5],
|
||||
]
|
||||
expect(insertMidpoint(odd, 0)![1]).toEqual([0.01, 0.01])
|
||||
})
|
||||
|
||||
it.each([-1, 4, 1.5, Number.NaN])('gives null for index %s', (index) => {
|
||||
expect(insertMidpoint(square, index)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('removeVertex', () => {
|
||||
it('removes the vertex at the index', () => {
|
||||
expect(removeVertex(square, 1)).toEqual([
|
||||
[0, 0],
|
||||
[10, 10],
|
||||
[0, 10],
|
||||
])
|
||||
})
|
||||
|
||||
it('gives null at 3 vertices and out of range', () => {
|
||||
expect(removeVertex(square.slice(0, 3), 0)).toBeNull()
|
||||
expect(removeVertex(square, 4)).toBeNull()
|
||||
expect(removeVertex(square, -1)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('moveVertex', () => {
|
||||
it('moves one vertex, rounded to 0.01', () => {
|
||||
const next = moveVertex(square, 2, { x: 12.345, y: 9.999 })!
|
||||
expect(next[2]).toEqual([12.35, 10])
|
||||
expect(next[0]).toBe(square[0])
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ x: Number.NaN, y: 1 },
|
||||
{ x: 1, y: Number.POSITIVE_INFINITY },
|
||||
])('gives null for a non-finite place %j', (to) => {
|
||||
expect(moveVertex(square, 0, to)).toBeNull()
|
||||
})
|
||||
|
||||
it('gives null out of range', () => {
|
||||
expect(moveVertex(square, 9, { x: 1, y: 1 })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isNoOpMove', () => {
|
||||
const movedTo = (index: number, x: number, y: number) =>
|
||||
moveVertex(square, index, { x, y })!
|
||||
|
||||
it.each([
|
||||
['itself', 1, 10, 0],
|
||||
['the next vertex', 1, 10, 10],
|
||||
['the previous vertex', 1, 0, 0],
|
||||
// Wrapping both ways.
|
||||
['the previous one across the start', 0, 0, 10],
|
||||
['the next one across the end', 3, 0, 0],
|
||||
] as const)('a release on %s is no change', (_, index, x, y) => {
|
||||
expect(isNoOpMove(square, index, movedTo(index, x, y))).toBe(true)
|
||||
})
|
||||
|
||||
it('a release elsewhere is a change, even on a vertex that is not a neighbour', () => {
|
||||
expect(isNoOpMove(square, 0, movedTo(0, 3, 3))).toBe(false)
|
||||
expect(isNoOpMove(square, 0, movedTo(0, 10, 10))).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('showsInsert (R-9)', () => {
|
||||
it.each([
|
||||
[20, 10, true],
|
||||
[19.99, 10, false],
|
||||
[44, 22, true],
|
||||
[43.9, 22, false],
|
||||
[0, 10, false],
|
||||
])('a %s px segment with a %s px hit radius: %s', (segment, hit, shown) => {
|
||||
expect(showsInsert(segment, hit)).toBe(shown)
|
||||
})
|
||||
})
|
||||
@@ -50,7 +50,13 @@ describe('dropStale (R-13)', () => {
|
||||
|
||||
it('a new session (another sheet, the editor closed) resets the work', () => {
|
||||
useAnnotationWork.setState({
|
||||
mode: { kind: 'move', annotationId: 'a', started: true, base: 'one' },
|
||||
mode: {
|
||||
kind: 'move',
|
||||
annotationId: 'a',
|
||||
started: true,
|
||||
base: 'one',
|
||||
vertex: null,
|
||||
},
|
||||
})
|
||||
useEditorStore.setState({ session: useEditorStore.getState().session + 1 })
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
|
||||
@@ -14,8 +14,10 @@ import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDial
|
||||
import { guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import {
|
||||
resetWork,
|
||||
markRedraw,
|
||||
setModePreview,
|
||||
startMove,
|
||||
startRedraw,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { useLeaveGuardStore } from '@/state/leaveGuardStore'
|
||||
|
||||
@@ -160,3 +162,44 @@ describe('SignOutButton and a started move on the drawing (R-12)', () => {
|
||||
expect(signOut).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('SignOutButton and a started redraw (R-12)', () => {
|
||||
beforeEach(() => {
|
||||
useLeaveGuardStore.getState().setAsk(guardDrawing)
|
||||
startRedraw('a', 'doc')
|
||||
markRedraw(true)
|
||||
})
|
||||
afterEach(() => {
|
||||
useLeaveGuardStore.getState().setAsk(null)
|
||||
resetWork()
|
||||
})
|
||||
|
||||
it('asks « Abandonner le nouveau tracé ? »; « Abandonner » signs out', async () => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<SignOutButton />
|
||||
<DrawingGuardDialog />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
await click()
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Abandonner le nouveau tracé ?' }),
|
||||
).toBeInTheDocument()
|
||||
expect(signOut).not.toHaveBeenCalled()
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
await waitFor(() => expect(signOut).toHaveBeenCalledTimes(1))
|
||||
})
|
||||
|
||||
it('an unstarted redraw signs out at once and ends', async () => {
|
||||
markRedraw(false)
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<SignOutButton />
|
||||
<DrawingGuardDialog />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
await click()
|
||||
await waitFor(() => expect(signOut).toHaveBeenCalledTimes(1))
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -61,8 +61,28 @@ const props = {
|
||||
const named = (id: string, cx: number, cy: number, r: number) =>
|
||||
point(id, cx, cy, r)
|
||||
const annotations = () => store.getState().previewState!.document.annotations
|
||||
const nameOf = (id: string) =>
|
||||
annotations().find((a: Annotation) => a.id === id)?.name?.fr
|
||||
const geometryOf = (id: string) =>
|
||||
annotations().find((a: Annotation) => a.id === id)?.geometry
|
||||
/** The selection as the overlay draws it (U2 Task 5: no coordinate field in the panel). */
|
||||
const shownCircle = () =>
|
||||
screen.getByTestId('overlay-selection').querySelector('circle')!
|
||||
/** A mouse drag of `el` from `from` to `to`, past the 4 px slop. */
|
||||
function mouseDrag(el: Element, from: [number, number], to: [number, number]) {
|
||||
const at = ([x, y]: [number, number], buttons = 1) => ({
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
pointerId: 1,
|
||||
isPrimary: true,
|
||||
button: 0,
|
||||
buttons,
|
||||
pointerType: 'mouse',
|
||||
})
|
||||
fireEvent.pointerDown(el, at(from))
|
||||
fireEvent.pointerMove(el, at(to))
|
||||
fireEvent.pointerUp(el, at(to, 0))
|
||||
}
|
||||
|
||||
/** Screen = drawing: the overlay's inverse CTM is the identity in the page under test. */
|
||||
function stubCtm(): void {
|
||||
@@ -105,14 +125,12 @@ async function selectFromList(name: RegExp | string = /N/) {
|
||||
}
|
||||
|
||||
describe('selection and the list', () => {
|
||||
it('lists the view annotations, selects one and shows its exact stored numbers', async () => {
|
||||
it('lists the view annotations, selects one and draws its exact stored numbers', async () => {
|
||||
await mount({
|
||||
text: insert(drawnText(), named('anno-a', 743.0451049804688, 50, 5)),
|
||||
})
|
||||
const panel = await selectFromList()
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue(
|
||||
'743.0451049804688',
|
||||
)
|
||||
await selectFromList()
|
||||
expect(shownCircle()).toHaveAttribute('cx', '743.0451049804688')
|
||||
expect(screen.getByTestId('edit-strip-detail')).toHaveTextContent('Point')
|
||||
})
|
||||
|
||||
@@ -126,52 +144,37 @@ describe('selection and the list', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('a numeric edit', () => {
|
||||
it('commits only when the typed number differs from the stored one', async () => {
|
||||
describe('an edit on the drawing (U2 Task 5: the numeric group left the panel)', () => {
|
||||
it('commits only when the shape changes', async () => {
|
||||
await mount()
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
await selectFromList()
|
||||
const version = store.getState().handleVersion
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.click(cx)
|
||||
await user.keyboard('{Enter}')
|
||||
const handle = screen.getByTestId('point-handle')
|
||||
fireEvent.keyDown(handle, { key: 'Enter' })
|
||||
expect(store.getState().handleVersion).toBe(version)
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60{Enter}')
|
||||
fireEvent.keyDown(handle, { key: 'ArrowRight' })
|
||||
fireEvent.keyDown(handle, { key: 'Enter' })
|
||||
expect(geometryOf('anno-a')).toEqual({
|
||||
type: 'circle',
|
||||
cx: 60,
|
||||
cx: 50.5,
|
||||
cy: 50,
|
||||
r: 5,
|
||||
})
|
||||
expect(store.getState().handleVersion).toBe(version + 1)
|
||||
})
|
||||
|
||||
it('keeps a refused value as « non appliqué » with the document unchanged, then applies a coherent set', async () => {
|
||||
it('a refused place keeps the stored shape, then a place inside the frame repairs it', async () => {
|
||||
await mount({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const before = store.getState().documentText
|
||||
expect(
|
||||
within(panel).getByTestId('annotation-geometry-issues'),
|
||||
).toBeInTheDocument()
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '50{Enter}')
|
||||
mouseDrag(pointHandle(), [150, 150], [50, 150])
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(within(panel).getByText('non appliqué')).toBeInTheDocument()
|
||||
expect(
|
||||
within(panel).getByText(/Valeurs non appliquées/),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Revenir aux valeurs enregistrées',
|
||||
}),
|
||||
).toBeInTheDocument()
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('50')
|
||||
const cy = within(panel).getByLabelText('Centre y')
|
||||
await user.clear(cy)
|
||||
await user.type(cy, '50{Enter}')
|
||||
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
|
||||
expect(shownCircle()).toHaveAttribute('cx', '150')
|
||||
mouseDrag(pointHandle(), [150, 150], [50, 50])
|
||||
expect(geometryOf('anno-a')).toEqual({
|
||||
type: 'circle',
|
||||
cx: 50,
|
||||
@@ -181,19 +184,17 @@ describe('a numeric edit', () => {
|
||||
expect(screen.queryByTestId('annotation-geometry-issues')).toBeNull()
|
||||
})
|
||||
|
||||
it('reverts the group to the saved values', async () => {
|
||||
await mount({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '50{Enter}')
|
||||
await user.click(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Revenir aux valeurs enregistrées',
|
||||
}),
|
||||
)
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('150')
|
||||
it('Escape drops a pending series: the stored shape shows again', async () => {
|
||||
await mount({ text: insert(drawnText(), named('anno-a', 50, 50, 5)) })
|
||||
await selectFromList()
|
||||
const before = store.getState().documentText
|
||||
const handle = screen.getByTestId('point-handle')
|
||||
fireEvent.keyDown(handle, { key: 'ArrowRight' })
|
||||
expect(shownCircle()).toHaveAttribute('cx', '50.5')
|
||||
// This mount has no workspace wrapper: Escape is pressed with nothing focused.
|
||||
fireEvent.keyDown(document.body, { key: 'Escape' })
|
||||
expect(shownCircle()).toHaveAttribute('cx', '50')
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -307,8 +308,8 @@ describe('the point tool and the corrected position (C26)', () => {
|
||||
})
|
||||
expect(panel).not.toBeInTheDocument()
|
||||
expect(screen.queryByTestId('overlay-click-cross')).toBeNull()
|
||||
const props = await screen.findByTestId('annotation-properties')
|
||||
expect(within(props).getByLabelText('Centre x')).toHaveValue('15')
|
||||
await screen.findByTestId('annotation-properties')
|
||||
expect(shownCircle()).toHaveAttribute('cx', '15')
|
||||
})
|
||||
|
||||
it('keeps the pending point at the click when the correction is cancelled', async () => {
|
||||
@@ -495,12 +496,9 @@ describe('an unmeasured view (C32)', () => {
|
||||
screen.getAllByText(/Ce dessin n'est pas mesurable/).length,
|
||||
).toBeGreaterThan(0)
|
||||
const panel = await selectFromList()
|
||||
expect(
|
||||
within(panel).queryByRole('textbox', { name: 'Centre x' }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(panel).getByText('Centre x', { exact: false }),
|
||||
).toBeInTheDocument()
|
||||
// Nothing edits the geometry of an unmeasured view: no handle, no field.
|
||||
expect(screen.queryByTestId('point-handle')).toBeNull()
|
||||
expect(within(panel).queryByRole('textbox', { name: /^Centre/ })).toBeNull()
|
||||
expect(
|
||||
within(panel).getByText(/Ce dessin n'est pas mesurable/),
|
||||
).toBeInTheDocument()
|
||||
@@ -657,14 +655,13 @@ describe('polygons and paths', () => {
|
||||
const zoneText = (geometry: object) =>
|
||||
insert(drawnText(), { kind: 'annotation', value: zoneAnnotation(geometry) })
|
||||
|
||||
it('adds and removes a vertex as part of the whole group', async () => {
|
||||
const handleHit = (name: string) =>
|
||||
screen.getByRole('button', { name }).querySelector('[data-handle]')!
|
||||
|
||||
it('« + » adds a vertex on the drawing and « − » removes it', async () => {
|
||||
await mount({ text: zoneText({ type: 'polygon', points: triangle }) })
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
await user.click(within(panel).getByLabelText('x du sommet 1'))
|
||||
await user.click(
|
||||
within(panel).getByRole('button', { name: 'Ajouter un sommet' }),
|
||||
)
|
||||
await selectFromList()
|
||||
pressAt(handleHit('Ajouter un sommet après le sommet 1'), 50, 20)
|
||||
expect(geometryOf('zone-a')).toMatchObject({
|
||||
points: [
|
||||
[20, 20],
|
||||
@@ -673,18 +670,17 @@ describe('polygons and paths', () => {
|
||||
[50, 80],
|
||||
],
|
||||
})
|
||||
await user.click(within(panel).getByRole('button', { name: 'Retirer' }))
|
||||
expect(geometryOf('zone-a')).toMatchObject({
|
||||
points: triangle.slice(0, 3).map((p, i) => (i === 0 ? [50, 20] : p)),
|
||||
})
|
||||
pressAt(handleHit('Retirer le sommet 2'), 50, 10)
|
||||
expect(geometryOf('zone-a')).toMatchObject({ points: triangle })
|
||||
})
|
||||
|
||||
it('never offers to remove a vertex below three', async () => {
|
||||
it('never removes a vertex below three: « − » is greyed', async () => {
|
||||
await mount({ text: zoneText({ type: 'polygon', points: triangle }) })
|
||||
const panel = await selectFromList()
|
||||
await selectFromList()
|
||||
pressAt(handleHit('Sommet 1'), 20, 20)
|
||||
expect(
|
||||
within(panel).getByRole('button', { name: 'Retirer' }),
|
||||
).toBeDisabled()
|
||||
screen.getByRole('button', { name: 'Retirer le sommet 1' }),
|
||||
).toHaveAttribute('aria-disabled', 'true')
|
||||
})
|
||||
|
||||
it('moves a selected polygon as a block', async () => {
|
||||
@@ -857,7 +853,7 @@ describe('refusals through the tab (H8)', () => {
|
||||
const zoneText = (geometry: object) =>
|
||||
insert(drawnText(), { kind: 'annotation', value: zoneAnnotation(geometry) })
|
||||
|
||||
it('a refused « Remplacer par un polygone » drops the tracing, shows the core message', async () => {
|
||||
it('a refused « Remplacer par un polygone » keeps the tracing open, with the core message', async () => {
|
||||
const path = { type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' }
|
||||
await mount({ text: zoneText(path) })
|
||||
const panel = await selectFromList()
|
||||
@@ -874,35 +870,31 @@ describe('refusals through the tab (H8)', () => {
|
||||
].forEach(([x, y]) => pressAt(canvas, x, y))
|
||||
fireEvent.keyDown(canvas, { key: 'Enter' })
|
||||
expect(await screen.findByRole('alert')).toBeInTheDocument()
|
||||
// Board 33 A: the tracing stays open with its commands (it was dropped before Task 5).
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Annuler le tracé' }),
|
||||
).toBeNull()
|
||||
screen.getByRole('button', { name: 'Annuler le tracé' }),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||
'Fermeture refusée',
|
||||
)
|
||||
expect(geometryOf('zone-a')).toEqual(path)
|
||||
})
|
||||
|
||||
it('a refused vertex add and a refused remove stay « non appliqué », document unchanged', async () => {
|
||||
it('a refused vertex move restores the shape exactly, document unchanged', async () => {
|
||||
await mount({
|
||||
text: zoneText({ type: 'polygon', points: [...triangle, [20, 60]] }),
|
||||
})
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
await selectFromList()
|
||||
const before = store.getState().documentText
|
||||
const x = within(panel).getByLabelText('x du sommet 1')
|
||||
await user.clear(x)
|
||||
await user.type(x, '500{Enter}')
|
||||
await user.click(
|
||||
within(panel).getByRole('button', { name: 'Ajouter un sommet' }),
|
||||
const vertex = screen
|
||||
.getByRole('button', { name: 'Sommet 1' })
|
||||
.querySelector('[data-handle]')!
|
||||
mouseDrag(vertex, [20, 20], [500, 20])
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(screen.getByTestId('overlay-refused-place')).toBeInTheDocument()
|
||||
expect(screen.getByTestId('gesture-line')).toHaveTextContent(
|
||||
'Déplacement refusé',
|
||||
)
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(within(panel).getAllByLabelText(/^x du sommet/)).toHaveLength(5)
|
||||
expect(
|
||||
within(panel).getByText(/Valeurs non appliquées/),
|
||||
).toBeInTheDocument()
|
||||
await user.click(within(panel).getByRole('button', { name: 'Retirer' }))
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
expect(
|
||||
within(panel).getByText(/Valeurs non appliquées/),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1038,12 +1030,12 @@ describe('« Désélectionner » (R1, A6)', () => {
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
await user.clear(within(panel).getByLabelText('Centre x'))
|
||||
await user.type(within(panel).getByLabelText('Centre x'), '60{Enter}')
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
await user.clear(within(panel).getByLabelText('Nom (FR)'))
|
||||
await user.type(within(panel).getByLabelText('Nom (FR)'), 'Nuque{Enter}')
|
||||
expect(nameOf('anno-a')).toBe('Nuque')
|
||||
await user.click(button(panel))
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
|
||||
expect(nameOf('anno-a')).toBe('N')
|
||||
})
|
||||
|
||||
it('read-only: no « Supprimer », it deselects and focuses the ro- row', async () => {
|
||||
@@ -1065,23 +1057,22 @@ describe('« Désélectionner » (R1, A6)', () => {
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60')
|
||||
const name = within(panel).getByLabelText('Nom (FR)')
|
||||
await user.clear(name)
|
||||
await user.type(name, 'Nuque')
|
||||
const depth = store.getState().undo.length
|
||||
await user.click(button(panel))
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
expect(nameOf('anno-a')).toBe('Nuque')
|
||||
expect(store.getState().undo.length).toBe(depth + 1)
|
||||
})
|
||||
|
||||
it('a refused typed value: the panel closes, the document is unchanged', async () => {
|
||||
await mountSpy({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
|
||||
await mountSpy()
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const before = store.getState().documentText
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '1000000')
|
||||
// A blank name is refused (both names are required).
|
||||
await user.clear(within(panel).getByLabelText('Nom (FR)'))
|
||||
await user.click(button(panel))
|
||||
expect(screen.queryByTestId('annotation-properties')).toBeNull()
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
@@ -1585,40 +1576,39 @@ describe('a tap on the drawing (D6b)', () => {
|
||||
it('undo after a tap deselect undoes the earlier edit, redo restores it', async () => {
|
||||
await selected()
|
||||
const user = userEvent.setup()
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60{Enter}')
|
||||
const name = screen.getByLabelText('Nom (FR)')
|
||||
await user.clear(name)
|
||||
await user.type(name, 'Nuque{Enter}')
|
||||
tap(rect())
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
|
||||
expect(nameOf('anno-a')).toBe('N')
|
||||
act(() => void store.getState().redoStep())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
expect(nameOf('anno-a')).toBe('Nuque')
|
||||
})
|
||||
|
||||
it('commits a typed valid value once and deselects when the press blurs the field', async () => {
|
||||
await selected()
|
||||
const user = userEvent.setup()
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60')
|
||||
const name = screen.getByLabelText('Nom (FR)')
|
||||
await user.clear(name)
|
||||
await user.type(name, 'Nuque')
|
||||
const depth = store.getState().undo.length
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
// What mousedown does: the focus moves to the box, the field commits, the drawing rebuilds.
|
||||
act(() => box().focus())
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(rect())
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
expect(nameOf('anno-a')).toBe('Nuque')
|
||||
expect(store.getState().undo.length).toBe(depth + 1)
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
it('a refused typed value: the panel closes, the document is unchanged', async () => {
|
||||
await selected({ text: insert(drawnText(), named('anno-a', 150, 150, 5)) })
|
||||
await selected()
|
||||
const user = userEvent.setup()
|
||||
const before = store.getState().documentText
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '1000000')
|
||||
// A blank name is refused (both names are required).
|
||||
await user.clear(screen.getByLabelText('Nom (FR)'))
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
act(() => box().focus())
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
@@ -1815,10 +1805,10 @@ describe('the strip', () => {
|
||||
await selectFromList()
|
||||
drag(marker('anno-a'), [60, 40])
|
||||
expect(line()).toHaveTextContent('Point déplacé')
|
||||
const cx = screen.getByLabelText('Centre x')
|
||||
const name = screen.getByLabelText('Nom (FR)')
|
||||
const user = userEvent.setup()
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '30{Enter}')
|
||||
await user.clear(name)
|
||||
await user.type(name, 'Nuque{Enter}')
|
||||
expect(line()).not.toHaveTextContent('Point déplacé')
|
||||
drag(marker('anno-a'), [40, 40])
|
||||
expect(line()).toHaveTextContent('Point déplacé')
|
||||
|
||||
@@ -14,7 +14,7 @@ import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import ModalDialog from '@/components/ui/ModalDialog'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, edit, insert, point } from '../helpers/editorFixtures'
|
||||
import { resetStore, serverHas, store } from '../helpers/editorHarness'
|
||||
import { pressAt, resetStore, serverHas, store } from '../helpers/editorHarness'
|
||||
import { openFinding } from '../helpers/findingDialog'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
@@ -240,14 +240,32 @@ describe('Escape leaves alone', () => {
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('a tracing: the strip tracing commands keep their Escape, the canvas box cancels the tracing only', async () => {
|
||||
it('a new zone tracing: the strip tracing commands keep their Escape (Task 7 asks)', async () => {
|
||||
const user = await mount(ZONE())
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
pressAt(canvasBox(), 20, 20)
|
||||
const bar = await screen.findByTestId('tracing-commands')
|
||||
bar.focus()
|
||||
escape(bar)
|
||||
expect(screen.queryByTestId('tracing-commands')).not.toBeNull()
|
||||
})
|
||||
|
||||
// U2 Task 5 (R-12, board 32 row 4): « Remplacer par un polygone » is a redraw, which
|
||||
// Escape cancels at once from anywhere in the workspace, the strip's commands included
|
||||
// (before Task 5 only the canvas box did). The selection stays.
|
||||
it('a redraw: Escape on the strip commands or on the canvas box cancels the tracing only', async () => {
|
||||
const user = await mount(ZONE())
|
||||
await select(user, 'zone-a')
|
||||
await user.click(inPanel('Remplacer par un polygone'))
|
||||
const bar = await screen.findByTestId('tracing-commands')
|
||||
bar.focus()
|
||||
escape(bar)
|
||||
expect(screen.queryByTestId('tracing-commands')).not.toBeNull()
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByTestId('tracing-commands')).toBeNull(),
|
||||
)
|
||||
expect(panel()).toBeDefined()
|
||||
await user.click(inPanel('Remplacer par un polygone'))
|
||||
await screen.findByTestId('tracing-commands')
|
||||
canvasBox().focus()
|
||||
escape(canvasBox())
|
||||
await waitFor(() =>
|
||||
|
||||
@@ -135,7 +135,11 @@ describe('focus requests', () => {
|
||||
)
|
||||
// anno-b and anno-a share a name: the circle's centre tells which one is selected.
|
||||
const properties = await screen.findByTestId('annotation-properties')
|
||||
expect(within(properties).getByLabelText('Centre x')).toHaveValue('20')
|
||||
expect(properties).toBeInTheDocument()
|
||||
// U2 Task 5: no coordinate field in the panel; the overlay draws the selection.
|
||||
expect(
|
||||
screen.getByTestId('overlay-selection').querySelector('circle'),
|
||||
).toHaveAttribute('cx', '20')
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toHaveAttribute('data-properties-heading'),
|
||||
)
|
||||
|
||||
@@ -17,6 +17,7 @@ import { usePlaceVisible } from '@/lib/placeVisibility'
|
||||
import { FocusConsumedContext } from '@/editor/focusRequest'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { cleanSvg } from '@/editor/core/cleaning'
|
||||
import {
|
||||
ASSET,
|
||||
@@ -512,7 +513,9 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
expect(liveText()).toContain('tracé est en cours')
|
||||
})
|
||||
|
||||
it('a « Remplacer par un polygone » tracing is kept and focused (it cannot coexist with a pending creation)', async () => {
|
||||
// U2 Task 5 (R-12): « Remplacer par un polygone » is a redraw mode. With nothing placed a
|
||||
// tab ends it at once; with a vertex placed the tab asks first and « Continuer » keeps it.
|
||||
it('a « Remplacer par un polygone » redraw: ended by a tab when empty, asked once a vertex is placed', async () => {
|
||||
const zone = point('zone-a', 0, 0, 1)
|
||||
const zoneValue = {
|
||||
...zone.value,
|
||||
@@ -524,22 +527,33 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
value: zoneValue,
|
||||
} as typeof zone)
|
||||
const user = await mount(text)
|
||||
await gotoBare(user, async () => {
|
||||
const drawing = inPlace('annotations.drawing')
|
||||
const list = drawing.getByRole('list', { name: 'Annotations de la vue' })
|
||||
await user.click(within(list).getAllByRole('button')[0])
|
||||
const drawing = inPlace('annotations.drawing')
|
||||
const replace = async () => {
|
||||
await user.click(
|
||||
await drawing.findByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
expect(drawing.getByTestId('tracing-commands')).toBeVisible()
|
||||
})
|
||||
const bar = within(place('annotations.drawing')).getByTestId(
|
||||
'tracing-commands',
|
||||
)
|
||||
await waitFor(() => expect(document.activeElement).toBe(bar))
|
||||
expect(liveText()).toContain('tracé est en cours')
|
||||
}
|
||||
const list = drawing.getByRole('list', { name: 'Annotations de la vue' })
|
||||
await user.click(within(list).getAllByRole('button')[0])
|
||||
await replace()
|
||||
await user.click(tab(/Vérification/))
|
||||
expect(tab(/Vérification/)).toHaveAttribute('aria-selected', 'true')
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
await user.click(tab('Annotations'))
|
||||
await replace()
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
|
||||
await user.click(tab(/Vérification/))
|
||||
expect(
|
||||
await screen.findByRole('dialog', {
|
||||
name: 'Abandonner le nouveau tracé ?',
|
||||
}),
|
||||
).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'Continuer' }))
|
||||
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
|
||||
expect(drawing.getByTestId('tracing-commands')).toBeVisible()
|
||||
})
|
||||
|
||||
it('a pending creation is kept and focused', async () => {
|
||||
|
||||
@@ -0,0 +1,676 @@
|
||||
/** U2 Task 5: vertices, « + », « − », zone move, redraw, paths and the handle cap. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
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 AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import { answerDrawing, guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import { useAnnotationWork, resetWork } from '@/editor/annotations/workStore'
|
||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, insert, point } 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(),
|
||||
}
|
||||
|
||||
function UndoKeys() {
|
||||
useUndoShortcuts(true)
|
||||
return null
|
||||
}
|
||||
|
||||
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 zone = (id: string, geometry: object): Annotation =>
|
||||
({
|
||||
...(point(id, 0, 0, 1).value as Annotation),
|
||||
kind: 'zone',
|
||||
geometry,
|
||||
}) as Annotation
|
||||
|
||||
const withZone = (text: string, id: string, geometry: object) =>
|
||||
insert(text, { kind: 'annotation', value: zone(id, geometry) })
|
||||
|
||||
const squareText = (points: Point[] = SQUARE) =>
|
||||
withZone(drawnText(), 'z', { type: 'polygon', points })
|
||||
|
||||
const tab = (readOnly = false) => (
|
||||
<div data-editor-workspace>
|
||||
<AnnotationsTab {...props} readOnly={readOnly} />
|
||||
</div>
|
||||
)
|
||||
|
||||
async function mount(text: string) {
|
||||
await openReady({ text })
|
||||
const view = render(tab())
|
||||
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])
|
||||
return screen.findByTestId('annotation-properties')
|
||||
}
|
||||
|
||||
const mouse = {
|
||||
pointerId: 1,
|
||||
isPrimary: true,
|
||||
button: 0,
|
||||
buttons: 1,
|
||||
pointerType: 'mouse',
|
||||
}
|
||||
/** The hit shape of a handle: the press machine reads its `data-handle`. */
|
||||
const hitOf = (name: string) =>
|
||||
screen.getByRole('button', { name }).querySelector('[data-handle]')!
|
||||
const vertex = (n: number) =>
|
||||
screen.getByRole('button', { name: `Sommet ${n}` })
|
||||
const plus = (n: number) =>
|
||||
screen.getByRole('button', { name: `Ajouter un sommet après le sommet ${n}` })
|
||||
const minus = (n: number) =>
|
||||
screen.getByRole('button', { name: `Retirer le sommet ${n}` })
|
||||
const clickHandle = (name: string, at: [number, number] = [0, 0]) =>
|
||||
pressAt(hitOf(name), at[0], at[1])
|
||||
const marker = (id: string) =>
|
||||
screen
|
||||
.getByTestId('annotation-canvas-drawing')
|
||||
.querySelector(`[data-anno-id="${id}"]`)!
|
||||
const detail = () => screen.getByTestId('edit-strip-detail')
|
||||
const message = () => screen.getByTestId('gesture-line')
|
||||
const chosen = () => useAnnotationWork.getState().chosen
|
||||
|
||||
function drag(el: Element, from: [number, number], to: [number, number]) {
|
||||
const [x0, y0] = from
|
||||
const [x1, y1] = to
|
||||
fireEvent.pointerDown(el, { ...mouse, clientX: x0, clientY: y0 })
|
||||
fireEvent.pointerMove(el, { ...mouse, clientX: x1, clientY: y1 })
|
||||
fireEvent.pointerUp(el, { ...mouse, buttons: 0, clientX: x1, clientY: y1 })
|
||||
}
|
||||
|
||||
describe('a vertex (R-9)', () => {
|
||||
it('a click chooses it, stamped; the strip says it; the interior unchooses it', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
expect(detail()).toHaveTextContent('Zone · 4 sommets')
|
||||
clickHandle('Sommet 2', [80, 20])
|
||||
expect(chosen()).toEqual({
|
||||
annotationId: 'z',
|
||||
vertex: 1,
|
||||
base: store.getState().documentText,
|
||||
})
|
||||
expect(detail()).toHaveTextContent('Zone · 4 sommets · sommet 2 choisi')
|
||||
expect(minus(2)).toBeInTheDocument()
|
||||
pressAt(marker('z'), 50, 50)
|
||||
expect(chosen()).toBeNull()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /^Retirer le sommet/ }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('a drag commits once; a release on a neighbour commits nothing', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
drag(hitOf('Sommet 2'), [80, 20], [90, 10])
|
||||
expect(pointsOf('z')![1]).toEqual([90, 10])
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(message()).toHaveTextContent('Sommet déplacé')
|
||||
drag(hitOf('Sommet 2'), [90, 10], [80, 80])
|
||||
expect(pointsOf('z')![1]).toEqual([90, 10])
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('« + » inserts at the midpoint and chooses the new vertex', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
clickHandle('Ajouter un sommet après le sommet 1', [50, 20])
|
||||
expect(pointsOf('z')).toEqual([[20, 20], [50, 20], ...SQUARE.slice(1)])
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(chosen()).toMatchObject({ vertex: 1 })
|
||||
expect(chosen()!.base).toBe(store.getState().documentText)
|
||||
expect(detail()).toHaveTextContent('sommet 2 choisi')
|
||||
expect(message()).toHaveTextContent('Sommet ajouté')
|
||||
})
|
||||
|
||||
it('undo after « + » drops the chosen vertex: « − » removes nothing stale (Review Focus 2)', async () => {
|
||||
await mount(squareText())
|
||||
render(<UndoKeys />)
|
||||
await select()
|
||||
clickHandle('Ajouter un sommet après le sommet 1', [50, 20])
|
||||
const bubble = hitOf('Retirer le sommet 2')
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(chosen()).toBeNull()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /^Retirer le sommet/ }),
|
||||
).toBeNull()
|
||||
const after = depth()
|
||||
pressAt(bubble, 50, 20)
|
||||
fireEvent.keyDown(vertex(2), { key: 'Delete' })
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(depth()).toBe(after)
|
||||
})
|
||||
|
||||
it('« − » removes the chosen vertex', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
clickHandle('Sommet 3', [80, 80])
|
||||
clickHandle('Retirer le sommet 3', [80, 70])
|
||||
expect(pointsOf('z')).toEqual([SQUARE[0], SQUARE[1], SQUARE[3]])
|
||||
expect(chosen()).toBeNull()
|
||||
expect(message()).toHaveTextContent('Sommet retiré')
|
||||
})
|
||||
|
||||
it('« − » is disabled at 3 with its reason; nothing is removed', async () => {
|
||||
const triangle = SQUARE.slice(0, 3)
|
||||
await mount(squareText(triangle))
|
||||
await select()
|
||||
const before = depth()
|
||||
clickHandle('Sommet 1', [20, 20])
|
||||
expect(minus(1)).toHaveAttribute('aria-disabled', 'true')
|
||||
clickHandle('Retirer le sommet 1', [20, 10])
|
||||
expect(pointsOf('z')).toEqual(triangle)
|
||||
expect(depth()).toBe(before)
|
||||
expect(message()).toHaveTextContent('Une zone garde au moins 3 sommets')
|
||||
})
|
||||
|
||||
it('keys: focus chooses, arrows preview, Enter commits; Insert adds, Delete removes', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
vertex(1).focus()
|
||||
expect(chosen()).toMatchObject({ vertex: 0 })
|
||||
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
|
||||
expect(pointsOf('z')![0]).toEqual([20, 20])
|
||||
fireEvent.keyDown(vertex(1), { key: 'Enter' })
|
||||
expect(pointsOf('z')![0]).toEqual([20.5, 20])
|
||||
expect(depth()).toBe(before + 1)
|
||||
fireEvent.keyDown(vertex(1), { key: 'Insert' })
|
||||
expect(pointsOf('z')).toHaveLength(5)
|
||||
expect(pointsOf('z')![1]).toEqual([50.25, 20])
|
||||
expect(chosen()).toMatchObject({ vertex: 1 })
|
||||
fireEvent.keyDown(vertex(2), { key: 'Delete' })
|
||||
expect(pointsOf('z')).toHaveLength(4)
|
||||
expect(depth()).toBe(before + 3)
|
||||
})
|
||||
|
||||
it('Enter on a « + » inserts; Tab walks the handles, « + » included', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const order = screen
|
||||
.getAllByRole('button')
|
||||
.filter((b) => b.closest('[data-testid="handle-layer"]'))
|
||||
.map((b) => b.getAttribute('aria-label'))
|
||||
expect(order).toContain('Ajouter un sommet après le sommet 4')
|
||||
expect(order).toContain('Sommet 4')
|
||||
fireEvent.keyDown(plus(4), { key: 'Enter' })
|
||||
expect(pointsOf('z')).toHaveLength(5)
|
||||
expect(pointsOf('z')![4]).toEqual([20, 50])
|
||||
})
|
||||
})
|
||||
|
||||
describe('a double click on a handle (R-8, carried Task 2 gap)', () => {
|
||||
const twice = (el: Element, x: number, y: number) => {
|
||||
pressAt(el, x, y)
|
||||
pressAt(el, x, y)
|
||||
}
|
||||
|
||||
it('on « + »: one insert, never a second', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
twice(hitOf('Ajouter un sommet après le sommet 1'), 50, 20)
|
||||
expect(pointsOf('z')).toHaveLength(5)
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('on a vertex: chosen once, the second click runs no handle action', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const spy = vi.spyOn(useAnnotationWork, 'setState')
|
||||
twice(hitOf('Sommet 2'), 80, 20)
|
||||
const choices = spy.mock.calls.filter(
|
||||
([patch]) => typeof patch === 'object' && 'chosen' in patch,
|
||||
)
|
||||
spy.mockRestore()
|
||||
expect(choices).toHaveLength(1)
|
||||
expect(chosen()).toMatchObject({ vertex: 1 })
|
||||
})
|
||||
|
||||
it('on « − »: one removal, never a second', async () => {
|
||||
await mount(squareText([...SQUARE, [10, 50]]))
|
||||
await select()
|
||||
clickHandle('Sommet 2', [80, 20])
|
||||
const before = depth()
|
||||
const bubble = hitOf('Retirer le sommet 2')
|
||||
pressAt(bubble, 80, 10)
|
||||
pressAt(bubble, 80, 10)
|
||||
expect(pointsOf('z')).toHaveLength(4)
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('moving the zone (A11, R-12)', () => {
|
||||
it('the interior dragged by mouse moves the zone once', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
drag(marker('z'), [50, 50], [60, 55])
|
||||
expect(pointsOf('z')![0]).toEqual([30, 25])
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(message()).toHaveTextContent('Zone déplacée')
|
||||
})
|
||||
|
||||
it('« Déplacer la zone » moves it whole; « Valider la position » commits once', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
const before = depth()
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Déplacer la zone' }))
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||
'Déplacer la zone',
|
||||
)
|
||||
const bar = screen.getByTestId('move-mode-bar')
|
||||
fireEvent.click(
|
||||
within(bar).getByRole('button', { name: 'Déplacer vers la droite' }),
|
||||
)
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
fireEvent.click(
|
||||
within(bar).getByRole('button', { name: 'Valider la position' }),
|
||||
)
|
||||
expect(pointsOf('z')).toEqual(SQUARE.map(([x, y]) => [x + 0.5, y]))
|
||||
expect(depth()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('« Déplacer le sommet » moves the chosen vertex only', async () => {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
clickHandle('Sommet 3', [80, 80])
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Déplacer le sommet' }))
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||
'Déplacer le sommet',
|
||||
)
|
||||
const bar = screen.getByTestId('move-mode-bar')
|
||||
fireEvent.click(
|
||||
within(bar).getByRole('button', { name: 'Déplacer vers le bas' }),
|
||||
)
|
||||
fireEvent.click(
|
||||
within(bar).getByRole('button', { name: 'Valider la position' }),
|
||||
)
|
||||
expect(pointsOf('z')).toEqual([SQUARE[0], SQUARE[1], [80, 80.5], SQUARE[3]])
|
||||
})
|
||||
})
|
||||
|
||||
describe('the handle cap (R-7, T18)', () => {
|
||||
const many = (n: number): Point[] =>
|
||||
Array.from({ length: n }, (_, i) => {
|
||||
const angle = (2 * Math.PI * i) / n
|
||||
return [
|
||||
Math.round((50 + 30 * Math.cos(angle)) * 100) / 100,
|
||||
Math.round((50 + 30 * Math.sin(angle)) * 100) / 100,
|
||||
]
|
||||
})
|
||||
|
||||
it('41 vertices: the outline, the cap message, no handle; move and redraw remain', async () => {
|
||||
await mount(squareText(many(41)))
|
||||
await select()
|
||||
expect(screen.queryByRole('button', { name: /^Sommet / })).toBeNull()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /^Ajouter un sommet après/ }),
|
||||
).toBeNull()
|
||||
expect(screen.getByTestId('overlay-selection')).toBeInTheDocument()
|
||||
expect(detail()).toHaveTextContent(
|
||||
'Zone · 41 sommets, trop pour les poignées',
|
||||
)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Déplacer la zone' }),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Redessiner' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('40 vertices still have their handles', async () => {
|
||||
await mount(squareText(many(40)))
|
||||
await select()
|
||||
expect(screen.getAllByRole('button', { name: /^Sommet / })).toHaveLength(40)
|
||||
})
|
||||
})
|
||||
|
||||
describe('paths (UX_TESTS « Paths »)', () => {
|
||||
const PATH = { type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' }
|
||||
const pathAndZone = () =>
|
||||
withZone(withZone(drawnText(), 'p', PATH), 'z', {
|
||||
type: 'polygon',
|
||||
points: [
|
||||
[55, 55],
|
||||
[90, 55],
|
||||
[90, 90],
|
||||
[55, 90],
|
||||
],
|
||||
})
|
||||
|
||||
it('show no handle and offer « Remplacer par un polygone »', async () => {
|
||||
await mount(pathAndZone())
|
||||
const panel = await select(0)
|
||||
expect(screen.queryByRole('button', { name: /^Sommet / })).toBeNull()
|
||||
expect(
|
||||
within(panel).getByRole('button', { name: 'Remplacer par un polygone' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keep their `d` byte-identical after gestures on a neighbour', async () => {
|
||||
await mount(pathAndZone())
|
||||
const before = JSON.stringify(annotationOf('p').geometry)
|
||||
await select(1)
|
||||
clickHandle('Ajouter un sommet après le sommet 1', [72.5, 55])
|
||||
clickHandle('Sommet 2', [72.5, 55])
|
||||
clickHandle('Retirer le sommet 2', [72.5, 45])
|
||||
drag(hitOf('Sommet 1'), [55, 55], [60, 60])
|
||||
drag(marker('z'), [80, 80], [85, 85])
|
||||
expect(depth()).toBe(4)
|
||||
expect(JSON.stringify(annotationOf('p').geometry)).toBe(before)
|
||||
})
|
||||
})
|
||||
|
||||
describe('redraw (R-12, board 06 C)', () => {
|
||||
const canvas = () => screen.getByTestId('annotation-canvas')
|
||||
const TRACE: [number, number][] = [
|
||||
[30, 30],
|
||||
[70, 30],
|
||||
[70, 70],
|
||||
[30, 70],
|
||||
]
|
||||
async function redrawing() {
|
||||
await mount(squareText())
|
||||
await select()
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Redessiner' }))
|
||||
}
|
||||
|
||||
it('keeps the old outline during the trace, no handle; a close commits once and keeps every property', async () => {
|
||||
await redrawing()
|
||||
const kept = { ...annotationOf('z'), geometry: null }
|
||||
expect(useAnnotationWork.getState().mode).toMatchObject({
|
||||
kind: 'redraw',
|
||||
started: false,
|
||||
})
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||
'Redessiner · N',
|
||||
)
|
||||
expect(screen.queryByRole('button', { name: /^Sommet / })).toBeNull()
|
||||
const before = depth()
|
||||
TRACE.forEach(([x, y]) => pressAt(canvas(), x, y))
|
||||
expect(screen.getByTestId('overlay-old-place')).toBeInTheDocument()
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Fermer le tracé' }))
|
||||
expect(pointsOf('z')).toEqual(TRACE)
|
||||
expect({ ...annotationOf('z'), geometry: null }).toEqual(kept)
|
||||
expect(depth()).toBe(before + 1)
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(message()).toHaveTextContent('Zone redessinée')
|
||||
expect(
|
||||
screen.queryByText('Nouveau tracé abandonné : la fiche a changé.'),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('a click within 12 px of the first vertex closes it (R-11)', async () => {
|
||||
await redrawing()
|
||||
TRACE.slice(0, 3).forEach(([x, y]) => pressAt(canvas(), x, y))
|
||||
pressAt(canvas(), 38, 30)
|
||||
expect(pointsOf('z')).toEqual(TRACE.slice(0, 3))
|
||||
})
|
||||
|
||||
it('a refusal (too small to touch) keeps the trace open with the core message', async () => {
|
||||
await redrawing()
|
||||
const sliver: [number, number][] = [
|
||||
[20, 50],
|
||||
[80, 50],
|
||||
[80, 50.5],
|
||||
]
|
||||
sliver.forEach(([x, y]) => pressAt(canvas(), x, y))
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Fermer le tracé' }))
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Fermer le tracé' }),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.getByTestId('edit-strip-notice')).toHaveTextContent(
|
||||
/too small/,
|
||||
)
|
||||
expect(screen.getByTestId('edit-strip-title')).toHaveTextContent(
|
||||
'Fermeture refusée',
|
||||
)
|
||||
expect(useAnnotationWork.getState().mode).toMatchObject({
|
||||
kind: 'redraw',
|
||||
started: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('Escape and « Annuler le tracé » cancel at once and keep the old shape', async () => {
|
||||
await redrawing()
|
||||
pressAt(canvas(), 30, 30)
|
||||
fireEvent.keyDown(document.body, { key: 'Escape' })
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: 'Fermer le tracé' })).toBeNull()
|
||||
expect(useAnnotationWork.getState().question).toBeNull()
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Redessiner' }))
|
||||
pressAt(canvas(), 30, 30)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Annuler le tracé' }))
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
})
|
||||
|
||||
it('removing the last vertex back to none makes it unstarted again', async () => {
|
||||
await redrawing()
|
||||
pressAt(canvas(), 30, 30)
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(true)
|
||||
fireEvent.click(
|
||||
screen.getByRole('button', { name: 'Retirer le dernier sommet' }),
|
||||
)
|
||||
expect(useAnnotationWork.getState().mode?.started).toBe(false)
|
||||
})
|
||||
|
||||
it('the guard: Back before the first vertex ends it at once; after one, it asks', async () => {
|
||||
await redrawing()
|
||||
const back = vi.fn()
|
||||
let allowed = false
|
||||
act(() => void (allowed = guardDrawing(back)))
|
||||
expect(allowed).toBe(true)
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: 'Fermer le tracé' })).toBeNull()
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Redessiner' }))
|
||||
pressAt(canvas(), 30, 30)
|
||||
act(() => void (allowed = guardDrawing(back)))
|
||||
expect(allowed).toBe(false)
|
||||
expect(useAnnotationWork.getState().question?.work).toBe('redraw')
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Fermer le tracé' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a tool asks first once a vertex is placed; « Abandonner » ends the trace', async () => {
|
||||
await redrawing()
|
||||
pressAt(canvas(), 30, 30)
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Point' }))
|
||||
expect(useAnnotationWork.getState().question?.work).toBe('redraw')
|
||||
act(() => answerDrawing(true))
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: 'Fermer le tracé' })).toBeNull()
|
||||
expect(pointsOf('z')).toEqual(SQUARE)
|
||||
})
|
||||
|
||||
it('a document change made elsewhere drops a started redraw and says so (R-13)', async () => {
|
||||
await redrawing()
|
||||
pressAt(canvas(), 30, 30)
|
||||
act(
|
||||
() =>
|
||||
void store.getState().commit({
|
||||
op: 'update',
|
||||
key: { kind: 'annotation', id: 'z' },
|
||||
element: {
|
||||
kind: 'annotation',
|
||||
value: zone('z', { type: 'polygon', points: TRACE }),
|
||||
},
|
||||
}),
|
||||
)
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(
|
||||
await screen.findByText('Nouveau tracé abandonné : la fiche a changé.'),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Fermer le tracé' })).toBeNull()
|
||||
})
|
||||
|
||||
it('« Remplacer par un polygone » on a path is the same redraw', async () => {
|
||||
await mount(
|
||||
withZone(drawnText(), 'p', {
|
||||
type: 'path',
|
||||
d: 'M 20 20 L 80 20 L 50 80 Z',
|
||||
}),
|
||||
)
|
||||
const panel = await select()
|
||||
await userEvent.setup().click(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
expect(useAnnotationWork.getState().mode).toMatchObject({ kind: 'redraw' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('the zoom hint for short segments (R-18, D2)', () => {
|
||||
const SHORT: Point[] = [
|
||||
[20, 20],
|
||||
[35, 20],
|
||||
[80, 20],
|
||||
[80, 80],
|
||||
[20, 80],
|
||||
]
|
||||
const zoomHint = 'Zoomez pour ajouter un sommet sur les segments courts.'
|
||||
beforeEach(() => {
|
||||
// One CSS px per drawing unit at fit: the 100-unit frame in a 100 px box.
|
||||
for (const side of ['clientWidth', 'clientHeight'])
|
||||
Object.defineProperty(window.SVGSVGElement.prototype, side, {
|
||||
configurable: true,
|
||||
get: () => 100,
|
||||
})
|
||||
})
|
||||
afterEach(() => {
|
||||
for (const side of ['clientWidth', 'clientHeight'])
|
||||
delete (
|
||||
window.SVGSVGElement.prototype as unknown as Record<string, unknown>
|
||||
)[side]
|
||||
})
|
||||
|
||||
it('a hidden « + » shows the line; zooming until every « + » shows removes it', async () => {
|
||||
await mount(squareText(SHORT))
|
||||
await select()
|
||||
expect(
|
||||
screen.queryByRole('button', {
|
||||
name: 'Ajouter un sommet après le sommet 1',
|
||||
}),
|
||||
).toBeNull()
|
||||
expect(plus(2)).toBeInTheDocument()
|
||||
expect(screen.getByTestId('edit-strip-notice')).toHaveTextContent(zoomHint)
|
||||
const zoomIn = screen.getByRole('button', { name: 'Zoom avant' })
|
||||
fireEvent.click(zoomIn)
|
||||
fireEvent.click(zoomIn)
|
||||
await waitFor(() => expect(plus(1)).toBeInTheDocument())
|
||||
expect(screen.getByTestId('edit-strip-notice')).not.toHaveTextContent(
|
||||
zoomHint,
|
||||
)
|
||||
})
|
||||
|
||||
it('a refusal takes its place while shown', async () => {
|
||||
await mount(squareText(SHORT))
|
||||
await select()
|
||||
drag(hitOf('Sommet 3'), [80, 20], [500, 20])
|
||||
const notice = screen.getByTestId('edit-strip-notice')
|
||||
expect(notice).toHaveTextContent('Déplacement refusé')
|
||||
expect(notice).not.toHaveTextContent(zoomHint)
|
||||
})
|
||||
|
||||
it('is absent in a redraw', async () => {
|
||||
await mount(squareText(SHORT))
|
||||
await select()
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(screen.getByRole('button', { name: 'Redessiner' }))
|
||||
expect(screen.getByTestId('edit-strip-notice')).not.toHaveTextContent(
|
||||
zoomHint,
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -32,8 +32,10 @@ import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDial
|
||||
import { guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import {
|
||||
resetWork,
|
||||
markRedraw,
|
||||
setModePreview,
|
||||
startMove,
|
||||
startRedraw,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
|
||||
@@ -341,6 +343,21 @@ describe('AppLayout and a started move on the drawing (R-12)', () => {
|
||||
expect(screen.queryByText('account page')).toBeNull()
|
||||
})
|
||||
|
||||
it('a started redraw asks « Abandonner le nouveau tracé ? » before a link', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
startRedraw('a', 'doc')
|
||||
markRedraw(true)
|
||||
await user.click(account())
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Abandonner le nouveau tracé ?' }),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.queryByText('account page')).toBeNull()
|
||||
await user.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(await screen.findByText('account page')).toBeInTheDocument()
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
})
|
||||
|
||||
it('a move with nothing started leaves at once and ends', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
|
||||
Reference in new issue
Block a user