An open source design system that's fully customizable and agent ready
TypeScript
test(NavigationStack): starved gestures fail by name, or not at all (#10529)
Christopher Chedeaue02ed192643c
diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.tsindex 25c73d6674..667a7c728d 100644--- a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts@@ -24,6 +24,7 @@ import {advanceFrozenPage,animationStoryboard,armHold,+ armInputRun,blockMainThread,BusyWindowTooLateError,busyWindowProof,@@ -48,7 +49,12 @@ import {startBusyControl,startScreencast,thawPage,+ toTouchEvents,+ touchArrivalsFrom,touchDriver,+ TouchPacingError,+ touchPacingFault,+ TouchPageStallError,touchStoryboard,traceRendering,trackMarker,@@ -456,6 +462,18 @@ const rowCenter = async (page: Page, name: string) => {return {x: box.x + box.width / 2, y: box.y + box.height / 2};};+/** The events a touch play's page receives, pointer events included. */+const TOUCH_INPUT_TYPES = [+ 'pointerdown',+ 'pointermove',+ 'pointerup',+ 'pointercancel',+ 'touchstart',+ 'touchmove',+ 'touchend',+ 'touchcancel',+];+test('a push follows UIKit’s push spring, the card underneath at 0.3 of its speed', async ({page,}, testInfo) => {@@ -930,9 +948,39 @@ test('a flick from near the edge finishes the pop', async ({page}) => {standalone: true,});// ~60 px of travel at ~1200 px/s: p + 0.35·v is well past half.- await driver.play(flick({x: left + 6, y: 400}, {velocity: {x: 1200, y: 0}}));+ const script = flick({x: left + 6, y: 400}, {velocity: {x: 1200, y: 0}});+ const run = await armInputRun(page, TOUCH_INPUT_TYPES);+ // The page reads the release from when the moves arrive: pace on spacing.+ await driver.play(script, {pacing: 'spacing'});await waitForRest(card(page, 'screen-General'));- await expect.poll(topTitle).toBe('General');+ try {+ await expect.poll(topTitle).toBe('General');+ } catch (error) {+ // A starved runner delivers the moves late, so the page reads a release+ // far from the script's. Past half of it, the run did not deliver the+ // flick this test describes. It fails by name, as the page's when its own+ // listeners held a move.+ const record = await run.evaluate(recorded => {+ recorded.stop();+ return {+ eventTypes: recorded.eventTypes.slice(),+ pointerTypes: recorded.pointerTypes.slice(),+ stamps: recorded.stamps.slice(),+ handledAt: recorded.handledAt.slice(),+ };+ });+ const fault = touchPacingFault(+ toTouchEvents(script),+ touchArrivalsFrom(record),+ 0.5,+ );+ if (fault != null) {+ throw fault.heldByPage == null+ ? new TouchPacingError(fault)+ : new TouchPageStallError({...fault, heldByPage: fault.heldByPage});+ }+ throw error;+ }});test('in a browser tab the leading screen edge stays the browser’s', async ({diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.tsindex 2c3137e3bf..21e0802090 100644--- a/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts@@ -59,27 +59,67 @@ async function settleAt(page: Page, screen: string, top: number) {return presentedOpacity(veil(page, screen));}+// A report that never comes leaves the finger down for about a second.+const REPORT_FRAMES = 60;+/*** Scrolls a screen while a finger rests on its content, and lifts the finger- * two frames later, after the observer has reported. The gesture host reads- * the scroll as the finger's, so the veil fades.+ * once the observer has reported: the veil then animates or changes. The+ * gesture host reads the scroll as the finger's, so the veil fades. The scroll+ * ends under the resting finger, so a lift before a late report would make+ * the scroll the program's. A page starved of frames reports late. Resolves+ * with the frames from the scroll to the veil's first change, or null when it+ * did not change within REPORT_FRAMES.*/-async function fingerScrollTo(page: Page, screen: string, top: number) {- await scroller(page, screen).evaluate((element, y) => {- const target = element.lastElementChild ?? element;- const touch = {identifier: 7, clientX: 100, clientY: 400, target};- const fire = (type: string, touches: (typeof touch)[]) => {- const event = new Event(type, {bubbles: true, cancelable: true});- Object.defineProperty(event, 'changedTouches', {value: [touch]});- Object.defineProperty(event, 'touches', {value: touches});- target.dispatchEvent(event);- };- fire('touchstart', [touch]);- element.scrollTop = y;- requestAnimationFrame(() =>- requestAnimationFrame(() => fire('touchend', [])),- );- }, top);+async function fingerScrollTo(+ page: Page,+ screen: string,+ top: number,+): Promise<number | null> {+ return scroller(page, screen).evaluate(+ (element, {y, maxFrames}) =>+ new Promise<number | null>(resolve => {+ const target = element.lastElementChild ?? element;+ const touch = {identifier: 7, clientX: 100, clientY: 400, target};+ const fire = (type: string, touches: (typeof touch)[]) => {+ const event = new Event(type, {bubbles: true, cancelable: true});+ Object.defineProperty(event, 'changedTouches', {value: [touch]});+ Object.defineProperty(event, 'touches', {value: touches});+ target.dispatchEvent(event);+ };+ const layer = element.parentElement?.querySelector(+ ':scope > [data-navigation-scroll-edge]',+ );+ const animationsBefore = new Set(layer?.getAnimations() ?? []);+ const opacityBefore =+ layer == null ? null : getComputedStyle(layer).opacity;+ fire('touchstart', [touch]);+ element.scrollTop = y;+ let frames = 0;+ const liftAfter = (changedAt: number | null) => () => {+ fire('touchend', []);+ resolve(changedAt);+ };+ const check = () => {+ frames += 1;+ const changed =+ layer == null ||+ layer+ .getAnimations()+ .some(animation => !animationsBefore.has(animation)) ||+ getComputedStyle(layer).opacity !== opacityBefore;+ if (changed) {+ requestAnimationFrame(liftAfter(frames));+ } else if (frames >= maxFrames) {+ requestAnimationFrame(liftAfter(null));+ } else {+ requestAnimationFrame(check);+ }+ };+ requestAnimationFrame(check);+ }),+ {y: top, maxFrames: REPORT_FRAMES},+ );}async function openStack(page: Page, story = STORY) {@@ -315,7 +355,12 @@ test(judges: {target: layer, property: 'opacity'},newOnly: true,});- await fingerScrollTo(page, 'root', 120);+ const reportFrames = await fingerScrollTo(page, 'root', 120);+ // How long the finger rested: a slow reaction to the scroll shows here.+ testInfo.annotations.push({+ type: 'veil report frames',+ description: String(reportFrames),+ });const held = await hold.held();const {storyboard} = await animationStoryboard(page, {held,