An open source design system that's fully customizable and agent ready
TypeScript
test(NavigationStack): a push reads its bars held (#10746)
Christopher Chedeau9f55320cc880
diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.tsindex 19097792aa..ea7366f596 100644--- a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts@@ -43,7 +43,6 @@ import {MARKER_RGB,openStory,releaseAnimations,- requireFrames,sampleCurve,sampleRects,seekAnimations,@@ -331,14 +330,6 @@ async function readBarsAt(page: Page, t: number): Promise<BarFrame> {const bar = (page: Page, key: string) =>page.locator(`[data-navigation-bar="${key}"]`).last();-/** The first frame at which `key`'s card has left where it started. */-const firstMove = (frames: BarFrame[], key: string) => {- const start = frames.find(f => f.cards[key] != null)?.cards[key];- return frames.find(- f => f.cards[key] != null && Math.abs(f.cards[key] - (start ?? 0)) > 0.5,- );-};-/*** The time (ms) at which the screens' push or pop spring (critically damped,* 0.3 s, starting at navigation.pushVelocity widths/s) reaches `progress`.@@ -590,19 +581,40 @@ test('a push follows UIKit’s push spring, the card underneath at 0.3 of its sptest('a push’s bar: the new bar slides in with its screen, the covered one rides its parallax, the chevron fades in a beat later', async ({page,}) => {- const {driver, width} = await openStack(page, 'settings');- const stop = await traceBars(page);- await driver.tap(await rowCenter(page, 'General'));- await page.waitForTimeout(900);- const frames = await stop();- const start = firstMove(frames, 'screen-General');- expect(start, 'the push started').toBeDefined();- const during = requireFrames(frames, {- min: 6,- during: 'the pushed screen slides in',- where: f =>- start != null && f.t >= start.t && f.cards['screen-General'] > 0.5,+ const {driver, stack, width} = await openStack(page, 'settings');+ await installBarReader(page);+ // Every layer of the push is held, then read at one timeline time. A busy+ // runner can draw too few live frames to see the push at all.+ const hold = await armHold(page, stack, {+ judges: [+ {target: card(page, 'screen-General'), property: 'translate'},+ {target: card(page, 'root'), property: 'translate'},+ {target: bar(page, 'screen-General'), property: 'translate'},+ {target: bar(page, 'root'), property: 'translate'},+ {+ target: page.locator('[data-navigation-back] > *').first(),+ property: 'opacity',+ },+ ],+ count: 5,+ newOnly: true,});+ await driver.tap(await rowCenter(page, 'General'));+ await hold.held();+ const frames: BarFrame[] = [];+ for (let i = 0; i <= 36; i++) {+ frames.push(await readBarsAt(page, await seekAnimations(page, i * 16.667)));+ }+ await releaseAnimations(page, {finish: true});+ // The push is over once its screen is at rest.+ await waitForRest(card(page, 'screen-General'));+ const during = frames.filter(f => (f.cards['screen-General'] ?? 0) > 0.5);+ // The held course shows the pushed screen moving, in enough samples to+ // judge.+ expect(+ during.length,+ JSON.stringify(frames.map(f => [f.t, f.cards])),+ ).toBeGreaterThanOrEqual(6);for (const f of during) {// UIKit's bar copy is part of its screen: it moves with the card (one// clock and spring). It stays within 1 % of the width, as engines sample