An open source design system that's fully customizable and agent ready
TypeScript
test(lab): the PageControl busy proof reads the slide on frames (#10433)
Christopher Chedeau3866383ff8b8
diff --git a/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts b/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.tsindex f74cef14fa..bfd8aaa288 100644--- a/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts+++ b/packages/lab/src/PageControl/__tests__/PageControl.interaction.browser.spec.ts@@ -19,11 +19,20 @@ import {import {animationStoryboard,armHold,+ blockMainThread,+ BUSY_PROOF_LOOKAROUND_MS,+ busyWindowProof,+ CONTROL_RGB,drag,+ MARKER_RGB,releaseAnimations,openStory,+ startBusyControl,+ startScreencast,touchDriver,touchStoryboard,+ trackMarkers,+ waitForRest,withStorybook,} from '@astryxdesign/interaction-harness';@@ -33,6 +42,11 @@ const storybook = withStorybook(test);const PITCH = 17.67;/** A full-size dot's scale: the 9.67 px indicator on its 10 px box. */const DOT_SCALE = 0.967;+/**+ * Frames of the slide the busy proof must judge inside its block. The slide+ * is a 190 ms spring that shows about five frames of travel there.+ */+const MIN_JUDGED_FRAMES = 4;/*** Opens a PageControl story. The phone projects have a coarse primary@@ -921,35 +935,66 @@ test('busy main thread: a window slide finishes on time through a 600 ms block',"WebKit's screencast clock is not the page's (harness README); the simulator clip covers it",);const {slider, driver} = await open(page, 'lab-pagecontrol--many-pages');+ const strip = slider.locator(':scope > *').first();+ // A chip on the strip between two dots, above them: the window shows it+ // before and after the slide, and no dot's scale reaches it. The strip's+ // translate makes it the chip's containing block, so the chip moves with it.+ await strip.evaluate(+ (el, {left, rgb}) => {+ const chip = document.createElement('div');+ chip.setAttribute('data-harness-marker-chip', '');+ chip.style.cssText = `position:absolute;left:${left}px;top:0;width:12px;height:6px;background:rgb(${rgb.join(',')})`;+ el.append(chip);+ },+ {left: 23.5 * PITCH - 6, rgb: MARKER_RGB},+ );+ // Before the slide, so the control is on the compositor first.+ await startBusyControl(page);+ const cast = await startScreencast(page);+ // The page blocks once the old dot's fade has run a frame, just before the+ // slide starts on its own start time. A round trip from here would start+ // the block later in the slide, or after it.+ const blocking = blockMainThread(page, 600, {during: strip});const current = await indicatorCenter(slider, 25);await driver.tap({x: current.x + 12, y: current.y});- await expect- .poll(async () =>- slider.evaluate(- el => (el.children[0] as HTMLElement).getAnimations().length,- ),- )- .toBeGreaterThan(0);- // Block the main thread once the slide is on the timeline (it starts 50 ms- // after the change), for longer than the slide lasts.- const afterBlock = await slider.evaluate(el => {- const strip = el.children[0] as HTMLElement;- const end = performance.now() + 600;- while (performance.now() < end) {- // busy- }- return {- x: Number.parseFloat(getComputedStyle(strip).translate),- running: strip- .getAnimations()- .filter(- a => a.playState === 'running' && Number(a.currentTime ?? 0) < 400,- ).length,- };+ const busy = await blocking;+ await waitForRest(strip);+ // Where the slide ends, read from the page once it rests.+ const settledAt = await strip.evaluate(el => {+ const chip = el.querySelector('[data-harness-marker-chip]') as Element;+ return chip.getBoundingClientRect().x;});- // The compositor carried the slide to the next slot during the block.- expect(afterBlock.x).toBeCloseTo(-19 * PITCH, 0);- expect(afterBlock.running).toBe(0);+ const frames = await cast.stop();+ // Only the frames the proof reads are decoded, each once for both colors.+ const [tracked, control] = await trackMarkers(+ page,+ frames.filter(f => f.t <= busy.to + BUSY_PROOF_LOOKAROUND_MS),+ {colors: [MARKER_RGB, CONTROL_RGB]},+ );+ const proof = busyWindowProof(tracked, busy, {+ axis: 'x',+ settledWithinSteps: 2,+ settledAt,+ minJudgedFrames: MIN_JUDGED_FRAMES,+ control,+ });+ // The compositor carried the slide to the next slot during the block. It+ // moved on every frame, and a frame inside the block shows it at rest.+ expect(proof.verdict.failures, proof.summary).toEqual([]);+ expect(proof.monotonic, proof.summary).toBe(true);+ const atRest = tracked.find(+ f =>+ f.box != null &&+ f.t >= busy.from &&+ f.t <= busy.to &&+ Math.abs(f.box.x - settledAt) <= 1,+ );+ expect(atRest, proof.summary).toBeDefined();+ expect(+ await strip.evaluate(el =>+ Number.parseFloat(getComputedStyle(el).translate),+ ),+ ).toBeCloseTo(-19 * PITCH, 0);});test('on an Android phone (no -webkit-touch-callout) a finger scrubs: one touch model, no platform idiom', async ({