fix(editor): message line lifecycle, own row, sound no-shift check

Task 3 review, fix round 1.
- The gesture message closes for good on any document or history
  change (store subscription): undo then redo no longer revives it.
- Hover and focus hold only the message they were taken on: after
  « Défaire » the next message expires.
- An accepted drop clears the strip's refusal hint again.
- Controller ruling: the message has its own fixed row under the add
  buttons, column width; a refused gesture's full text also shows in
  the strip notice (red, aria-hidden copy of the row's alert).
- expectNoShift: native requestAnimationFrame kept before page.clock
  (keepNativeFrames), every part box asserted non-null, message row
  measured; the e2e checks the message is not truncated.
No assertion removed; the refused-drop unit test gains the strip copy.
This commit is contained in:
bchanot committed 2026-11-17 18:10:24 +01:00
1 parent 1deb037fac
commit 7a45f1d885
9 files changed
+198 -49

No files matched your search

@@ -22,7 +22,7 @@ import {
standardShape,
UNSAVED_LINE,
} from '../support/editor'
import { expectNoShift } from '../support/layout'
import { expectNoShift, keepNativeFrames } from '../support/layout'
// V1-2.6 A3 (contract C7, C8, C21): points, zones and links by clicks and by keyboard,
// move by drag, numeric edits, undo and redo, then the save that carries them.
@@ -300,6 +300,7 @@ test.describe('editor annotations (A3)', () => {
async function openWithPoint(page: Page, width: number) {
await page.setViewportSize({ width, height: 800 })
// Installed before any timer: the message's 6 s run on this clock (fast-forwarded below).
await keepNativeFrames(page)
await page.clock.install()
const actor = await editorActor('fr')
const point = pointOf('p-a', 'main', { cx: 500, cy: 300, r: 40 }, 'Pt A')
@@ -350,6 +351,12 @@ test.describe('editor annotations (A3)', () => {
},
swaps,
)
// Its own row, the column's width: the message is read whole.
const cut = await line(page)
.locator('span')
.first()
.evaluate((span) => span.scrollWidth > span.clientWidth)
expect(cut, 'the message is cut short').toBe(false)
// Its expiry, 6 s later.
await expectNoShift(page, async () => {
await page.clock.fastForward(6_100)
+35 -6
View File
@@ -1,8 +1,8 @@
/**
* 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
* tab moves no box. The boxes of the canvas, the strip, the message row, 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'
@@ -31,6 +31,7 @@ interface Snapshot {
const PARTS = {
canvas: '[data-testid="annotation-canvas"]',
strip: '[data-testid="edit-strip"]',
line: '[data-testid="gesture-line"]',
aside: '[data-testid="editor-tab-annotations"] aside',
header: 'header:has(> nav + div > h1)',
} as const
@@ -62,6 +63,23 @@ function snapshot(page: Page): Promise<Snapshot> {
interface ShiftScope {
__shift: { total: number; moved: string[] }
__shiftObserver?: PerformanceObserver
/** The browser's own requestAnimationFrame, kept before `page.clock` replaces it. */
__nativeRaf?: (callback: FrameRequestCallback) => number
}
/**
* Keeps the native requestAnimationFrame: call it before `page.clock.install()`, whose fake
* frames would let the two-frame wait end before the real layout (and its shift) happens.
*/
export async function keepNativeFrames(page: Page): Promise<void> {
await page.addInitScript(() => {
const scope = window as unknown as ShiftScope
const raf = window.requestAnimationFrame
// Kept only when this script ran before the clock's (else the probe would wait on fakes).
if (String(raf).includes('[native code]'))
scope.__nativeRaf = raf.bind(window)
else throw new Error('keepNativeFrames ran after page.clock.install()')
})
}
/** Starts summing layout-shift entries; read back with `shiftTotal`. */
@@ -100,10 +118,17 @@ function observeShifts(page: Page, asideExempt: boolean): Promise<void> {
/** 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 faked = !String(window.requestAnimationFrame).includes(
'[native code]',
)
if (faked && !scope.__nativeRaf) {
throw new Error(
'page.clock fakes the frames: call keepNativeFrames first',
)
}
const frame = scope.__nativeRaf ?? window.requestAnimationFrame.bind(window)
await new Promise((done) => frame(() => frame(done)))
const observer = scope.__shiftObserver!
const pending = observer.takeRecords()
observer.disconnect()
@@ -125,6 +150,10 @@ export async function expectNoShift(
exempt: readonly ShiftExemption[] = [],
): Promise<void> {
const before = await snapshot(page)
// A selector that stops matching would compare null with null: every part must be there.
for (const [name, box] of Object.entries(before.boxes)) {
expect(box, `${name} box before the act`).not.toBeNull()
}
const loose = exempt.includes('aside-content')
await observeShifts(page, loose)
await act()