test(tests): typed draft before Escape in the add e2e, prettier on C4 spec
This commit is contained in:
1 parent
94f8a8bf27
commit
346a8fd8f1
2 files changed
+78
-22
No files matched your search
@@ -452,7 +452,9 @@ test.describe('reference tiles, search, sort and add', () => {
|
||||
await expect(headers(page)).toHaveCount(count)
|
||||
await expect(add).toBeFocused()
|
||||
expect(await states()).toEqual(before)
|
||||
// A typed draft, then Escape on the type select (not a text target): it cancels.
|
||||
await add.click()
|
||||
await root.getByLabel(dict['editor.reference.citation']).fill('Brouillon')
|
||||
await type.focus()
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(draft).toHaveCount(0)
|
||||
|
||||
@@ -182,7 +182,11 @@ async function stableScrollY(page: Page) {
|
||||
function triggerRect(trigger: Locator) {
|
||||
return trigger.evaluate((el) => {
|
||||
const box = el.getBoundingClientRect()
|
||||
return { top: box.top, bottom: box.bottom, gap: window.innerHeight - box.bottom }
|
||||
return {
|
||||
top: box.top,
|
||||
bottom: box.bottom,
|
||||
gap: window.innerHeight - box.bottom,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -190,12 +194,21 @@ function triggerRect(trigger: Locator) {
|
||||
async function touchSwipe(page: Page, cdp: CDPSession, travel: number) {
|
||||
const from = 340
|
||||
const point = (y: number) => [{ x: 200, y }]
|
||||
await cdp.send('Input.dispatchTouchEvent', { type: 'touchStart', touchPoints: point(from) })
|
||||
await cdp.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchStart',
|
||||
touchPoints: point(from),
|
||||
})
|
||||
for (let step = 1; step <= 10; step++) {
|
||||
const y = from - (travel * step) / 10
|
||||
await cdp.send('Input.dispatchTouchEvent', { type: 'touchMove', touchPoints: point(y) })
|
||||
await cdp.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchMove',
|
||||
touchPoints: point(y),
|
||||
})
|
||||
}
|
||||
await cdp.send('Input.dispatchTouchEvent', { type: 'touchEnd', touchPoints: [] })
|
||||
await cdp.send('Input.dispatchTouchEvent', {
|
||||
type: 'touchEnd',
|
||||
touchPoints: [],
|
||||
})
|
||||
return stableScrollY(page)
|
||||
}
|
||||
|
||||
@@ -207,32 +220,48 @@ const REACH_MAX_SWIPES = 12
|
||||
* Swipes by touch only until the trigger is wholly on screen and hit-testable. Answers the
|
||||
* swipe count; throws with the scrollY trace after REACH_MAX_SWIPES swipes.
|
||||
*/
|
||||
async function swipeUntilReached(page: Page, cdp: CDPSession, trigger: Locator) {
|
||||
async function swipeUntilReached(
|
||||
page: Page,
|
||||
cdp: CDPSession,
|
||||
trigger: Locator,
|
||||
) {
|
||||
const trace: number[] = []
|
||||
for (let swipes = 0; swipes <= REACH_MAX_SWIPES; swipes++) {
|
||||
const view = await probeInView(trigger)
|
||||
if (view.inside && view.hit) return swipes
|
||||
if (swipes < REACH_MAX_SWIPES) trace.push(await touchSwipe(page, cdp, REACH_TRAVEL))
|
||||
if (swipes < REACH_MAX_SWIPES)
|
||||
trace.push(await touchSwipe(page, cdp, REACH_TRAVEL))
|
||||
}
|
||||
throw new Error(`the trigger never came into view: scrollY after each swipe ${trace.join(' ')}`)
|
||||
throw new Error(
|
||||
`the trigger never came into view: scrollY after each swipe ${trace.join(' ')}`,
|
||||
)
|
||||
}
|
||||
|
||||
/** Scrolls at once so the trigger's bottom sits on the viewport bottom (clamped to the page). */
|
||||
async function scrollToWorstCase(page: Page, trigger: Locator) {
|
||||
await trigger.evaluate((el) => {
|
||||
const max = document.documentElement.scrollHeight - window.innerHeight
|
||||
const want = window.scrollY + el.getBoundingClientRect().bottom - window.innerHeight
|
||||
window.scrollTo({ top: Math.min(Math.max(Math.ceil(want), 0), max), behavior: 'instant' })
|
||||
const want =
|
||||
window.scrollY + el.getBoundingClientRect().bottom - window.innerHeight
|
||||
window.scrollTo({
|
||||
top: Math.min(Math.max(Math.ceil(want), 0), max),
|
||||
behavior: 'instant',
|
||||
})
|
||||
})
|
||||
return stableScrollY(page)
|
||||
}
|
||||
|
||||
/** Taps the trigger: the panel opens with heading and close in view, the page does not scroll. */
|
||||
async function tapOpensInPlace(page: Page, trigger: Locator, scrollY: number) {
|
||||
expect(await probeInView(trigger), 'trigger in view').toEqual({ inside: true, hit: true })
|
||||
expect(await probeInView(trigger), 'trigger in view').toEqual({
|
||||
inside: true,
|
||||
hit: true,
|
||||
})
|
||||
await trigger.tap()
|
||||
await expect(page.locator('#editor-citations-title')).toBeFocused()
|
||||
expect(await stableScrollY(page), 'no scroll once the panel is open').toBe(scrollY)
|
||||
expect(await stableScrollY(page), 'no scroll once the panel is open').toBe(
|
||||
scrollY,
|
||||
)
|
||||
await expectPanelReachable(page)
|
||||
}
|
||||
|
||||
@@ -240,10 +269,15 @@ async function tapOpensInPlace(page: Page, trigger: Locator, scrollY: number) {
|
||||
function probeInView(target: Locator) {
|
||||
return target.evaluate((el) => {
|
||||
const box = el.getBoundingClientRect()
|
||||
const at = document.elementFromPoint(box.x + box.width / 2, box.y + box.height / 2)
|
||||
const at = document.elementFromPoint(
|
||||
box.x + box.width / 2,
|
||||
box.y + box.height / 2,
|
||||
)
|
||||
const inside =
|
||||
box.top >= 0 && box.left >= 0 &&
|
||||
box.bottom <= window.innerHeight && box.right <= window.innerWidth
|
||||
box.top >= 0 &&
|
||||
box.left >= 0 &&
|
||||
box.bottom <= window.innerHeight &&
|
||||
box.right <= window.innerWidth
|
||||
return { inside, hit: !!at && el.contains(at) }
|
||||
})
|
||||
}
|
||||
@@ -252,15 +286,29 @@ function probeInView(target: Locator) {
|
||||
async function expectPanelReachable(page: Page) {
|
||||
const panel = page.locator('#editor-citations-panel')
|
||||
const heading = page.locator('#editor-citations-title')
|
||||
const close = panel.getByRole('button', { name: dict['editor.references.close'] })
|
||||
const close = panel.getByRole('button', {
|
||||
name: dict['editor.references.close'],
|
||||
})
|
||||
const visible = await panel.evaluate(
|
||||
(el) => Math.min(el.getBoundingClientRect().bottom, window.innerHeight) -
|
||||
(el) =>
|
||||
Math.min(el.getBoundingClientRect().bottom, window.innerHeight) -
|
||||
Math.max(el.getBoundingClientRect().top, 0),
|
||||
)
|
||||
test.info().annotations.push({ type: 'c4-measure', description: `panel visible ${visible}` })
|
||||
test
|
||||
.info()
|
||||
.annotations.push({
|
||||
type: 'c4-measure',
|
||||
description: `panel visible ${visible}`,
|
||||
})
|
||||
expect(visible).toBeGreaterThan(0)
|
||||
expect(await probeInView(heading), 'heading').toEqual({ inside: true, hit: true })
|
||||
expect(await probeInView(close), 'close button').toEqual({ inside: true, hit: true })
|
||||
expect(await probeInView(heading), 'heading').toEqual({
|
||||
inside: true,
|
||||
hit: true,
|
||||
})
|
||||
expect(await probeInView(close), 'close button').toEqual({
|
||||
inside: true,
|
||||
hit: true,
|
||||
})
|
||||
}
|
||||
|
||||
test.describe('editor shell layout (H)', () => {
|
||||
@@ -585,7 +633,9 @@ test.describe('citations panel at 375 px, read-only (O4-2)', () => {
|
||||
const reached = await stableScrollY(page)
|
||||
expect(reached, 'the page scrolled by touch').toBeGreaterThan(0)
|
||||
await tapOpensInPlace(page, trigger, reached)
|
||||
const close = page.getByRole('button', { name: dict['editor.references.close'] })
|
||||
const close = page.getByRole('button', {
|
||||
name: dict['editor.references.close'],
|
||||
})
|
||||
await close.tap()
|
||||
await expect(place(page, 'citations')).toHaveCount(0)
|
||||
// B. Worst case: the trigger's bottom exactly on the viewport bottom. Set by window.scrollTo
|
||||
@@ -595,10 +645,14 @@ test.describe('citations panel at 375 px, read-only (O4-2)', () => {
|
||||
const end = await triggerRect(trigger)
|
||||
test.info().annotations.push({
|
||||
type: 'c4-measure',
|
||||
description: `top=${start.top} bottom=${start.bottom}; A swipes=${swipes} y=${reached}; ` +
|
||||
description:
|
||||
`top=${start.top} bottom=${start.bottom}; A swipes=${swipes} y=${reached}; ` +
|
||||
`B gap=${end.gap} y=${worst}`,
|
||||
})
|
||||
expect(end.gap, 'trigger gap to the viewport bottom').toBeGreaterThanOrEqual(0)
|
||||
expect(
|
||||
end.gap,
|
||||
'trigger gap to the viewport bottom',
|
||||
).toBeGreaterThanOrEqual(0)
|
||||
expect(end.gap, 'trigger gap to the viewport bottom').toBeLessThanOrEqual(1)
|
||||
await tapOpensInPlace(page, trigger, worst)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user