feat(editor): fixed edit strip and message line without layout shift

U2 Task 3 (A6, A14, R-2). A fixed-height strip over the drawing and the
right column replaces the tool line, the sr-only selection tag of the
edit body and TracingBar: lead (name + status, type + detail), notice
(refusal, first geometry issue + n, unmeasured view with its link, no
category, no child view), commands (Fermer le trace, Retirer le dernier
sommet, Annuler le trace). A fixed-height line under the drawing holds
the add buttons and the gesture message: a kept drop says « Point
deplace » with « Defaire » (same store undo as the header), a refused
drop says « Deplacement refuse : ... » as a red alert. 6 s, held by
mouse hover and focus inside, closed by any commit, undo or redo.
trace_pop and Backspace remove the last vertex. The busy « Aller a »
target is the strip's tracing commands. scrollbar-gutter stable, scoped
to the editor. e2e helper expectNoShift (boxes, scroll height, gutter,
client width, layout-shift sum). DraftHeader untouched: no shift seen.

Rewritten assertions (old -> new):
- tab unit « Sélection : point » on annotation-selection-tag -> strip
  detail « Point »
- tab unit tag sr-only, not live -> strip lead outside any live region
- tab unit « 1 sommet posé. » -> « 1 sommet posé » (board 04 wording)
- tab unit D6b tag present / « zone » -> strip detail « Point » /
  « Zone · 3 sommets »
- keep-alive, sections, escape units: tracing-bar -> tracing-commands
- e2e selectionTag helper -> strip title with data-selection; the
  twin's tag is twinSelectionTag (deselect 375 px describe)
- e2e deselect « tag position absolute » (edit) -> strip height 64 px,
  drawing top unchanged; twin Escape test keeps tag 0, properties 0,
  overview visible
- e2e deselect and journey tracing-bar / annotation-selection-tag ->
  tracing-commands / selectionTag
- e2e historyButton scoped to history-buttons (the message's
  « Défaire » has the same accessible name)
This commit is contained in:
bchanot committed 2026-11-17 17:45:41 +01:00
1 parent b2d78f9621
commit 1deb037fac
23 files changed
+1228 -181

No files matched your search

@@ -12,6 +12,9 @@ import {
import userEvent from '@testing-library/user-event'
import type { Annotation } from '@faunosteo/core-wasm/types'
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
import EditStrip from '@/components/editor/annotations/EditStrip'
import { selectionLead } from '@/editor/annotations/stripLead'
import { fr } from '@/i18n/fr'
import { AnnounceContext } from '@/editor/focusRequest'
import { useLocaleStore } from '@/state/localeStore'
import {
@@ -107,18 +110,16 @@ describe('selection and the list', () => {
expect(within(panel).getByLabelText('Centre x')).toHaveValue(
'743.0451049804688',
)
expect(screen.getByTestId('annotation-selection-tag')).toHaveTextContent(
'Sélection : point',
)
expect(screen.getByTestId('edit-strip-detail')).toHaveTextContent('Point')
})
it('keeps the selection tag out of the visual flow and not live', async () => {
it('names the selection in the strip, outside any live region', async () => {
await mount()
await selectFromList()
const tag = screen.getByTestId('annotation-selection-tag')
expect(tag).toHaveClass('sr-only')
expect(tag).not.toHaveAttribute('aria-live')
expect(tag).not.toHaveAttribute('role')
const lead = screen.getByTestId('edit-strip-lead')
expect(lead).toHaveTextContent('N')
expect(lead.closest('[aria-live]')).toBeNull()
expect(lead.closest('[role]')).toBeNull()
})
})
@@ -585,11 +586,11 @@ describe('tracing a zone or a link', () => {
)
await userEvent.setup().click(screen.getByRole('button', { name: 'Zone' }))
clickAt(20, 20)
expect(screen.getByText('1 sommet posé.')).toBeInTheDocument()
expect(screen.getByText('1 sommet posé')).toBeInTheDocument()
fireEvent.keyDown(screen.getByTestId('annotation-canvas'), {
key: 'Escape',
})
expect(screen.queryByText('1 sommet posé.')).toBeNull()
expect(screen.queryByText('1 sommet posé')).toBeNull()
expect(annotations()).toHaveLength(0)
})
@@ -1214,10 +1215,10 @@ describe('a tap on the drawing (D6b)', () => {
),
})
tap(marker('anno-b'))
expect(screen.getByTestId('annotation-selection-tag')).toBeInTheDocument()
expect(screen.getByTestId('edit-strip-detail')).toHaveTextContent('Point')
tap(marker('zone-a'))
expect(screen.getByTestId('annotation-selection-tag')).toHaveTextContent(
'zone',
expect(screen.getByTestId('edit-strip-detail')).toHaveTextContent(
'Zone · 3 sommets',
)
expect(announce).not.toHaveBeenCalled()
})
@@ -1614,3 +1615,234 @@ describe('a tap on the drawing (D6b)', () => {
expect(store.getState().documentText).toBe(before)
})
})
describe('the strip', () => {
const strip = () => screen.getByTestId('edit-strip')
const lead = () => within(strip()).getByTestId('edit-strip-lead')
const notice = () => within(strip()).getByTestId('edit-strip-notice')
const line = () => screen.getByTestId('gesture-line')
const canvas = () => screen.getByTestId('annotation-canvas')
const button = (name: string) => screen.getByRole('button', { name })
const drag = (el: Element, to: [number, number]) => {
const at = (x: number, y: number) => ({
clientX: x,
clientY: y,
pointerId: 1,
button: 0,
buttons: 1,
})
fireEvent.pointerDown(el, at(50, 50))
fireEvent.pointerMove(el, at(58, 50))
fireEvent.pointerUp(el, { ...at(...to), buttons: 0 })
}
async function tool(name: string) {
await waitFor(() => expect(button(name)).toBeEnabled())
await userEvent.setup().click(button(name))
}
const zoneText = (points: number[][], name = 'N') =>
insert(drawnText(), {
kind: 'annotation',
value: {
...zoneAnnotation({ type: 'polygon', points }),
name: { fr: name, en: name },
},
})
it('has a fixed height, hides its overflow and spans both columns', async () => {
await mount()
expect(strip()).toHaveClass('h-16', 'overflow-hidden')
expect(strip().nextElementSibling?.querySelector('aside')).not.toBeNull()
expect(screen.queryByTestId('tracing-bar')).toBeNull()
})
it('the Point tool: « Ajouter un point », then where to click', async () => {
await mount({ text: drawnText() })
await tool('Point')
expect(lead()).toHaveTextContent('Ajouter un point')
expect(lead()).toHaveTextContent(
'Cliquez dans le dessin pour placer le point',
)
})
it('a selected point: its name, its status, then « Point »; the sr-only tag is gone', async () => {
await mount()
await selectFromList()
expect(within(lead()).getByTestId('edit-strip-title')).toHaveTextContent(
'N',
)
expect(lead()).toHaveTextContent('À confirmer')
expect(within(lead()).getByTestId('edit-strip-detail')).toHaveTextContent(
/^Point$/,
)
expect(screen.queryByTestId('annotation-selection-tag')).toBeNull()
})
it('a selected zone: « Zone · 9 sommets »', async () => {
const nine = [...Array(9).keys()].map((i) =>
[
50 + 30 * Math.cos((i * 2 * Math.PI) / 9),
50 + 30 * Math.sin((i * 2 * Math.PI) / 9),
].map((v) => Math.round(v * 100) / 100),
)
await mount({ text: zoneText(nine) })
await selectFromList()
expect(within(lead()).getByTestId('edit-strip-detail')).toHaveTextContent(
'Zone · 9 sommets',
)
})
it('a long name truncates before the status', async () => {
await mount({ text: zoneText(triangle, 'Un nom très long '.repeat(12)) })
await selectFromList()
const title = within(lead()).getByTestId('edit-strip-title')
expect(title).toHaveClass('truncate')
expect(title.nextElementSibling).toHaveClass('shrink-0')
expect(title.nextElementSibling).toHaveTextContent('À confirmer')
})
it('tracing: the count and the three commands; « Retirer le dernier sommet » and Backspace remove the last vertex', async () => {
await mount({ text: drawnText() })
await tool('Zone')
triangle.forEach(([x, y]) => pressAt(canvas(), x, y))
expect(lead()).toHaveTextContent('Ajouter une zone')
expect(lead()).toHaveTextContent('3 sommets posés')
const commands = within(strip()).getByTestId('tracing-commands')
for (const name of [
'Fermer le tracé',
'Retirer le dernier sommet',
'Annuler le tracé',
]) {
expect(within(commands).getByRole('button', { name })).toBeEnabled()
}
await userEvent.setup().click(button('Retirer le dernier sommet'))
expect(lead()).toHaveTextContent('2 sommets posés')
expect(button('Fermer le tracé')).toBeDisabled()
fireEvent.keyDown(canvas(), { key: 'Backspace' })
expect(lead()).toHaveTextContent('1 sommet posé')
})
it('read-only: « Point · fiche en lecture seule » from the lead builder', () => {
const t = (key: string) => (fr as Record<string, string>)[key] ?? key
const value = point('p', 1, 1, 1).value as Annotation
expect(
selectionLead(value, [], { t, locale: 'fr', readOnly: true }),
).toMatchObject({
title: 'N',
status: 'to_confirm',
detail: 'Point · fiche en lecture seule',
icon: 'point',
})
})
it('an unmeasured view: the hint in the notice, with its link to the views section', async () => {
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const drawing = svgBytes()
sb.getSheetVersion.mockResolvedValue({
...versionAnswer(text(), 3),
drawings: [],
} 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(notice()).toHaveTextContent(/Ce dessin n'est pas mesurable/),
)
await userEvent
.setup()
.click(within(notice()).getByRole('button', { name: 'Vues' }))
expect(props.navigate).toHaveBeenCalled()
})
it('geometry issues: the issue of the selection in the notice, as an error', async () => {
await mount({
text: zoneText([
[150, 150],
[250, 150],
[150, 250],
]),
})
await selectFromList()
const issues = within(screen.getByTestId('annotation-properties'))
.getAllByRole('listitem')
.map((item) => item.textContent)
// The core gives one frame fault per annotation: « +n » is shown by the strip below.
expect(issues).toHaveLength(1)
expect(within(notice()).getByRole('alert')).toHaveTextContent(issues[0]!)
expect(notice()).not.toHaveTextContent('+')
})
it('geometry issues: the first one, then « +n » for the others', () => {
render(
<EditStrip
lead={{ title: 'T', detail: 'Zone', icon: 'zone' }}
notice={{ tone: 'error', text: 'Premier problème', more: 2 }}
commands={null}
/>,
)
expect(notice()).toHaveTextContent('Premier problème+2')
})
it('a drop shows « Point déplacé · Défaire »; « Défaire » undoes it', async () => {
await mount()
await selectFromList()
const before = store.getState().documentText
drag(marker('anno-a'), [60, 40])
expect(line()).toHaveTextContent('Point déplacé')
const undo = within(line()).getByRole('button', {
name: 'Défaire la dernière modification',
})
expect(undo).toHaveTextContent('Défaire')
await userEvent.setup().click(undo)
expect(store.getState().documentText).toBe(before)
expect(line()).not.toHaveTextContent('Point déplacé')
})
it('a new commit replaces the message; an undo from the header clears it', async () => {
await mount()
await selectFromList()
drag(marker('anno-a'), [60, 40])
expect(line()).toHaveTextContent('Point déplacé')
const cx = screen.getByLabelText('Centre x')
const user = userEvent.setup()
await user.clear(cx)
await user.type(cx, '30{Enter}')
expect(line()).not.toHaveTextContent('Point déplacé')
drag(marker('anno-a'), [40, 40])
expect(line()).toHaveTextContent('Point déplacé')
act(() => void store.getState().undoStep())
expect(line()).not.toHaveTextContent('Point déplacé')
})
it('a refused drop: « Déplacement refusé : … » as an alert, red, no « Défaire »', async () => {
await mount()
await selectFromList()
drag(marker('anno-a'), [98, 50])
const alert = within(line()).getByRole('alert')
expect(alert).toHaveTextContent(/^Déplacement refusé : /)
expect(alert.className).toContain('danger')
expect(within(line()).queryByRole('button', { name: /Défaire/ })).toBeNull()
})
it('expires after 6 s; a mouse hover pauses it, a touch does not', async () => {
vi.useFakeTimers({ shouldAdvanceTime: true })
try {
await mount()
await selectFromList()
drag(marker('anno-a'), [60, 40])
const message = () => within(line()).getByTestId('gesture-message')
fireEvent.pointerEnter(message(), { pointerType: 'touch' })
act(() => void vi.advanceTimersByTime(6_100))
expect(line()).not.toHaveTextContent('Point déplacé')
drag(marker('anno-a'), [70, 40])
fireEvent.pointerEnter(message(), { pointerType: 'mouse' })
act(() => void vi.advanceTimersByTime(10_000))
expect(line()).toHaveTextContent('Point déplacé')
fireEvent.pointerLeave(message(), { pointerType: 'mouse' })
act(() => void vi.advanceTimersByTime(6_100))
expect(line()).not.toHaveTextContent('Point déplacé')
} finally {
vi.useRealTimers()
}
})
})
+6 -4
View File
@@ -240,17 +240,19 @@ describe('Escape leaves alone', () => {
expect(store.getState().documentText).toBe(before)
})
it('a tracing: the TracingBar keeps its Escape, the canvas box cancels the tracing only', async () => {
it('a tracing: the strip tracing commands keep their Escape, 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-bar')
const bar = await screen.findByTestId('tracing-commands')
bar.focus()
escape(bar)
expect(screen.queryByTestId('tracing-bar')).not.toBeNull()
expect(screen.queryByTestId('tracing-commands')).not.toBeNull()
canvasBox().focus()
escape(canvasBox())
await waitFor(() => expect(screen.queryByTestId('tracing-bar')).toBeNull())
await waitFor(() =>
expect(screen.queryByTestId('tracing-commands')).toBeNull(),
)
expect(panel()).toBeDefined()
})
@@ -504,7 +504,9 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
})
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
const bar = within(place('annotations.drawing')).getByTestId('tracing-bar')
const bar = within(place('annotations.drawing')).getByTestId(
'tracing-commands',
)
expect(bar).toBeVisible()
await waitFor(() => expect(document.activeElement).toBe(bar))
expect(liveText()).toContain('tracé est en cours')
@@ -531,9 +533,11 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
name: 'Remplacer par un polygone',
}),
)
expect(drawing.getByTestId('tracing-bar')).toBeVisible()
expect(drawing.getByTestId('tracing-commands')).toBeVisible()
})
const bar = within(place('annotations.drawing')).getByTestId('tracing-bar')
const bar = within(place('annotations.drawing')).getByTestId(
'tracing-commands',
)
await waitFor(() => expect(document.activeElement).toBe(bar))
expect(liveText()).toContain('tracé est en cours')
})
+6 -4
View File
@@ -228,9 +228,11 @@ describe('the shown view disappears (undo)', () => {
)
await user.click(screen.getByRole('button', { name: 'Zone' }))
pressAt(screen.getByTestId('annotation-canvas'), 20, 30)
expect(screen.getByTestId('tracing-bar')).toBeInTheDocument()
expect(screen.getByTestId('tracing-commands')).toBeInTheDocument()
act(() => void store.getState().undoStep())
await waitFor(() => expect(screen.queryByTestId('tracing-bar')).toBeNull())
await waitFor(() =>
expect(screen.queryByTestId('tracing-commands')).toBeNull(),
)
})
it('dispatches nothing while the shown view still exists', async () => {
@@ -268,7 +270,7 @@ describe('« Aller à » an annotation while something is in progress', () => {
expect(screen.queryByTestId('annotation-properties')).toBeNull()
})
it('an open zone tracing is kept: the bar takes the focus', async () => {
it('an open zone tracing is kept: the strip tracing commands take the focus', async () => {
const { consumed, announce } = await withProgress(async (user) => {
await waitFor(() =>
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
@@ -277,7 +279,7 @@ describe('« Aller à » an annotation while something is in progress', () => {
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
})
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'kept'))
expect(document.activeElement).toBe(screen.getByTestId('tracing-bar'))
expect(document.activeElement).toBe(screen.getByTestId('tracing-commands'))
expect(announce).toHaveBeenCalledWith(
expect.stringContaining('tracé est en cours'),
)