chore(editor): rev 5 review nits
Deterministic scroll-settle wait for the bubble e2e, useDismissal split, precondition for the add-button focus test, CSS comment wrap.
This commit is contained in:
1 parent
a9252375e1
commit
b5dcb766b1
4 files changed
+65
-26
No files matched your search
@@ -67,6 +67,27 @@ interface Box {
|
|||||||
height: number
|
height: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves once the page's scroll position has held for three animation frames: a scroll
|
||||||
|
* event of the move before is then past, which a bubble (closed by any scroll) must not meet.
|
||||||
|
*/
|
||||||
|
async function settleScroll(page: Page) {
|
||||||
|
await page.evaluate(
|
||||||
|
() =>
|
||||||
|
new Promise<void>((resolve) => {
|
||||||
|
let last = window.scrollY
|
||||||
|
let still = 0
|
||||||
|
const frame = () => {
|
||||||
|
still = window.scrollY === last ? still + 1 : 0
|
||||||
|
last = window.scrollY
|
||||||
|
if (still >= 3) resolve()
|
||||||
|
else requestAnimationFrame(frame)
|
||||||
|
}
|
||||||
|
requestAnimationFrame(frame)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The bubble sits in the window, under the top bar, right under its button (within 8 px
|
* The bubble sits in the window, under the top bar, right under its button (within 8 px
|
||||||
* unless the bar pushes it down), and over neither « Défaire » nor the strip's commands.
|
* unless the bar pushes it down), and over neither « Défaire » nor the strip's commands.
|
||||||
@@ -311,7 +332,7 @@ test.describe('editor annotations (A3)', () => {
|
|||||||
await page.waitForTimeout(300)
|
await page.waitForTimeout(300)
|
||||||
await redo.evaluate((el) => el.scrollIntoView({ block: 'center' }))
|
await redo.evaluate((el) => el.scrollIntoView({ block: 'center' }))
|
||||||
// Its scroll event lands before the press, which a scroll would close.
|
// Its scroll event lands before the press, which a scroll would close.
|
||||||
await page.waitForTimeout(150)
|
await settleScroll(page)
|
||||||
const widthBefore = await scrollWidth(page)
|
const widthBefore = await scrollWidth(page)
|
||||||
await expectNoShift(page, async () => {
|
await expectNoShift(page, async () => {
|
||||||
await pressAtBox(page, redo)
|
await pressAtBox(page, redo)
|
||||||
@@ -325,14 +346,14 @@ test.describe('editor annotations (A3)', () => {
|
|||||||
// Scrolled, the strip stuck under the bar: the keyboard press keeps the same rules.
|
// Scrolled, the strip stuck under the bar: the keyboard press keeps the same rules.
|
||||||
await page.evaluate(() => window.scrollTo(0, 150))
|
await page.evaluate(() => window.scrollTo(0, 150))
|
||||||
await redo.focus()
|
await redo.focus()
|
||||||
await page.waitForTimeout(150)
|
await settleScroll(page)
|
||||||
await page.keyboard.press('Enter')
|
await page.keyboard.press('Enter')
|
||||||
await expect(bubble).toHaveText(reason)
|
await expect(bubble).toHaveText(reason)
|
||||||
await expectBubbleBeside(page, bubble, redo, undo)
|
await expectBubbleBeside(page, bubble, redo, undo)
|
||||||
await page.keyboard.press('Escape')
|
await page.keyboard.press('Escape')
|
||||||
await expect(bubble).toHaveCount(0)
|
await expect(bubble).toHaveCount(0)
|
||||||
await page.evaluate(() => window.scrollTo(0, 0))
|
await page.evaluate(() => window.scrollTo(0, 0))
|
||||||
await page.waitForTimeout(150)
|
await settleScroll(page)
|
||||||
}
|
}
|
||||||
await expect(page.getByTestId('gesture-message')).toHaveCount(0)
|
await expect(page.getByTestId('gesture-message')).toHaveCount(0)
|
||||||
// Escape order: the bubble first, alone; the next Escape asks about the creation.
|
// Escape order: the bubble first, alone; the next Escape asks about the creation.
|
||||||
|
|||||||
@@ -902,6 +902,11 @@ for (const viewport of VIEWPORTS) {
|
|||||||
// scroll, never onto the bar or the strip, and the column stays below the strip.
|
// scroll, never onto the bar or the strip, and the column stays below the strip.
|
||||||
await page.evaluate(() => window.scrollTo(0, 0))
|
await page.evaluate(() => window.scrollTo(0, 0))
|
||||||
const add = page.locator('[data-add-kind="point"]')
|
const add = page.locator('[data-add-kind="point"]')
|
||||||
|
const unrevealed = (await add.boundingBox())!
|
||||||
|
expect(
|
||||||
|
unrevealed.y,
|
||||||
|
'precondition: the add button is below the fold',
|
||||||
|
).toBeGreaterThan(await page.evaluate(() => window.innerHeight))
|
||||||
await add.focus()
|
await add.focus()
|
||||||
const revealed = await stripGeometry(page)
|
const revealed = await stripGeometry(page)
|
||||||
const addBox = (await add.boundingBox())!
|
const addBox = (await add.boundingBox())!
|
||||||
|
|||||||
@@ -26,6 +26,33 @@ export function useHeldBubble(
|
|||||||
return { open, serial, show, close }
|
return { open, serial, show, close }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PAGE_MOVES = ['scroll', 'wheel', 'touchmove']
|
||||||
|
|
||||||
|
/** Escape closes the bubble first; in a text field it is not taken, a modal keeps its own. */
|
||||||
|
function escapeHandler(close: () => void) {
|
||||||
|
return (event: KeyboardEvent) => {
|
||||||
|
if (event.key !== 'Escape' || event.isComposing) return
|
||||||
|
if (document.querySelector('dialog[open]')) return
|
||||||
|
close()
|
||||||
|
if (isTextField(event.target)) return
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A dialog gaining `open` anywhere in the page closes the bubble. */
|
||||||
|
function watchDialogs(close: () => void) {
|
||||||
|
const watch = new MutationObserver(() => {
|
||||||
|
if (document.querySelector('dialog[open]')) close()
|
||||||
|
})
|
||||||
|
watch.observe(document.body, {
|
||||||
|
subtree: true,
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ['open'],
|
||||||
|
})
|
||||||
|
return watch
|
||||||
|
}
|
||||||
|
|
||||||
function useDismissal(
|
function useDismissal(
|
||||||
open: boolean,
|
open: boolean,
|
||||||
close: () => void,
|
close: () => void,
|
||||||
@@ -33,37 +60,22 @@ function useDismissal(
|
|||||||
) {
|
) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return
|
if (!open) return
|
||||||
const onKey = (event: KeyboardEvent) => {
|
const onKey = escapeHandler(close)
|
||||||
if (event.key !== 'Escape' || event.isComposing) return
|
|
||||||
if (document.querySelector('dialog[open]')) return
|
|
||||||
close()
|
|
||||||
if (isTextField(event.target)) return
|
|
||||||
event.preventDefault()
|
|
||||||
event.stopPropagation()
|
|
||||||
}
|
|
||||||
const onPress = (event: Event) => {
|
const onPress = (event: Event) => {
|
||||||
if (!button.current?.contains(event.target as Node)) close()
|
if (!button.current?.contains(event.target as Node)) close()
|
||||||
}
|
}
|
||||||
const onDialog = () => {
|
const watch = watchDialogs(close)
|
||||||
if (document.querySelector('dialog[open]')) close()
|
|
||||||
}
|
|
||||||
const watch = new MutationObserver(onDialog)
|
|
||||||
watch.observe(document.body, {
|
|
||||||
subtree: true,
|
|
||||||
attributes: true,
|
|
||||||
attributeFilter: ['open'],
|
|
||||||
})
|
|
||||||
const passive = { capture: true, passive: true }
|
const passive = { capture: true, passive: true }
|
||||||
document.addEventListener('keydown', onKey, true)
|
document.addEventListener('keydown', onKey, true)
|
||||||
document.addEventListener('pointerdown', onPress, true)
|
document.addEventListener('pointerdown', onPress, true)
|
||||||
for (const type of ['scroll', 'wheel', 'touchmove']) {
|
for (const type of PAGE_MOVES) {
|
||||||
document.addEventListener(type, close, passive)
|
document.addEventListener(type, close, passive)
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
watch.disconnect()
|
watch.disconnect()
|
||||||
document.removeEventListener('keydown', onKey, true)
|
document.removeEventListener('keydown', onKey, true)
|
||||||
document.removeEventListener('pointerdown', onPress, true)
|
document.removeEventListener('pointerdown', onPress, true)
|
||||||
for (const type of ['scroll', 'wheel', 'touchmove']) {
|
for (const type of PAGE_MOVES) {
|
||||||
document.removeEventListener(type, close, passive)
|
document.removeEventListener(type, close, passive)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,10 +63,11 @@ body,
|
|||||||
}
|
}
|
||||||
/* The drawing column (chips, tools, canvas, add row, message line) is pinned under the
|
/* The drawing column (chips, tools, canvas, add row, message line) is pinned under the
|
||||||
strip, so no part of the drawing is ever under it while the side panel scrolls (U2 Task
|
strip, so no part of the drawing is ever under it while the side panel scrolls (U2 Task
|
||||||
17). Only where the column fits: below 40.25rem (644 px) of window height the 365 px tool
|
17). Only where the column fits: below 40.25rem (644 px) of window height the 365 px
|
||||||
column beside a capped canvas does not, nothing here applies and nothing is pinned. The negative bottom margin lets the
|
tool column beside a capped canvas does not, nothing here applies and nothing is
|
||||||
pinned travel run into the page's bottom space (workspace gap + main padding): without
|
pinned. The negative bottom margin lets the pinned travel run into the page's bottom
|
||||||
it, the page's end pushed the column's top under the strip at 1 180 x 820. */
|
space (workspace gap + main padding): without it, the page's end pushed the column's
|
||||||
|
top under the strip at 1 180 x 820. */
|
||||||
@media (min-width: 1024px) and (min-height: 40.25rem) {
|
@media (min-width: 1024px) and (min-height: 40.25rem) {
|
||||||
[data-drawing-column] {
|
[data-drawing-column] {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
|||||||
Reference in new issue
Block a user