fix(app): annotations tab split, editor-wide undo keys, keyboard point fits, typed radius message
This commit is contained in:
1 parent
447d0a4272
commit
3f15762d95
25 files changed
+1398
-653
No files matched your search
@@ -1,6 +1,7 @@
|
||||
/** Lot H: the Annotations tab (creation, corrected position, gestures, read-only, repair). */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
@@ -22,6 +23,7 @@ import {
|
||||
import {
|
||||
USER,
|
||||
VERSION,
|
||||
commitMove,
|
||||
openReady,
|
||||
resetStore,
|
||||
sb,
|
||||
@@ -693,13 +695,11 @@ describe('polygons and paths', () => {
|
||||
})
|
||||
const panel = await selectFromList()
|
||||
expect(within(panel).queryByText(/M 20 20/)).toBeNull()
|
||||
await userEvent
|
||||
.setup()
|
||||
.click(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
await userEvent.setup().click(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
const canvas = screen.getByTestId('annotation-canvas')
|
||||
triangle.forEach(([x, y]) =>
|
||||
fireEvent.click(canvas, { clientX: x, clientY: y }),
|
||||
@@ -714,25 +714,232 @@ describe('polygons and paths', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('keyboard shortcuts', () => {
|
||||
it('undoes with Ctrl+Z outside a text field and not inside one', async () => {
|
||||
await mount()
|
||||
await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
const cx = within(
|
||||
screen.getByTestId('annotation-properties'),
|
||||
).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '60{Enter}')
|
||||
fireEvent.keyDown(cx, { key: 'z', ctrlKey: true })
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 50 })
|
||||
fireEvent.keyDown(document.body, {
|
||||
key: 'z',
|
||||
ctrlKey: true,
|
||||
shiftKey: true,
|
||||
describe('keys while tracing (H3)', () => {
|
||||
const clickAt = (x: number, y: number) =>
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
})
|
||||
expect(geometryOf('anno-a')).toMatchObject({ cx: 60 })
|
||||
|
||||
async function traced() {
|
||||
await mount({ text: drawnText() })
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
triangle.forEach(([x, y]) => clickAt(x, y))
|
||||
return user
|
||||
}
|
||||
|
||||
it('Enter on « Annuler le tracé » cancels the tracing instead of closing it', async () => {
|
||||
const user = await traced()
|
||||
screen.getByRole('button', { name: 'Annuler le tracé' }).focus()
|
||||
await user.keyboard('{Enter}')
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Annuler le tracé' }),
|
||||
).toBeNull()
|
||||
expect(screen.queryByTestId('annotation-creation')).toBeNull()
|
||||
})
|
||||
|
||||
it('Enter on a view chip or a list row never closes the tracing', async () => {
|
||||
await traced()
|
||||
const views = screen.getByRole('group', { name: 'Vues' })
|
||||
fireEvent.keyDown(within(views).getAllByRole('button')[0], {
|
||||
key: 'Enter',
|
||||
})
|
||||
expect(screen.queryByTestId('annotation-creation')).toBeNull()
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Annuler le tracé' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('a second click with the point tool (H6)', () => {
|
||||
it('moves the pending point and keeps what was typed', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'Point' })).toBeEnabled(),
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 50,
|
||||
clientY: 50,
|
||||
})
|
||||
const panel = await fillCreation(user)
|
||||
fireEvent.click(screen.getByTestId('annotation-canvas'), {
|
||||
clientX: 60,
|
||||
clientY: 40,
|
||||
})
|
||||
await waitFor(() =>
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('60'),
|
||||
)
|
||||
expect(within(panel).getByLabelText('Nom (FR)')).toHaveValue('Nuque')
|
||||
expect(within(panel).getByLabelText('Latéralité')).toHaveValue('unpaired')
|
||||
expect(screen.getByTestId('annotation-creation')).toBe(panel)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a typed radius (H5)', () => {
|
||||
it('shows the core issue, not a corrected position', async () => {
|
||||
const drawing = svgBytes('0 0 5000 5000')
|
||||
sb.getSheetVersion.mockResolvedValue({
|
||||
...versionAnswer(drawnText(), 3),
|
||||
drawings: [{ asset_id: ASSET, sha256: drawing.sha256 }],
|
||||
} as never)
|
||||
sb.downloadSheetDrawing.mockResolvedValue(drawing.bytes)
|
||||
store.getState().open(VERSION, USER, { canEdit: true })
|
||||
await waitFor(() => expect(store.getState().status).toBe('ready'))
|
||||
render(<AnnotationsTab {...props} />)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter un point' }),
|
||||
).toBeEnabled(),
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await fillCreation(user)
|
||||
const r = within(panel).getByLabelText('Rayon')
|
||||
await user.clear(r)
|
||||
await user.type(r, '1{Enter}')
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
expect(screen.queryByTestId('correction-notice')).toBeNull()
|
||||
expect(within(panel).getByRole('alert')).toBeInTheDocument()
|
||||
expect(annotations()).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the frame follows the view (H7)', () => {
|
||||
it('holds the keyboard point at the centre of the view shown, after a switch', async () => {
|
||||
const withView = 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: 20, width: 40, height: 60 },
|
||||
parent_view_id: 'view-main',
|
||||
},
|
||||
})
|
||||
await mount({ text: withView })
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Tête' }))
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter un point' }),
|
||||
).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('30')
|
||||
expect(within(panel).getByLabelText('Centre y')).toHaveValue('50')
|
||||
})
|
||||
})
|
||||
|
||||
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 () => {
|
||||
const path = { type: 'path', d: 'M 20 20 L 80 20 L 50 80 Z' }
|
||||
await mount({ text: zoneText(path) })
|
||||
const panel = await selectFromList()
|
||||
await userEvent.setup().click(
|
||||
within(panel).getByRole('button', {
|
||||
name: 'Remplacer par un polygone',
|
||||
}),
|
||||
)
|
||||
const canvas = screen.getByTestId('annotation-canvas')
|
||||
;[
|
||||
[20, 20],
|
||||
[500, 20],
|
||||
[50, 80],
|
||||
].forEach(([x, y]) => fireEvent.click(canvas, { clientX: x, clientY: y }))
|
||||
fireEvent.keyDown(canvas, { key: 'Enter' })
|
||||
expect(await screen.findByRole('alert')).toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Annuler le tracé' }),
|
||||
).toBeNull()
|
||||
expect(geometryOf('zone-a')).toEqual(path)
|
||||
})
|
||||
|
||||
it('a refused vertex add and a refused remove stay « non appliqué », document unchanged', async () => {
|
||||
await mount({
|
||||
text: zoneText({ type: 'polygon', points: [...triangle, [20, 60]] }),
|
||||
})
|
||||
const panel = await selectFromList()
|
||||
const user = userEvent.setup()
|
||||
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' }),
|
||||
)
|
||||
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()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the drag and the canvas follow the handle (H8)', () => {
|
||||
const down = (el: Element, x: number, y: number) =>
|
||||
fireEvent.pointerDown(el, {
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
button: 0,
|
||||
pointerId: 1,
|
||||
})
|
||||
|
||||
it('lostpointercapture drops the drag with no command', async () => {
|
||||
await mount()
|
||||
await selectFromList()
|
||||
const hit = marker('anno-a')
|
||||
const version = store.getState().handleVersion
|
||||
down(hit, 50, 50)
|
||||
fireEvent.pointerMove(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
fireEvent.lostPointerCapture(hit, { pointerId: 1 })
|
||||
fireEvent.pointerUp(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
expect(store.getState().handleVersion).toBe(version)
|
||||
})
|
||||
|
||||
it('a switch to read-only mid-drag drops it', async () => {
|
||||
await openReady({ text: text() })
|
||||
const view = render(<AnnotationsTab {...props} />)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('annotation-canvas-drawing').querySelector('svg'),
|
||||
).not.toBeNull(),
|
||||
)
|
||||
await selectFromList()
|
||||
const hit = marker('anno-a')
|
||||
const version = store.getState().handleVersion
|
||||
down(hit, 50, 50)
|
||||
fireEvent.pointerMove(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
view.rerender(<AnnotationsTab {...props} readOnly />)
|
||||
fireEvent.pointerUp(hit, { clientX: 70, clientY: 50, pointerId: 1 })
|
||||
expect(store.getState().handleVersion).toBe(version)
|
||||
expect(geometryOf('anno-a')).toEqual({
|
||||
type: 'circle',
|
||||
cx: 50,
|
||||
cy: 50,
|
||||
r: 5,
|
||||
})
|
||||
})
|
||||
|
||||
it('rebuilds the drawing when the handle changes under it', async () => {
|
||||
await mount()
|
||||
const first = marker('anno-a')
|
||||
act(() => void commitMove(60))
|
||||
await waitFor(() => expect(marker('anno-a')).not.toBe(first))
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user