Skip to content

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

TypeScript

test(interaction-harness): share settlesAt with waitForRest's deadline (#10606)

Christopher Chedeau5490c7c50993
diff --git a/internal/interaction-harness/README.md b/internal/interaction-harness/README.md
index 2fbc3c3d9f..e9149a7f85 100644
--- a/internal/interaction-harness/README.md
+++ b/internal/interaction-harness/README.md
@@ -58,21 +58,21 @@ committed: a pull request links or attaches it.
## Instruments
-| Module | What it gives a spec |
-| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `scripts.ts` | Touch scripts as data: `tap`, `drag` (hold, rest), `flick` (exact final-move speed, velocity profiles), `holdThenDrag`, `pinch`, `rotate`, `path`, `merge` (a second finger mid-gesture), `releaseVelocity`, `toTouchEvents`. |
-| `touch.ts` | `touchDriver(page).play(script)`: the script as real engine input. `installInputLog` / `readInputLog`: what the page received. |
-| `frames.ts` | `startScreencast` (timestamped composited frames), `markElement` (a marker chip or outline), `trackMarker` (marker box per frame), `trackMarkers` (several colors from one decode of each frame), `sampleRects` (per-rAF rects), `frameStats`, `requireFrames`. |
-| `busy.ts` | `blockMainThread(page, ms)`, which returns the window it held and the span its loop measured, and `busyWindowProof(tracked, window)`: frames presented, frames that moved, longest stall, a verdict; `presented` adds the compositor's own frames. |
-| `brightness.ts` | `trackBrightness(page, frames, {x, y})`: a colour channel's mean in a square per frame, as a scalar on `box.x`, for a busy-window proof of a fade or a dim. |
-| `webInput.ts` | `webInputDriver(page)`: `wheel({x, y, dx, dy, ctrl})` and `pen(points)` as real engine input, for proofs across pointers (`spec:AST-100` FR4); `wheel` resolves once the page has the step; read back through the input log. |
-| `trace.ts` | `traceRendering(page, body)`: main-thread counts of UpdateLayoutTree / Layout / PrePaint / Paint / Layerize / UpdateLayer / ScrollLayer / HitTest, `countBetween`, long tasks; `installLongTaskLog` / `readLongTasks`; `startCompositorTrace`: when the compositor presents. |
-| `curves.ts` | `holdAnimations`, `armHold`, `seekAnimations`, `sampleCurve` (presented transform / opacity at any t), `waitForAnimation`, `watchAnimations`, `waitForRest`, `releaseAnimations`, `releaseAnimationLog` (frees what the recorder kept, before a heap or listener count). |
-| `math.ts` | Oracles independent of the code under test: `cubicBezier`, `timingFunction`, `springStep` (SwiftUI response / dampingFraction, initial velocity), `projectDecay`, `rubberBand`, `parseTransform`, `compareCurve`, `timeline`. |
-| `storyboard.ts` | `animationStoryboard` (seek to t = 0, 16.7, 33.3 … ms), `touchStoryboard` (a frame per scripted event), `castStoryboard` (real screencast frames): PNG contact sheet + JSON trace. |
-| `output.ts` | `evidenceDir`, `writeEvidence`: where evidence goes and how it is attached to the report. |
-| `story.ts` | `phone`, `withStorybook`, `openStory`, `frames`, and the timer gate (`installTimerGate`, `freezeTimers`, `thawTimers`). |
-| `pointer.ts` | `newFinePointerPage(browser)`: a page under a mouse that really reads `(pointer: fine)`. `assertFinePointer` / `assertCoarsePointer`: fail before a case's checks when the page reads the other pointer. |
+| Module | What it gives a spec |
+| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `scripts.ts` | Touch scripts as data: `tap`, `drag` (hold, rest), `flick` (exact final-move speed, velocity profiles), `holdThenDrag`, `pinch`, `rotate`, `path`, `merge` (a second finger mid-gesture), `releaseVelocity`, `toTouchEvents`. |
+| `touch.ts` | `touchDriver(page).play(script)`: the script as real engine input. `installInputLog` / `readInputLog`: what the page received. |
+| `frames.ts` | `startScreencast` (timestamped composited frames), `markElement` (a marker chip or outline), `trackMarker` (marker box per frame), `trackMarkers` (several colors from one decode of each frame), `sampleRects` (per-rAF rects), `frameStats`, `requireFrames`. |
+| `busy.ts` | `blockMainThread(page, ms)`, which returns the window it held and the span its loop measured, and `busyWindowProof(tracked, window)`: frames presented, frames that moved, longest stall, a verdict; `presented` adds the compositor's own frames. |
+| `brightness.ts` | `trackBrightness(page, frames, {x, y})`: a colour channel's mean in a square per frame, as a scalar on `box.x`, for a busy-window proof of a fade or a dim. |
+| `webInput.ts` | `webInputDriver(page)`: `wheel({x, y, dx, dy, ctrl})` and `pen(points)` as real engine input, for proofs across pointers (`spec:AST-100` FR4); `wheel` resolves once the page has the step; read back through the input log. |
+| `trace.ts` | `traceRendering(page, body)`: main-thread counts of UpdateLayoutTree / Layout / PrePaint / Paint / Layerize / UpdateLayer / ScrollLayer / HitTest, `countBetween`, long tasks; `installLongTaskLog` / `readLongTasks`; `startCompositorTrace`: when the compositor presents. |
+| `curves.ts` | `holdAnimations`, `armHold`, `seekAnimations`, `sampleCurve` (presented transform / opacity at any t), `waitForAnimation`, `watchAnimations`, `waitForRest`, `settlesAt` (a computed value reached and every animation inside finished, on `waitForRest`'s deadline), `releaseAnimations`, `releaseAnimationLog` (frees what the recorder kept, before a heap or listener count). |
+| `math.ts` | Oracles independent of the code under test: `cubicBezier`, `timingFunction`, `springStep` (SwiftUI response / dampingFraction, initial velocity), `projectDecay`, `rubberBand`, `parseTransform`, `compareCurve`, `timeline`. |
+| `storyboard.ts` | `animationStoryboard` (seek to t = 0, 16.7, 33.3 … ms), `touchStoryboard` (a frame per scripted event), `castStoryboard` (real screencast frames): PNG contact sheet + JSON trace. |
+| `output.ts` | `evidenceDir`, `writeEvidence`: where evidence goes and how it is attached to the report. |
+| `story.ts` | `phone`, `withStorybook`, `openStory`, `frames`, and the timer gate (`installTimerGate`, `freezeTimers`, `thawTimers`). |
+| `pointer.ts` | `newFinePointerPage(browser)`: a page under a mouse that really reads `(pointer: fine)`. `assertFinePointer` / `assertCoarsePointer`: fail before a case's checks when the page reads the other pointer. |
## A fine pointer
diff --git a/internal/interaction-harness/src/curves.ts b/internal/interaction-harness/src/curves.ts
index 3d97fcae88..e02f62694d 100644
--- a/internal/interaction-harness/src/curves.ts
+++ b/internal/interaction-harness/src/curves.ts
@@ -5,16 +5,15 @@
* @input Uses a Playwright `Page`, a `Locator` for the animated element, and
* the Web Animations API in the page (CSS transitions and CSS animations are
* Web Animations too)
- * @output `holdAnimations` (pause every running animation and describe it),
- * `armHold` (the page holds what an action starts, as soon as it runs,
- * and checks that it took the motion the test judges),
- * `seekAnimations` (move them to t ms from the held origin, each keeping
- * its offset), `sampleCurve` (the presented
- * transform/opacity at each t, with the individual `translate`, `rotate` and
- * `scale` properties composed in), `releaseAnimations`, `curveOf`, which
- * picks one channel out of the samples for ./math's `compareCurve`, and the
- * animation-state waits `waitForAnimation`, `watchAnimations` and
- * `waitForRest`.
+ * @output `holdAnimations` pauses every running animation and describes it.
+ * `armHold` makes the page hold what an action starts, as soon as it runs,
+ * and checks that it took the motion the test judges. `seekAnimations`
+ * moves them to t ms from the held origin, each keeping its offset, and
+ * `releaseAnimations` lets them go. `sampleCurve` reads the presented
+ * transform/opacity at each t, with the individual `translate`, `rotate`
+ * and `scale` properties composed in. `curveOf` picks one channel out of
+ * the samples for ./math's `compareCurve`. The animation-state waits are
+ * `waitForAnimation`, `watchAnimations`, `waitForRest` and `settlesAt`.
* @position Curve sampling: the exact presented value of an animation at a
* fixed time, independent of frame timing, so a curve can be compared with
* the UIKit reference to a fraction of a pixel. A paused animation's effect
@@ -2213,3 +2212,188 @@ export async function waitForRest(
throw new Error('waitForRest: still moving at the deadline');
}
}
+
+/** What the page saw by the end of a `settlesAt` wait. */
+interface SettleOutcome {
+ readonly settled: boolean;
+ /** No frame came for longer than the starvation gap before the deadline. */
+ readonly starved: boolean;
+ /** The value the last check read. */
+ readonly seen: string;
+ /** The animations still unfinished, described for the error. */
+ readonly unfinished: readonly string[];
+ /** From the start of the wait to its end, ms. */
+ readonly spanMs: number;
+ /** From the last frame before the deadline to the deadline, ms. */
+ readonly unwatchedMs: number;
+}
+
+/**
+ * Resolves once `locator`'s element shows `property` at `value` and no
+ * animation inside it is left unfinished. Held final keyframes count until
+ * their end, where `waitForRest` reads them as rest. The page checks once a
+ * frame, on its real frames, so a frozen timer gate does not hold it.
+ *
+ * Its deadline is `waitForRest`'s. Past `timeout` ms it rejects, and names
+ * the property, the last value it read and the animations still unfinished.
+ * It throws `FrameStarvationError` with the same names instead when the
+ * page drew no frame for longer than `FRAME_STARVATION_MS` before the
+ * deadline. A stall after the deadline does not count, because the page was
+ * watched up to it. An animation that repeats forever never finishes, so a
+ * wait under one reaches the deadline.
+ */
+export async function settlesAt(
+ locator: Locator,
+ property: string,
+ value: string,
+ {timeout = 5_000}: {timeout?: number} = {},
+): Promise<void> {
+ // The page-side wait answers at its own deadline; the read gets a second
+ // more, so only an element that is gone runs it out.
+ const outcome = await withinTimeout(
+ 'settlesAt',
+ locator,
+ Date.now() + timeout + 1_000,
+ async evaluateTimeout =>
+ locator.evaluate(
+ (element, {prop, expected, ms, starvationMs}) =>
+ new Promise<SettleOutcome>(resolve => {
+ // The wait uses the page's real frames, timers and clock, so a
+ // frozen timer gate does not hold it.
+ const gate = (
+ window as unknown as {
+ __harnessTimerGate?: {
+ frame: typeof requestAnimationFrame;
+ now?: () => number;
+ timeout?: typeof setTimeout;
+ clearTimeout?: typeof clearTimeout;
+ };
+ }
+ ).__harnessTimerGate;
+ const frame = gate?.frame ?? requestAnimationFrame;
+ const realNow = gate?.now ?? (() => performance.now());
+ const later = gate?.timeout ?? setTimeout;
+ const clearTimer = gate?.clearTimeout ?? clearTimeout;
+ const startedAt = realNow();
+ const deadline = startedAt + ms;
+ let lastFrame = startedAt;
+ let seen = '';
+ let ended = false;
+ const unfinished = () =>
+ element
+ .getAnimations({subtree: true})
+ .filter(animation => animation.playState !== 'finished');
+ const describe = (animation: Animation) => {
+ const effect = animation.effect as KeyframeEffect | null;
+ const target = effect?.target ?? null;
+ const where =
+ target == null
+ ? 'no element'
+ : `${target.tagName.toLowerCase()}${target.id === '' ? '' : `#${target.id}`}${effect?.pseudoElement ?? ''}`;
+ const css = animation as Animation & {
+ transitionProperty?: string;
+ animationName?: string;
+ };
+ const label =
+ css.transitionProperty ?? css.animationName ?? animation.id;
+ const end = Number(
+ effect?.getComputedTiming().endTime ?? Infinity,
+ );
+ const at = Math.round(Number(animation.currentTime ?? 0));
+ const length = Number.isFinite(end)
+ ? `${Math.round(end)} ms`
+ : 'forever';
+ return `${animation.constructor.name}${label === '' ? '' : ` ${label}`} on ${where}, ${animation.playState} at ${at} of ${length}`;
+ };
+ const finish = (
+ settled: boolean,
+ starved: boolean,
+ unwatchedMs: number,
+ ) => {
+ ended = true;
+ clearTimer(deadlineTimer);
+ const listed = settled ? [] : unfinished().map(describe);
+ resolve({
+ settled,
+ starved,
+ seen,
+ unfinished:
+ listed.length > 5
+ ? [...listed.slice(0, 5), `${listed.length - 5} more`]
+ : listed,
+ spanMs: realNow() - startedAt,
+ unwatchedMs,
+ });
+ };
+ // A frame that never comes cannot reach the deadline check in
+ // `check`, so this timer gives the verdict instead.
+ const deadlineTimer = later(
+ () => {
+ if (!ended) {
+ const unwatched = Math.max(0, deadline - lastFrame);
+ finish(false, unwatched > starvationMs, unwatched);
+ }
+ },
+ ms + starvationMs + 1,
+ );
+ const check = (frameBefore: number) => {
+ seen = getComputedStyle(element).getPropertyValue(prop);
+ if (seen === expected && unfinished().length === 0) {
+ finish(true, false, 0);
+ } else if (realNow() > deadline) {
+ // Only the span from the frame before this one to the
+ // deadline went unwatched. A stall after the deadline does
+ // not hide the value read before it.
+ const unwatched = Math.max(0, deadline - frameBefore);
+ finish(false, unwatched > starvationMs, unwatched);
+ } else {
+ frame(onFrame);
+ }
+ };
+ const onFrame = () => {
+ if (!ended) {
+ const frameBefore = lastFrame;
+ lastFrame = realNow();
+ check(frameBefore);
+ }
+ };
+ check(startedAt);
+ }),
+ {
+ prop: property,
+ expected: value,
+ ms: timeout,
+ starvationMs: FRAME_STARVATION_MS,
+ },
+ {timeout: evaluateTimeout},
+ ),
+ );
+ if (outcome == null) {
+ throw new Error(
+ `settlesAt: ${property} did not settle at ${value} by the deadline, and the page did not answer`,
+ );
+ }
+ if (outcome.settled) {
+ return;
+ }
+ const read =
+ outcome.seen === value
+ ? `${property} read ${JSON.stringify(outcome.seen)}`
+ : `${property} read ${JSON.stringify(outcome.seen)} (not ${JSON.stringify(value)})`;
+ const running =
+ outcome.unfinished.length === 0
+ ? 'no animation under it was unfinished'
+ : `unfinished under it: ${outcome.unfinished.join('; ')}`;
+ if (outcome.starved) {
+ throw new FrameStarvationError({
+ by: 'settlesAt',
+ frames: 0,
+ during: `it looked for ${property} to settle at ${value} in the ${Math.round(outcome.unwatchedMs)} ms up to its deadline (${read}; ${running})`,
+ min: 1,
+ longestGapMs: outcome.unwatchedMs,
+ });
+ }
+ throw new Error(
+ `settlesAt: not settled ${Math.round(outcome.spanMs)} ms after it began: ${read}; ${running}`,
+ );
+}
diff --git a/internal/interaction-harness/src/harness.interaction.browser.spec.ts b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
index c8b79cbd1a..7184928b96 100644
--- a/internal/interaction-harness/src/harness.interaction.browser.spec.ts
+++ b/internal/interaction-harness/src/harness.interaction.browser.spec.ts
@@ -106,6 +106,7 @@ import {
sampleCurve,
sampleRects,
seekAnimations,
+ settlesAt,
springStep,
startCompositorTrace,
startScreencast,
@@ -4707,6 +4708,217 @@ test.describe('animation state', () => {
expect(parseTransform(transform).translateY).toBeCloseTo(100, 1);
});
+ test('settlesAt waits for the value, which can come after every animation has ended', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const box = page.locator('#box');
+ // No animation runs: a page timer sets the value 300 ms from now.
+ await box.evaluate(el => {
+ setTimeout(() => {
+ (el as HTMLElement).style.opacity = '0.25';
+ }, 300);
+ });
+ await settlesAt(box, 'opacity', '0.25');
+ expect(await box.evaluate(el => getComputedStyle(el).opacity)).toBe('0.25');
+ });
+
+ test('settlesAt resolves only once every animation inside the element has finished', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const box = page.locator('#box');
+ // The box fades for 300 ms, and a child inside it slides for 2 s. The
+ // value comes first, and the wait ends with the slide.
+ await box.evaluate(el => {
+ const child = document.createElement('div');
+ el.append(child);
+ child.animate(
+ [{transform: 'translateX(0px)'}, {transform: 'translateX(40px)'}],
+ {duration: 2000},
+ );
+ const target = el as HTMLElement;
+ target.style.transition = 'opacity 300ms linear';
+ void target.offsetWidth;
+ target.style.opacity = '0.5';
+ });
+ await settlesAt(box, 'opacity', '0.5');
+ const unfinished = await box.evaluate(
+ el =>
+ el
+ .getAnimations({subtree: true})
+ .filter(animation => animation.playState !== 'finished').length,
+ );
+ expect(unfinished).toBe(0);
+ });
+
+ test("settlesAt keeps checking while a frozen timer gate holds the page's frames", async ({
+ page,
+ }) => {
+ await fixture(page);
+ const box = page.locator('#box');
+ await installTimerGate(page);
+ await freezeTimers(page);
+ // Waits for real frames, which the frozen gate does not hold.
+ const realFrames = async (count: number) =>
+ page.evaluate(
+ async n =>
+ new Promise<void>(resolve => {
+ const {frame} = (
+ window as unknown as {
+ __harnessTimerGate: {frame: typeof requestAnimationFrame};
+ }
+ ).__harnessTimerGate;
+ let left = n;
+ const tick = () => {
+ left -= 1;
+ if (left <= 0) {
+ resolve();
+ } else {
+ frame(tick);
+ }
+ };
+ frame(tick);
+ }),
+ count,
+ );
+ let outcome: unknown = 'waiting';
+ const wait = settlesAt(box, 'opacity', '0.75').then(
+ () => {
+ outcome = 'settled';
+ },
+ (error: unknown) => {
+ outcome = error;
+ },
+ );
+ await realFrames(2);
+ await box.evaluate(el => {
+ (el as HTMLElement).style.opacity = '0.75';
+ });
+ // The wait answers on the first real frame after the change. That
+ // answer comes back before the answer to five more frames.
+ await realFrames(5);
+ expect(outcome).toBe('settled');
+ await wait;
+ await thawTimers(page);
+ });
+
+ test('settlesAt names the property, the last value and what still runs at its deadline', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const box = page.locator('#box');
+ const message = async (wait: Promise<void>) =>
+ wait.then(
+ () => 'settled',
+ (error: unknown) => (error as Error).message,
+ );
+ // The value never comes. A starved runner can leave the page unwatched
+ // before the deadline. Then FrameStarvationError carries the same names,
+ // so either error matches.
+ expect(
+ await message(settlesAt(box, 'opacity', '0.3', {timeout: 300})),
+ ).toMatch(
+ /^settlesAt: .*opacity read "1" \(not "0\.3"\); no animation under it was unfinished/,
+ );
+ // The value is there, but a child slides forever, so the box never
+ // settles.
+ await box.evaluate(el => {
+ const child = document.createElement('div');
+ child.id = 'slider';
+ el.append(child);
+ child.animate(
+ [{transform: 'translateX(0px)'}, {transform: 'translateX(40px)'}],
+ {duration: 400, iterations: Infinity},
+ );
+ });
+ expect(
+ await message(settlesAt(box, 'opacity', '1', {timeout: 300})),
+ ).toMatch(
+ /^settlesAt: .*opacity read "1"; unfinished under it: Animation on div#slider, running at \d+ of forever/,
+ );
+ });
+
+ test('settlesAt on a page starved of frames fails by name, with what it last read', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const box = page.locator('#box');
+ // Each frame now comes 1,000 ms after the one before, as on a starved
+ // machine.
+ await page.evaluate(() => {
+ const frame = window.requestAnimationFrame.bind(window);
+ window.requestAnimationFrame = callback => {
+ setTimeout(() => frame(callback), 1000);
+ return 0;
+ };
+ });
+ const outcome = await settlesAt(box, 'opacity', '0.3', {
+ timeout: 1500,
+ }).then(
+ () => 'settled',
+ (error: unknown) => error,
+ );
+ expect(outcome).toBeInstanceOf(FrameStarvationError);
+ const {numbers} = outcome as FrameStarvationError;
+ expect(numbers.frames).toBe(0);
+ expect(numbers.longestGapMs).toBeGreaterThan(FRAME_STARVATION_MS);
+ expect((outcome as Error).message).toMatch(
+ /^settlesAt: the page drew 0 frames while it looked for opacity to settle at 0\.3 in the \d+ ms up to its deadline \(opacity read "1" \(not "0\.3"\)/,
+ );
+ });
+
+ test('settlesAt does not name a stall that starts after its deadline as starvation', async ({
+ page,
+ }) => {
+ await fixture(page);
+ const box = page.locator('#box');
+ const stallMs = 500;
+ // Frames come on pace until the wait's deadline, 300 ms after its first
+ // frame request. The first frame after that then holds the main thread
+ // for 500 ms before the wait's check runs.
+ await page.evaluate(
+ ({timeoutMs, holdMs}) => {
+ const frame = window.requestAnimationFrame.bind(window);
+ let firstAt: number | null = null;
+ let stalled = false;
+ window.requestAnimationFrame = callback => {
+ firstAt ??= performance.now();
+ const stallAfter = firstAt + timeoutMs;
+ return frame(time => {
+ if (!stalled && performance.now() > stallAfter) {
+ stalled = true;
+ const end = performance.now() + holdMs;
+ while (performance.now() < end) {
+ // the page's main thread is busy
+ }
+ }
+ callback(time);
+ });
+ };
+ },
+ {timeoutMs: 300, holdMs: stallMs},
+ );
+ const outcome = await settlesAt(box, 'opacity', '0.3', {
+ timeout: 300,
+ }).then(
+ () => 'settled',
+ (error: unknown) => error,
+ );
+ // A starved runner can also leave the page unwatched before the
+ // deadline. That run proves nothing, so it fails by name.
+ if (
+ outcome instanceof FrameStarvationError &&
+ outcome.numbers.longestGapMs < stallMs
+ ) {
+ throw outcome;
+ }
+ expect(outcome).not.toBeInstanceOf(FrameStarvationError);
+ expect((outcome as Error).message).toMatch(
+ /^settlesAt: not settled \d+ ms after it began: opacity read "1" \(not "0\.3"\)/,
+ );
+ });
+
test("waitForAnimation's progress starts after a transition's delay", async ({
page,
}) => {
diff --git a/packages/core/src/DateInput/__tests__/MonthYearWheels.interaction.browser.spec.ts b/packages/core/src/DateInput/__tests__/MonthYearWheels.interaction.browser.spec.ts
index 3204cb7a8a..648df968a2 100644
--- a/packages/core/src/DateInput/__tests__/MonthYearWheels.interaction.browser.spec.ts
+++ b/packages/core/src/DateInput/__tests__/MonthYearWheels.interaction.browser.spec.ts
@@ -22,6 +22,7 @@ import {
import {
drag,
openStory,
+ settlesAt,
touchDriver,
withStorybook,
type TouchDriver,
@@ -30,43 +31,6 @@ import {WHEEL_ROW_HEIGHT} from '../wheelOptions';
const storybook = withStorybook(test);
-/**
- * Resolves once `locator`'s element shows `property` at `value` and no
- * animation inside it is left unfinished. The page checks the value once a
- * frame, then awaits each animation's own `finished` promise. It sets no
- * deadline of its own, so a starved runner only makes it later.
- */
-async function settlesAt(locator: Locator, property: string, value: string) {
- await locator.evaluate(
- async (element, [name, expected]) => {
- await new Promise<void>(resolve => {
- const check = () => {
- if (getComputedStyle(element).getPropertyValue(name) === expected) {
- resolve();
- } else {
- requestAnimationFrame(check);
- }
- };
- check();
- });
- for (;;) {
- const unfinished = element
- .getAnimations({subtree: true})
- .filter(animation => animation.playState !== 'finished');
- if (unfinished.length === 0) {
- return;
- }
- await Promise.all(
- unfinished.map(async animation =>
- animation.finished.catch(() => undefined),
- ),
- );
- }
- },
- [property, value] as const,
- );
-}
-
async function openWheels(page: Page) {
await openStory(
page,
diff --git a/packages/core/src/DateInput/__tests__/WheelActivation.interaction.browser.spec.ts b/packages/core/src/DateInput/__tests__/WheelActivation.interaction.browser.spec.ts
index 9ae235575a..ba2b60e73f 100644
--- a/packages/core/src/DateInput/__tests__/WheelActivation.interaction.browser.spec.ts
+++ b/packages/core/src/DateInput/__tests__/WheelActivation.interaction.browser.spec.ts
@@ -15,14 +15,10 @@
* a frame clock, never that count.
*/
-import {
- expect,
- test,
- type Locator,
- type Page,
-} from '@astryxdesign/a11y-spec/playwright';
+import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';
import {
openStory,
+ settlesAt,
touchDriver,
withStorybook,
} from '@astryxdesign/interaction-harness';
@@ -30,43 +26,6 @@ import {WHEEL_ROW_HEIGHT} from '../wheelOptions';
const storybook = withStorybook(test);
-/**
- * Resolves once `locator`'s element shows `property` at `value` and no
- * animation inside it is left unfinished. The page checks the value once a
- * frame, then awaits each animation's own `finished` promise. It sets no
- * deadline of its own, so a starved runner only makes it later.
- */
-async function settlesAt(locator: Locator, property: string, value: string) {
- await locator.evaluate(
- async (element, [name, expected]) => {
- await new Promise<void>(resolve => {
- const check = () => {
- if (getComputedStyle(element).getPropertyValue(name) === expected) {
- resolve();
- } else {
- requestAnimationFrame(check);
- }
- };
- check();
- });
- for (;;) {
- const unfinished = element
- .getAnimations({subtree: true})
- .filter(animation => animation.playState !== 'finished');
- if (unfinished.length === 0) {
- return;
- }
- await Promise.all(
- unfinished.map(async animation =>
- animation.finished.catch(() => undefined),
- ),
- );
- }
- },
- [property, value] as const,
- );
-}
-
interface Activation {
/** Year options listed, and the year rows drawn (each option is one). */
yearOptions: number;