Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test: watch before the action at 28 first-contact waits (#10286)

Christopher Chedeaub1327c020611
diff --git a/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts b/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts
index 2f9b4dccb1..b2893f23cb 100644
--- a/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts
+++ b/packages/core/src/Button/__tests__/ButtonPressRelease.interaction.browser.spec.ts
@@ -44,7 +44,7 @@ import {
timeline,
touchDriver,
traceRendering,
- waitForAnimation,
+ watchAnimations,
withStorybook,
writeEvidence,
type CastFrame,
@@ -534,10 +534,11 @@ test('the release of a button keeps fading on every frame while the main thread
(el as HTMLElement).style.setProperty('--duration-exit', '400ms'),
);
const cast = await startScreencast(page);
+ const watch = await watchAnimations(opened.surface);
await opened.driver.play(tap(opened.center, {holdMs: HOLD_MS}));
// The release is the longest animation running: the `::before`
// opacity fade, not the 125 ms press-scale transition that starts with it.
- const running = await waitForAnimation(opened.surface, {minProgressMs: 16});
+ const running = await watch.started({minProgressMs: 16});
const release = longestOf(running);
// A 1 s block, as spec:AST-094 FR5's verification names, covers the
// whole release.
@@ -704,10 +705,11 @@ test('the release of a button does no Layout or Paint per frame', async ({
const opened = await openSurface(page, BUTTONS, secondaryButton);
let release = {from: 0, to: 0};
const trace = await traceRendering(page, async () => {
+ const watch = await watchAnimations(opened.surface);
await opened.driver.play(tap(opened.center, {holdMs: HOLD_MS}));
// The release is the longest animation running: the `::before`
// opacity fade, not the 125 ms press-scale transition that starts with it.
- const running = await waitForAnimation(opened.surface);
+ const running = await watch.started();
release = longestOf(running);
await page.waitForTimeout(RELEASE_MS + 100);
});
diff --git a/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts b/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts
index 64c68862d1..4c88d5039c 100644
--- a/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts
+++ b/packages/core/src/DateInput/__tests__/Wheel.interaction.browser.spec.ts
@@ -47,8 +47,9 @@ import {
toTouchEvents,
traceRendering,
trackMarker,
- waitForAnimation,
+ type waitForAnimation,
waitForRest,
+ watchAnimations,
retakeOnWheelPacing,
webInputDriver,
WHEEL_SKIP,
@@ -380,8 +381,9 @@ test('a flick coasts on UIKit’s curve onto the row it projects, and commits it
const {script, offsetAtLift} = flickUp(start);
expect(releaseVelocity(script).y).toBeCloseTo(-FLICK_VELOCITY, -1);
await recordFingerInputs(page);
+ const watch = await watchAnimations(strip);
await driver.play(script);
- const coast = stripAnimationOf(await waitForAnimation(strip));
+ const coast = stripAnimationOf(await watch.started());
const held = await holdAnimations(page, strip);
const motion = held.find(animation => animation.kind === 'Animation');
if (motion == null) {
@@ -520,10 +522,9 @@ test('the coast keeps advancing every frame while the main thread is blocked', a
// The compositor's own record of the frames it presents: a frame the
// screencast skips under load is not a stall (busyWindowProof).
const compositor = await startCompositorTrace(page);
+ const watch = await watchAnimations(strip);
await driver.play(script);
- const coast = stripAnimationOf(
- await waitForAnimation(strip, {minProgressMs: 16}),
- );
+ const coast = stripAnimationOf(await watch.started({minProgressMs: 16}));
// Read the coast the page is playing, from its keyframes: where the strip is
// at each moment. WebKit's real-time input gives the page its own release
// velocity.
@@ -674,10 +675,9 @@ test('a finger landing on the coasting wheel stops it where it is, then it eases
}) => {
const {driver, field, strip, start} = await openWheel(page);
const before = await stripOffset(strip);
+ const watch = await watchAnimations(strip);
await driver.play(flickUp(start).script);
- const coast = stripAnimationOf(
- await waitForAnimation(strip, {minProgressMs: 16}),
- );
+ const coast = stripAnimationOf(await watch.started({minProgressMs: 16}));
const coastEnd = -stripYOf(coast.keyframes?.at(-1));
await page.waitForTimeout(300);
// Land and hold still: the wheel stops at once, between rows.
@@ -728,6 +728,7 @@ test(
// The wheel ends a motion from a timer; gate the page's timers so the
// held coast is not finished behind the filmstrip's back.
await installTimerGate(page);
+ const watch = await watchAnimations(strip);
const flickBoard = await touchStoryboard(page, driver, script, {
name: 'wheel-flick',
clip,
@@ -735,7 +736,7 @@ test(
columns: 6,
cellScale: 0.5,
});
- await waitForAnimation(strip);
+ await watch.started();
await freezeTimers(page);
const {storyboard: coastBoard} = await animationStoryboard(page, {
name: 'wheel-coast',
diff --git a/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts b/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts
index 8945b3c0bc..aed3e3d326 100644
--- a/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts
+++ b/packages/core/src/List/__tests__/ListRowPress.interaction.browser.spec.ts
@@ -52,7 +52,6 @@ import {
timeline,
touchDriver,
traceRendering,
- waitForAnimation,
watchAnimations,
withStorybook,
writeEvidence,
@@ -521,8 +520,9 @@ test('the release does no Layout or Paint per frame', async ({
let release = {from: 0, to: 0};
const started = Date.now();
const trace = await traceRendering(page, async () => {
+ const watch = await watchAnimations(row);
await driver.play(tap(center, {holdMs: HOLD_MS}));
- [release] = await waitForAnimation(row);
+ [release] = await watch.started();
await page.waitForTimeout(exit.ms + 100);
});
// The steady part of the release: its first and last frames may commit.
diff --git a/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts b/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts
index 5dd904c43e..4924772ca8 100644
--- a/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts
+++ b/packages/core/src/SegmentedControl/__tests__/SegmentedControl.interaction.browser.spec.ts
@@ -50,10 +50,12 @@ import {
touchStoryboard,
toTouchEvents,
waitForAnimation,
+ watchAnimations,
webInputDriver,
withStorybook,
writeEvidence,
PEN_SKIP,
+ type AnimationWatch,
type TouchDriver,
} from '@astryxdesign/interaction-harness';
@@ -224,10 +226,13 @@ async function waitForLens(
{
minProgressMs = 1,
timeout = 5000,
- }: {minProgressMs?: number; timeout?: number} = {},
+ watch,
+ }: {minProgressMs?: number; timeout?: number; watch?: AnimationWatch} = {},
): Promise<{from: number; to: number; durationMs: number; easing: string}[]> {
// Installs the harness's curve-end reader and waits for the control to move.
- await waitForAnimation(control.group, {minProgressMs, timeout});
+ await (watch == null
+ ? waitForAnimation(control.group, {minProgressMs, timeout})
+ : watch.started({minProgressMs, timeout}));
const deadline = Date.now() + timeout;
for (;;) {
const found = await control.group.evaluate((group, minProgress) => {
@@ -506,8 +511,9 @@ test('the surface lands exactly where the segment paints it', async ({
// Gate timers: the hand-back runs from the slide's completion timer, which
// must wait while the landed frame is photographed.
await installTimerGate(page);
+ const watch = await watchAnimations(control.group);
await control.tapSegment('list');
- await waitForLens(control);
+ await waitForLens(control, {watch});
await freezeTimers(page);
// The slide runs its course on the compositor. With the timers held, the
// hand-back waits. So this is the slide's last frame: the lens carries the
@@ -581,8 +587,9 @@ test('the titles switch at once with the selection: no second copy of a title is
const elements = await control.group.evaluate(
group => group.querySelectorAll('*').length,
);
+ const watch = await watchAnimations(control.group);
await control.tapSegment('table');
- await waitForLens(control);
+ await waitForLens(control, {watch});
// Mid-slide, as many elements as at rest, and nothing animates Table's
// title's weight or color: it already shows its selected rendering. (Its
// opacity comes back from the press's dim.)
@@ -607,8 +614,9 @@ test('a second tap mid-flight retargets from what is on screen, keeping its velo
page,
}) => {
const control = await openControl(page);
+ const watch = await watchAnimations(control.group);
await control.tapSegment('table');
- await waitForLens(control, {minProgressMs: 60});
+ await waitForLens(control, {minProgressMs: 60, watch});
const describe = async () =>
control.group.evaluate(async group => {
const animations = group.getAnimations({subtree: true}).filter(a => {
@@ -1153,8 +1161,9 @@ test('the slide plays UISegmentedControl’s measured spring, an internal motion
}
});
const from = boxOf(await control.boxes(), 'grid');
+ const watch = await watchAnimations(control.group);
await control.tapSegment('table');
- await waitForLens(control);
+ await waitForLens(control, {watch});
await holdLens(control);
const samples = await sampleLens(control.group, timeline(400));
await releaseAnimations(page);
@@ -1187,8 +1196,9 @@ test('RTL: the surface slides toward the tapped segment', async ({page}) => {
{direction: 'rtl'},
);
const grid = boxOf(await control.boxes(), 'grid');
+ const watch = await watchAnimations(control.group);
await control.tapSegment('table');
- await waitForLens(control);
+ await waitForLens(control, {watch});
await holdLens(control);
const [start, end] = await sampleLens(control.group, [0, 2000]);
// Where Table is once its title has its new weight.
@@ -1315,9 +1325,10 @@ test('the slide keeps advancing every frame while the main thread is blocked', a
);
const control = await openControl(page);
const cast = await startScreencast(page);
+ const watch = await watchAnimations(control.group);
await control.tapSegment('table');
// Running and composited before the block.
- const [slide] = await waitForLens(control, {minProgressMs: 16});
+ const [slide] = await waitForLens(control, {minProgressMs: 16, watch});
// The lens has no element to carry the harness's marker chip: paint the
// lens itself in the marker colour for the frames to find it.
await paintLensMarker(control);
@@ -1380,9 +1391,13 @@ test('the slide does no Layout or Paint per frame', async ({
let start = 0;
const started = Date.now();
const trace = await traceRendering(page, async () => {
+ const watches = [
+ await watchAnimations(groups.nth(0)),
+ await watchAnimations(groups.nth(1)),
+ ];
await next.evaluate(button => (button as HTMLButtonElement).click());
const slides = await Promise.all(
- [0, 1].map(async i => (await waitForAnimation(groups.nth(i)))[0]),
+ watches.map(async watch => (await watch.started())[0]),
);
start = Math.max(...slides.map(slide => slide.from));
// Wait in the test runner, not in the page. Polling the page forces its
@@ -1442,8 +1457,9 @@ test(
});
return sample;
};
+ const watch = await watchAnimations(control.group);
await control.tapSegment('table');
- await waitForLens(control);
+ await waitForLens(control, {watch});
await freezeTimers(page);
const {storyboard: slideBoard} = await animationStoryboard(page, {
name: 'segmented-tap-slide',
diff --git a/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts b/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts
index e086f169c2..17edbba032 100644
--- a/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts
+++ b/packages/core/src/Switch/__tests__/Switch.interaction.browser.spec.ts
@@ -50,8 +50,8 @@ import {
touchStoryboard,
traceRendering,
trackMarker,
- waitForAnimation,
waitForRest,
+ watchAnimations,
withStorybook,
writeEvidence,
type CastFrame,
@@ -2175,8 +2175,9 @@ test.describe('Switch touch presentation (UISwitch, iOS 26.2), under a finger',
// The travel and the track color, from a programmatic change: the thumb
// starts at rest, as UISwitch's `setOn(_:animated:)` does.
await openStory(page, storybook(), 'core-switch--controlled-update');
+ const watch = await watchAnimations(thumb);
await page.getByRole('button', {name: 'Turn on remotely'}).click();
- await waitForAnimation(thumb);
+ await watch.started();
await holdAnimations(page, page.locator('#storybook-root .astryx-switch'));
const travelSamples = await sampleThumb(page, timeline(500));
await releaseAnimations(page);
@@ -2515,9 +2516,10 @@ test.describe('Switch touch presentation (UISwitch, iOS 26.2), under a finger',
throw new Error('no track');
}
const cast = await startScreencast(page);
+ const watch = await watchAnimations(onLayer);
await driver.play(tap(center, {holdMs: 50}));
await expect(input).toBeChecked();
- await waitForAnimation(onLayer, {minProgressMs: 16});
+ await watch.started({minProgressMs: 16});
const block = await blockMainThread(page, 700);
await page.waitForTimeout(150);
const castFrames = await cast.stop();
@@ -2637,8 +2639,9 @@ test.describe('Switch touch presentation (UISwitch, iOS 26.2), under a finger',
const {driver, thumb, center} = await openSwitch(page);
await installTimerGate(page);
const clip = page.locator('#storybook-root .astryx-switch');
+ const watch = await watchAnimations(thumb);
await driver.play(tap(center, {holdMs: 50}));
- await waitForAnimation(thumb);
+ await watch.started();
await freezeTimers(page);
const {storyboard} = await animationStoryboard(page, {
name: 'switch-tap',
diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
index fa390dc9ba..31fbf6123a 100644
--- a/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts
@@ -45,8 +45,8 @@ import {
touchStoryboard,
traceRendering,
trackMarker,
- waitForAnimation,
waitForRest,
+ watchAnimations,
withStorybook,
writeEvidence,
type TouchDriver,
@@ -435,10 +435,11 @@ test('a push follows UIKit’s push spring, the card underneath at 0.3 of its sp
page,
}, testInfo) => {
const {driver, width} = await openStack(page, 'settings');
- await driver.tap(await rowCenter(page, 'General'));
const top = card(page, 'screen-General');
const under = card(page, 'root');
- await waitForAnimation(top);
+ const watch = await watchAnimations(top);
+ await driver.tap(await rowCenter(page, 'General'));
+ await watch.started();
await holdAnimations(page);
const times = Array.from({length: 31}, (_, i) => i * 16.667);
@@ -956,10 +957,11 @@ test('a push keeps advancing every frame while the main thread is blocked', asyn
// The compositor's own pace on this machine, from the same screencast.
await startBusyControl(page);
const cast = await startScreencast(page);
+ const watch = await watchAnimations(top);
await driver.tap(await rowCenter(page, 'General'));
// Below the bar, which overlays the screens.
await markElement(top, {inset: 60});
- const [push] = await waitForAnimation(top, {minProgressMs: 16});
+ const [push] = await watch.started({minProgressMs: 16});
// The page blocks itself from inside the push, once it has run a frame. A
// block from the test's own round trip can start before the marker paints.
const block = await blockMainThread(page, 600, {
@@ -1035,8 +1037,9 @@ test('with a mouse, the incoming bar covers the old title while the main thread
});
const cast = await startScreencast(page);
const row = await rowCenter(page, 'General');
+ const watch = await watchAnimations(card(page, 'screen-General'));
await page.mouse.click(row.x, row.y);
- await waitForAnimation(card(page, 'screen-General'), {minProgressMs: 16});
+ await watch.started({minProgressMs: 16});
const block = await blockMainThread(page, 900);
await page.waitForTimeout(150);
const frames = await cast.stop();
@@ -1886,8 +1889,9 @@ test('a push does no Layout or Paint per frame', async ({
requestAnimationFrame(waitForStart);
});
});
+ const watch = await watchAnimations(top);
await row.evaluate(element => (element as HTMLElement).click());
- [push] = await waitForAnimation(top);
+ [push] = await watch.started();
await waitForRest(top);
});
const motion = await page.evaluate(
@@ -1979,9 +1983,10 @@ test.describe('with Reduce Motion', () => {
test('a push cross-fades in place instead of sliding', async ({page}) => {
await page.emulateMedia({reducedMotion: 'reduce'});
const {driver} = await openStack(page, 'settings');
- await driver.tap(await rowCenter(page, 'General'));
const top = card(page, 'screen-General');
- await waitForAnimation(top);
+ const watch = await watchAnimations(top);
+ await driver.tap(await rowCenter(page, 'General'));
+ await watch.started();
const midway = await top.evaluate(element => ({
x: getComputedStyle(element).translate,
opacity: Number(getComputedStyle(element).opacity),
@@ -2037,9 +2042,10 @@ test('a large title scrolls under the bar, which then shows the title; scrolling
test('a pushed large title rides in with its screen', async ({page}) => {
const {driver} = await openStack(page, 'large-title');
- await driver.tap(await rowCenter(page, 'General'));
const top = card(page, 'screen-General');
- await waitForAnimation(top);
+ const watch = await watchAnimations(top);
+ await driver.tap(await rowCenter(page, 'General'));
+ await watch.started();
await waitForRest(top);
// The pushed screen here is inline; the root's large title stays with the
// root card, under it and to the left.
@@ -2109,9 +2115,10 @@ test('a back swipe carries the large titles: each rides its own screen', async (
page,
}) => {
const {driver, width, left} = await openStack(page, 'large-title');
- await driver.tap(await rowCenter(page, 'General'));
const top = card(page, 'screen-General');
- await waitForAnimation(top);
+ const watch = await watchAnimations(top);
+ await driver.tap(await rowCenter(page, 'General'));
+ await watch.started();
await waitForRest(top);
await expect(
page.getByRole('heading', {level: 1, name: 'Settings'}),
@@ -2270,10 +2277,11 @@ test('the bar title’s handover keeps running while the main thread is blocked'
expect(box).not.toBeNull();
await startBusyControl(page);
const cast = await startScreencast(page);
+ const watch = await watchAnimations(barText);
await card(page, 'root').evaluate(element =>
(element.firstElementChild as HTMLElement).scrollTo({top: 300}),
);
- const [fade] = await waitForAnimation(barText, {minProgressMs: 16});
+ const [fade] = await watch.started({minProgressMs: 16});
const block = await blockMainThread(page, 600, {
during: barText,
minProgressMs: 16,
@@ -2317,9 +2325,10 @@ test('the bar title’s handover keeps running while the main thread is blocked'
test('storyboard: a push', {tag: '@storyboard'}, async ({page}, testInfo) => {
const {driver, width} = await openStack(page, 'settings');
- await driver.tap(await rowCenter(page, 'General'));
const top = card(page, 'screen-General');
- await waitForAnimation(top);
+ const watch = await watchAnimations(top);
+ await driver.tap(await rowCenter(page, 'General'));
+ await watch.started();
const viewport = page.viewportSize() ?? {width: 402, height: 714};
const {storyboard} = await animationStoryboard(page, {
name: 'navigationstack-push',
diff --git a/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts b/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts
index 2e09aac425..f785f26875 100644
--- a/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts
+++ b/packages/lab/src/NavigationStack/__tests__/NavigationStackScrollEdge.interaction.browser.spec.ts
@@ -29,8 +29,8 @@ import {
openStory,
releaseAnimations,
touchDriver,
- waitForAnimation,
waitForRest,
+ watchAnimations,
withStorybook,
} from '@astryxdesign/interaction-harness';
@@ -311,8 +311,9 @@ test(
const layer = veil(page, 'root');
const viewport = page.viewportSize() ?? {width: 402, height: 714};
const clip = {x: 0, y: 0, width: viewport.width, height: 120};
+ const watch = await watchAnimations(layer);
await fingerScrollTo(page, 'root', 120);
- await waitForAnimation(layer);
+ await watch.started();
const {storyboard} = await animationStoryboard(page, {
name: 'navigation-stack-scroll-edge-appear',
clip,