feat(editor): creation on the drawing then the creation dialog

U2 Task 7 (A2, A4, A5, A7, A12, A15; R-3, R-4, R-12, R-13, R-14).
The work store's `creation` owns the new shape, its form, its view and
F: a click with the point tool, a closed tracing or a keyboard
« Ajouter … » opens « Nouveau point / zone / accès », a modal without
a history layer over the right column, mounted beside EditOnly so a
read-only flip keeps it (« Créer », « Replacer », « Reprendre » off).
A new zone or link is a creation from its first vertex. The ghost
takes the form's category colour; the point tool previews under a
mouse; the canvas carries data-creating (other markers dimmed,
unselectable). « Replacer le point » / « Reprendre le tracé » hide the
dialog and keep the form; the strip offers « Revenir aux propriétés »,
« Retirer le dernier sommet », « Abandonner ». « Créer »: one insert,
tool back to « Sélectionner », the new element selected, « Point
créé · Défaire », focus on its row. ✕, Échap, « Abandonner » and Back
always ask « Abandonner la création ? » (DiscardConfirm inside the
dialog; DrawingGuardDialog elsewhere); answerDrawing drops the
creation. Undo, its shortcuts and the line's « Défaire » are inactive
during a creation. missingFields replaces formProblem (MissingSummary
shared with the edit form); the C26 notice has no numbers.
CreationPanel, formProblem, withGeometry and the keys required.fields,
required.names and create_cancel are gone; GeometryGroup is imported
by RepairDialog only.

Removed or rewritten assertions:
- tab « holds a point at the frame centre »: « Centre x » = 50 ->
  the ghost circle cx = 50; plus tool back to Sélectionner, « Point
  créé », one undo step.
- tab « refuses a creation without laterality »: the general line
  « Choisissez la catégorie et la latéralité » -> only « Choisissez
  une latéralité. » and « À compléter : Latéralité. », focus on it.
- tab « applies the geometry group to a pending zone »: removed (A8,
  no coordinate field) -> « places a triangle at the centre: the ghost
  shows it, Créer inserts it »; vertex edits after Créer are the e2e
  keyboard test.
- tab C26 « proposes C »: « x = 15, y = 15 » in the notice -> the R-4
  text, the notice inside the dialog; cancel test « Centre x » = 0 ->
  ghost cx = 0.
- tab « offers the correction when the core refuses a pending point »
  (typed cx 98): removed, no typed coordinate is possible; the verdict
  path stays covered by the C26 click tests and correctionFor units.
- tab H5 « a typed radius shows the core issue »: removed (A8); the
  size refusal is the slider's (Task 4 tests).
- tab H6 « a second click moves the pending point »: -> « Replacer le
  point », then the click moves the ghost, the form kept.
- tab H7 « Centre x/y » = 30/50 -> ghost cx/cy.
- tab tracing Enter: « x du sommet 3 » -> ghost points; « drops the
  tracing on Escape » -> Escape asks first (board 32 row 3), Continuer
  keeps, Abandonner drops; new « Annuler le tracé acts at once ».
- keep-alive « a pending creation is kept and focused » and « a
  tracing … is kept and focused »: the tab now asks first (R-12) ->
  « Continuer » keeps the tracing / the form, « Abandonner » goes.
- sections « its panel takes the focus » -> its dialog's
  [data-creation-focus] takes it.
- no-loss « pending creation with its name » (hidden with the body) ->
  the dialog stays across the crossing, read-only, Créer off (R-14).
- point-edit A5 « Rayon » = 7 / 9 -> ghost r = 7 / 9.
- e2e editor-annotations keyboard test « numeric position » (cx field
  250) -> UX_TESTS Keyboard: zone added, vertex added and removed,
  moved by the move mode, validated, saved. The « Fermer le tracé »
  step runs under expectNoShift again (shortcut removed).
- e2e editor-geometry C26: the proposed x, y read from the notice
  text -> from the overlay's correction circle; the R-4 text checked
  in the dialog.
- e2e editor-deselect « Escape cancels the tracing only » -> Escape
  asks, « Abandonner » cancels it, the selection kept.
- e2e editor-shell-crossing « keeps its tool and its pending
  creation » (field hidden) -> the dialog stays read-only, Créer off,
  then editable on widening.
This commit is contained in:
bchanot committed 2026-11-17 23:32:42 +01:00
1 parent 2d58da7d01
commit 4d2c64f57f
50 files changed
+3050 -1181

No files matched your search

@@ -0,0 +1,314 @@
/** U2 Task 7: creation on the drawing, then the creation dialog (A2, A4, A5, A7, A12, A15). */
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 HistoryButtons from '@/components/editor/HistoryButtons'
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
import { useAnnotationWork } from '@/editor/annotations/workStore'
import { useLocaleStore } from '@/state/localeStore'
import { drawnText, insert, point } from '../helpers/editorFixtures'
import { LayeredTab } from '../helpers/annotationLayer'
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(),
}
/** Screen = drawing: the overlay's inverse CTM is the identity in the page under test. */
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()
})
/** A second category, coloured, so the ghost's colour can follow the form (A4). */
function twoCategories(): string {
return insert(insert(drawnText(), point('anno-a', 20, 20, 5)), {
kind: 'category',
value: { id: 'cat-b', name: { fr: 'Os', en: 'Bone' }, color: '#aa3366' },
} as never)
}
/** The tab with the header's history controls, as the workspace shows them. */
function Page() {
useUndoShortcuts(true)
return (
<>
<HistoryButtons />
<LayeredTab {...props} />
</>
)
}
async function mount(text = twoCategories()) {
await openReady({ text })
render(<Page />)
await waitFor(() =>
expect(screen.getByRole('button', { name: 'Point' })).toBeEnabled(),
)
return userEvent.setup()
}
const canvas = () => screen.getByTestId('annotation-canvas')
const ghost = () => screen.getByTestId('overlay-ghost')
const creation = () => useAnnotationWork.getState().creation
const annotations = () => store.getState().previewState!.document.annotations
const dialog = (name = 'Nouveau point') => screen.findByRole('dialog', { name })
async function placePoint(user: ReturnType<typeof userEvent.setup>) {
await user.click(screen.getByRole('button', { name: 'Point' }))
pressAt(canvas(), 50, 50)
return dialog()
}
describe('the creation dialog asks before leaving, always (A12)', () => {
it('✕ with nothing typed asks; « Continuer » keeps the shape', async () => {
const user = await mount()
const shown = await placePoint(user)
await user.click(within(shown).getByRole('button', { name: 'Fermer' }))
const ask = within(shown).getByRole('group', {
name: 'Abandonner la création ?',
})
await user.click(within(ask).getByRole('button', { name: 'Continuer' }))
expect(screen.getByRole('dialog', { name: 'Nouveau point' })).toBe(shown)
expect(creation()).not.toBeNull()
expect(ghost()).toBeInTheDocument()
})
it('Échap with nothing typed asks inside the dialog, never the workspace question', async () => {
const user = await mount()
const shown = await placePoint(user)
await user.keyboard('{Escape}')
expect(
within(shown).getByRole('group', { name: 'Abandonner la création ?' }),
).toBeInTheDocument()
expect(screen.getAllByRole('dialog')).toHaveLength(1)
})
it('« Abandonner » asks, then clears the creation; the focus goes to the tool', async () => {
const user = await mount()
const shown = await placePoint(user)
await user.click(within(shown).getByRole('button', { name: 'Abandonner' }))
expect(creation()).not.toBeNull()
const ask = within(shown).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(screen.queryByTestId('overlay-ghost')).toBeNull()
await waitFor(() =>
expect(screen.getByRole('button', { name: 'Point' })).toHaveFocus(),
)
expect(annotations()).toHaveLength(1)
})
it('a keyboard creation abandoned gives the focus back to its « Ajouter … » button', async () => {
const user = await mount()
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
const shown = await dialog('Nouvelle zone')
await user.click(within(shown).getByRole('button', { name: 'Abandonner' }))
await user.click(
within(
within(shown).getByRole('group', { name: 'Abandonner la création ?' }),
).getByRole('button', { name: 'Abandonner' }),
)
await waitFor(() =>
expect(
screen.getByRole('button', { name: 'Ajouter une zone' }),
).toHaveFocus(),
)
})
})
describe('placing and the form (A4, A5)', () => {
it('the category prefilled, the laterality without default; a category recolours the ghost', async () => {
const user = await mount()
const shown = await placePoint(user)
expect(within(shown).getByLabelText('Catégorie')).toHaveValue('cat-a')
expect(within(shown).getByLabelText('Latéralité')).toHaveValue('')
expect(within(shown).queryByLabelText('Couleur')).toBeNull()
expect(ghost()).toHaveAttribute('data-colour', 'var(--color-accent)')
await user.selectOptions(within(shown).getByLabelText('Catégorie'), 'cat-b')
expect(ghost()).toHaveAttribute('data-colour', '#aa3366')
})
it('the point tool previews the next point under a mouse, never under a finger', async () => {
const user = await mount()
await user.click(screen.getByRole('button', { name: 'Point' }))
const at = { clientX: 40, clientY: 30 }
fireEvent.pointerMove(canvas(), { ...at, pointerType: 'touch' })
expect(screen.queryByTestId('overlay-point-preview')).toBeNull()
fireEvent.pointerMove(canvas(), { ...at, pointerType: 'mouse' })
const preview = screen.getByTestId('overlay-point-preview')
// A5: the view's most used size (the only point has r = 5).
expect(preview.querySelector('circle')).toHaveAttribute('r', '5')
expect(preview.querySelector('circle')).toHaveAttribute('cx', '40')
fireEvent.pointerLeave(canvas())
expect(screen.queryByTestId('overlay-point-preview')).toBeNull()
})
it('a link shows « Vue ouverte »', async () => {
const text = insert(twoCategories(), {
kind: 'view',
value: {
kind: 'detail',
id: 'view-det',
name: { fr: 'Tête', en: 'Head' },
svg_asset_id: null,
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
parent_view_id: 'view-main',
},
} as never)
const user = await mount(text)
await user.click(screen.getByRole('button', { name: 'Ajouter un accès' }))
const shown = await dialog('Nouvel accès')
expect(within(shown).getByLabelText('Vue ouverte')).toBeInTheDocument()
expect(
within(shown).getByText('Accès tracé, 3 sommets'),
).toBeInTheDocument()
})
})
describe('« Reprendre le tracé » and « Revenir aux propriétés » (board 04 C)', () => {
it('keeps the vertices and the form; a new vertex, then the dialog again', async () => {
const user = await mount()
await user.click(screen.getByRole('button', { name: 'Zone' }))
;[
[20, 20],
[80, 20],
[50, 80],
].forEach(([x, y]) => pressAt(canvas(), x, y))
await user.click(screen.getByRole('button', { name: 'Fermer le tracé' }))
let shown = await dialog('Nouvelle zone')
await user.type(within(shown).getByLabelText('Nom (FR)'), 'Tibia')
await user.click(
within(shown).getByRole('button', { name: 'Reprendre le tracé' }),
)
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
const strip = screen.getByTestId('edit-strip')
expect(strip).toHaveTextContent('Tracé repris, saisie gardée')
expect(
within(strip).getByRole('button', { name: 'Retirer le dernier sommet' }),
).toBeEnabled()
pressAt(canvas(), 30, 60)
await user.click(
within(strip).getByRole('button', { name: 'Revenir aux propriétés' }),
)
shown = await dialog('Nouvelle zone')
expect(within(shown).getByLabelText('Nom (FR)')).toHaveValue('Tibia')
expect(
within(shown).getByText('Zone tracée, 4 sommets'),
).toBeInTheDocument()
})
})
describe('« Créer » (A7, board 32)', () => {
it('one insert, one undo; « Sélectionner », the new zone selected, its row focused', async () => {
const user = await mount()
await user.click(screen.getByRole('button', { name: 'Zone' }))
;[
[20, 20],
[80, 20],
[50, 80],
].forEach(([x, y]) => pressAt(canvas(), x, y))
fireEvent.keyDown(canvas(), { key: 'Enter' })
const shown = await dialog('Nouvelle zone')
await user.type(within(shown).getByLabelText('Nom (FR)'), 'Tibia')
await user.type(within(shown).getByLabelText('Nom (EN)'), 'Tibia')
await user.selectOptions(within(shown).getByLabelText('Latéralité'), 'left')
const before = store.getState().undo.length
await user.click(within(shown).getByRole('button', { name: 'Créer' }))
expect(store.getState().undo).toHaveLength(before + 1)
const created = annotations().find((a) => a.kind === 'zone')!
expect(created).toMatchObject({ name: { fr: 'Tibia', en: 'Tibia' } })
expect(screen.getByTestId('gesture-line')).toHaveTextContent('Zone créée')
expect(
screen.getByRole('button', { name: 'Sélectionner et déplacer' }),
).toHaveAttribute('aria-pressed', 'true')
await waitFor(() =>
expect(document.activeElement).toHaveAttribute(
'data-focus-key',
JSON.stringify({ kind: 'annotation', id: created.id }),
),
)
})
})
describe('during a creation (A12, R-13)', () => {
it('the other markers are dimmed; undo is inactive; « Défaire » leaves the line', async () => {
const user = await mount()
// A kept gesture first, so the line under the drawing offers « Défaire ».
await user.click(screen.getByRole('button', { name: 'Point' }))
pressAt(canvas(), 50, 50)
const shown = await dialog()
await user.type(within(shown).getByLabelText('Nom (FR)'), 'A')
await user.type(within(shown).getByLabelText('Nom (EN)'), 'B')
await user.selectOptions(within(shown).getByLabelText('Latéralité'), 'left')
await user.click(within(shown).getByRole('button', { name: 'Créer' }))
const line = screen.getByTestId('gesture-line')
expect(within(line).getByRole('button', { name: /Défaire/ })).toBeTruthy()
expect(canvas()).not.toHaveAttribute('data-creating')
// A tracing: no dialog, the page itself is live.
await user.click(screen.getByRole('button', { name: 'Zone' }))
pressAt(canvas(), 20, 80)
expect(canvas()).toHaveAttribute('data-creating')
expect(within(line).queryByRole('button', { name: /Défaire/ })).toBeNull()
const undo = screen.getByRole('button', { name: /Défaire la dernière/ })
expect(undo).toHaveAttribute('aria-disabled', 'true')
const depth = store.getState().undo.length
await user.click(undo)
fireEvent.keyDown(window, { key: 'z', ctrlKey: true })
expect(store.getState().undo).toHaveLength(depth)
expect(creation()).not.toBeNull()
})
it('Escape while the point is replaced asks « Abandonner la création ? »', async () => {
const user = await mount()
const shown = await placePoint(user)
await user.click(
within(shown).getByRole('button', { name: 'Replacer le point' }),
)
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
act(() => canvas().focus())
fireEvent.keyDown(document.body, { key: 'Escape' })
expect(
await screen.findByRole('dialog', { name: 'Abandonner la création ?' }),
).toBeInTheDocument()
})
})