Files
faunosteo/apps/app/e2e/support/layout.ts
T
bchanot 1deb037fac 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)
2026-11-17 17:45:41 +01:00

147 lines
4.9 KiB
TypeScript

/**
* The no-shift probe of U2 (adjustment A14, plan Task 3): a state change of the annotations
* tab moves no box. The boxes of the canvas, the strip, the aside and the draft header,
* the page's scroll height, its scrollbar gutter and its client width are read before and
* after `act`; a layout-shift observer adds up every entry in between, the ones following
* an input included (a message appearing after a drop is still a shift).
*/
import { expect, type Page } from '@playwright/test'
/**
* What may change by design until a later task, named at the call site only: the side
* panel's own content (its height, the scroll height, and shifts whose every moved node is
* inside it) while it still swaps the overview, the properties and the creation panel.
*/
export type ShiftExemption = 'aside-content'
interface Box {
x: number
y: number
width: number
height: number
}
interface Snapshot {
boxes: Record<string, Box | null>
scrollHeight: number
gutter: string
clientWidth: number
}
const PARTS = {
canvas: '[data-testid="annotation-canvas"]',
strip: '[data-testid="edit-strip"]',
aside: '[data-testid="editor-tab-annotations"] aside',
header: 'header:has(> nav + div > h1)',
} as const
function snapshot(page: Page): Promise<Snapshot> {
return page.evaluate((parts) => {
const shown = (selector: string) =>
[...document.querySelectorAll(selector)].find(
(element) => (element as HTMLElement).offsetParent !== null,
)
const boxes: Record<string, Box | null> = {}
for (const [name, selector] of Object.entries(parts)) {
const rect = shown(selector)?.getBoundingClientRect()
boxes[name] = rect
? { x: rect.x, y: rect.y, width: rect.width, height: rect.height }
: null
}
const root = document.documentElement
return {
boxes,
scrollHeight: root.scrollHeight,
gutter: getComputedStyle(root).scrollbarGutter,
clientWidth: root.clientWidth,
}
}, PARTS)
}
/** The page side of the probe: the summed shift and what moved, for the failure message. */
interface ShiftScope {
__shift: { total: number; moved: string[] }
__shiftObserver?: PerformanceObserver
}
/** Starts summing layout-shift entries; read back with `shiftTotal`. */
function observeShifts(page: Page, asideExempt: boolean): Promise<void> {
return page.evaluate(
({ exempt, aside }) => {
const scope = window as unknown as ShiftScope
scope.__shiftObserver?.disconnect()
scope.__shift = { total: 0, moved: [] }
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
const shift = entry as unknown as {
value: number
sources: { node?: Node }[]
}
const inAside = shift.sources.every((source) =>
(source.node as Element | undefined)?.closest?.(aside),
)
if (exempt && inAside) continue
scope.__shift.total += shift.value
for (const source of shift.sources) {
const node = source.node as Element | undefined
scope.__shift.moved.push(
node?.outerHTML?.slice(0, 160) ?? String(source.node),
)
}
}
})
observer.observe({ type: 'layout-shift' })
scope.__shiftObserver = observer
},
{ exempt: asideExempt, aside: PARTS.aside },
)
}
/** Two frames for layout to settle, then the pending entries and the total. */
function shiftTotal(page: Page): Promise<ShiftScope['__shift']> {
return page.evaluate(async () => {
await new Promise((done) =>
requestAnimationFrame(() => requestAnimationFrame(done)),
)
const scope = window as unknown as ShiftScope
const observer = scope.__shiftObserver!
const pending = observer.takeRecords()
observer.disconnect()
for (const entry of pending) {
scope.__shift.total += (entry as unknown as { value: number }).value
}
return scope.__shift
})
}
/**
* Runs `act` and asserts nothing moved. `exempt: ['aside-content']` lets the side panel's
* content change (see `ShiftExemption`); the aside's position and width, the canvas, the
* strip and the header are still checked, and every shift outside the aside.
*/
export async function expectNoShift(
page: Page,
act: () => Promise<void>,
exempt: readonly ShiftExemption[] = [],
): Promise<void> {
const before = await snapshot(page)
const loose = exempt.includes('aside-content')
await observeShifts(page, loose)
await act()
const shift = await shiftTotal(page)
const after = await snapshot(page)
const drop = (shot: Snapshot) => ({
...shot,
scrollHeight: loose ? 0 : shot.scrollHeight,
boxes: {
...shot.boxes,
aside:
loose && shot.boxes.aside
? { ...shot.boxes.aside, height: 0 }
: shot.boxes.aside,
},
})
expect(drop(after)).toEqual(drop(before))
expect(shift.total, `layout shift of ${shift.moved.join(' | ')}`).toBe(0)
}