fix(editor): slider while replacing, announced drop, review minors

Task 7 fix round 1 (review task-7-review.md).
- Important 1: « Taille » shows beside « Revenir aux propriétés » while
  a point is replaced (still hidden under the modal dialog); it feeds
  the hover preview and the re-placed point (R-10).
- Important 2: a creation whose view leaves the document is dropped
  and said, « Création abandonnée : la fiche a changé. » (dropped:
  'creation', read by useDroppedNotice).
- Minor 3: DrawingGuardDialog leaves a creation question to the
  creation dialog only while that dialog is really on screen
  (creationShown, set by the dialog).
- Minor 7: the dialog's long className strings split into constants.
- Minor 8: dead TOOL_OF removed; trace_start is a redraw's only.

Tests added (no assertion removed): slider while replacing (unit,
RED then GREEN; e2e under expectNoShift at three widths, last strip
command inside the strip); view removed during a creation (RED then
GREEN); question shown by the workspace when the dialog is not on
screen (RED then GREEN); « Abandonner » while read-only; R-13 with a
restored copy during a started move; leaving the route resets the
work (fails with the session reset removed). The unit Back test's
comment is corrected: it does pin the modal branch.
This commit is contained in:
bchanot committed 2026-11-18 00:06:16 +01:00
1 parent fe333c2bbd
commit 837ec9f436
14 files changed
+315 -29

No files matched your search

@@ -12,7 +12,11 @@ import {
import userEvent from '@testing-library/user-event'
import HistoryButtons from '@/components/editor/HistoryButtons'
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
import { useAnnotationWork } from '@/editor/annotations/workStore'
import { resetWork, useAnnotationWork } from '@/editor/annotations/workStore'
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
import { emptyForm } from '@/editor/annotations/creation'
import { placePending } from '@/editor/annotations/creationWork'
import { guardDrawing } from '@/editor/annotations/drawingGuard'
import { useLocaleStore } from '@/state/localeStore'
import { drawnText, insert, point } from '../helpers/editorFixtures'
import { LayeredTab } from '../helpers/annotationLayer'
@@ -426,3 +430,109 @@ describe('the mode flip (R-14, Review Focus 3)', () => {
expect(annotations()).toHaveLength(1)
})
})
describe('fix round 1: the size while a point is replaced (board 02, R-10)', () => {
const sized = () =>
[
point('a', 20, 20, 7),
point('b', 40, 40, 7),
point('c', 60, 60, 9),
].reduce((text, p) => insert(text, p), drawnText())
const slider = () =>
within(screen.getByTestId('size-slider')).getByRole('slider')
it('hidden under the dialog, shown beside « Revenir aux propriétés »; it sizes the re-placed point', async () => {
const user = await mount(sized())
const shown = await placePoint(user)
const strip = screen.getByTestId('edit-strip')
// The modal makes the strip inert: no slider while the dialog shows.
expect(within(strip).queryByTestId('size-slider')).toBeNull()
await user.click(
within(shown).getByRole('button', { name: 'Replacer le point' }),
)
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(
within(strip).getByRole('button', { name: 'Revenir aux propriétés' }),
).toBeInTheDocument()
expect(slider()).toHaveValue('7')
fireEvent.change(slider(), { target: { value: '9' } })
fireEvent.pointerMove(canvas(), {
clientX: 30,
clientY: 70,
pointerType: 'mouse',
})
expect(
screen.getByTestId('overlay-point-preview').querySelector('circle'),
).toHaveAttribute('r', '9')
pressAt(canvas(), 30, 70)
await dialog()
expect(ghost().querySelector('circle')).toHaveAttribute('r', '9')
})
})
describe('fix round 1: a creation whose view leaves the document (no silent loss)', () => {
it('a document change removes the view: the creation goes and the line says so', async () => {
const user = await mount(withDetail())
await user.click(screen.getByRole('button', { name: 'Tête' }))
await waitFor(() =>
expect(
screen.getByRole('button', { name: 'Ajouter une zone' }),
).toBeEnabled(),
)
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
const shown = await dialog('Nouvelle zone')
await user.type(within(shown).getByLabelText('Nom (FR)'), 'Perdue')
act(
() =>
void store
.getState()
.commit({ op: 'remove', key: { kind: 'view', id: 'view-det' } }),
)
await waitFor(() => expect(creation()).toBeNull())
expect(
await screen.findByText('Création abandonnée : la fiche a changé.'),
).toBeInTheDocument()
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
})
})
describe('fix round 1: the question is never hidden behind a dialog not shown', () => {
afterEach(() => act(() => resetWork()))
it('a creation whose dialog is not on screen (its place hidden): the workspace asks', () => {
render(<DrawingGuardDialog />)
act(() =>
placePending(
{
viewId: 'view-main',
frame: null,
origin: 'tool',
form: emptyForm(JSON.parse(drawnText())),
},
{ kind: 'point', geometry: { type: 'circle', cx: 5, cy: 5, r: 2 } },
),
)
act(() => void guardDrawing(() => undefined))
expect(
screen.getByRole('dialog', { name: 'Abandonner la création ?' }),
).toBeInTheDocument()
})
})
describe('fix round 1: « Abandonner » while read-only (R-14)', () => {
it('asks, then drops the creation', async () => {
const user = await mount()
await placePoint(user)
view.rerender(<Page readOnly />)
const kept = screen.getByRole('dialog', { name: 'Nouveau point' })
await user.click(within(kept).getByRole('button', { name: 'Abandonner' }))
expect(creation()).not.toBeNull()
const ask = within(kept).getByRole('group', {
name: 'Abandonner la création ?',
})
await user.click(within(ask).getByRole('button', { name: 'Abandonner' }))
expect(creation()).toBeNull()
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
expect(annotations()).toHaveLength(1)
})
})
@@ -628,9 +628,8 @@ describe('the drawing guard at every site: creation, move, redraw', () => {
/**
* U2 Task 7: the creation dialog is a modal without a history layer. A Back while it is
* open is refused, and its « Abandonner la création ? » shows inside it. (Under happy-dom
* the refusal is reached through the drawing guard; the browser's modal branch is proved
* by the e2e in editor-annotations.spec.ts.)
* open is refused as a modal (the real `dialog[open]` of happy-dom), and its « Abandonner la
* création ? » shows inside it: without the modal branch's guard call this test fails.
*/
describe('a Back on the creation dialog', () => {
afterEach(() => act(() => resetWork()))
@@ -18,6 +18,8 @@ import { FocusConsumedContext } from '@/editor/focusRequest'
import { targetOfKey } from '@/editor/navigation'
import { useLocaleStore } from '@/state/localeStore'
import { useAnnotationWork } from '@/editor/annotations/workStore'
import { emptyForm } from '@/editor/annotations/creation'
import { traceVertex } from '@/editor/annotations/creationWork'
import { cleanSvg } from '@/editor/core/cleaning'
import {
ASSET,
@@ -575,3 +577,40 @@ describe('a tab while a creation or a tracing is in progress', () => {
expect(within(back).getByLabelText('Nom (FR)')).toHaveValue('Nuque')
})
})
/**
* Fix round 1 (review ⚠️): a shell link with nothing at stake is not intercepted, so the
* route's own cleanup must end the drawing's work. The route closes the store session on
* unmount (`AdminSheetDraftRoute`), and a session change resets the work store.
*/
describe('leaving the editor route resets the drawing work', () => {
// A mode on no selection is ended by the body itself (`useModeFollowsSelection`), so the
// work held here is a creation; the reset is the same `resetWork` for a mode.
it('a creation is gone once the route unmounts, its question too', async () => {
serverHas(baseText(), 3)
const view = mountDraft()
await ready()
const base = store.getState().documentText
const viewId = JSON.parse(base).views[0].id as string
act(() => {
traceVertex(
{
viewId,
frame: null,
origin: 'tool',
form: emptyForm({ categories: [] } as never),
},
'zone',
[1, 1],
)
})
expect(useAnnotationWork.getState().creation).not.toBeNull()
view.unmount()
expect(useAnnotationWork.getState()).toMatchObject({
mode: null,
preview: null,
creation: null,
question: null,
})
})
})
@@ -397,6 +397,53 @@ describe('the move mode (A11, R-12, R-13)', () => {
})
})
describe('fix round 1: a recovery during a started move (R-13)', () => {
const two = () => withPoints(point('a', 50, 50, 5), point('b', 20, 20, 5))
it('a restored copy replaces the document: the mode is dropped and said', async () => {
await mount(two())
await select()
await userEvent.setup().click(moveButton())
fireEvent.click(arrow('la droite'))
expect(useAnnotationWork.getState().mode?.started).toBe(true)
const { savedRevision, drawings } = store.getState()
const copy = {
v: 1 as const,
user_id: USER,
version_id: VERSION,
sheet_id: 'sheet-1',
sheet_name: 'Fiche',
revision: savedRevision,
written_at: '2026-11-03T10:00:00Z',
document: JSON.parse(
withPoints(point('a', 30, 30, 5), point('b', 20, 20, 5)),
),
drawings: drawings.map((d) => ({
asset_id: d.asset_id,
sha256: d.sha256,
})),
}
act(() =>
store.setState({
recovery: 'pending',
offer: {
revision: savedRevision,
writtenAt: copy.written_at,
sheetName: 'Fiche',
serverRevision: savedRevision,
copy,
},
}),
)
await act(async () => {
expect(await store.getState().restoreCopy()).toEqual({ ok: true })
})
expect(useAnnotationWork.getState().mode).toBeNull()
expect(
await screen.findByText('Déplacement abandonné : la fiche a changé.'),
).toBeInTheDocument()
})
})
describe('the point handle (R-9, R-11)', () => {
it('is a focusable button outside any aria-hidden subtree, named « Point {nom} »', async () => {
await mount(withPoints(point('a', 50, 50, 5)))