Skip to content

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

TypeScript

test(DateInput): the wheel activation proof waits on the sheet's own end, not on still frames before a deadline (#9942)

Christopher Chedeaud23d1fe43898
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 4a7b66656e..9ae235575a 100644
--- a/packages/core/src/DateInput/__tests__/WheelActivation.interaction.browser.spec.ts
+++ b/packages/core/src/DateInput/__tests__/WheelActivation.interaction.browser.spec.ts
@@ -15,17 +15,58 @@
* a frame clock, never that count.
*/
-import {expect, test, type Page} from '@astryxdesign/a11y-spec/playwright';
+import {
+ expect,
+ test,
+ type Locator,
+ type Page,
+} from '@astryxdesign/a11y-spec/playwright';
import {
openStory,
touchDriver,
- waitForRest,
withStorybook,
} from '@astryxdesign/interaction-harness';
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;
@@ -56,7 +97,12 @@ async function openMonthYearWheels(
});
const title = page.locator('[data-title="month-year"]');
await expect(title).toBeVisible();
- await waitForRest(page.locator('.astryx-bottom-sheet').first());
+ // The sheet rises to its open position, where its transform is the identity.
+ await settlesAt(
+ page.locator('.astryx-bottom-sheet').first(),
+ 'transform',
+ 'matrix(1, 0, 0, 1, 0, 0)',
+ );
const titleBox = await title.boundingBox();
if (titleBox == null) {
throw new Error('no month and year title');
@@ -97,7 +143,13 @@ async function openMonthYearWheels(
});
const years = page.getByRole('listbox', {name: 'Year'});
await expect(years).toBeVisible();
- await waitForRest(years.locator('[data-wheel-strip]'));
+ // The wheels fade in over the calendar. The year wheel parks its strip on
+ // its year as they show, so it rests once they do.
+ await settlesAt(
+ page.locator('[data-panel="wheels"]').first(),
+ 'opacity',
+ '1',
+ );
// The committed year is drawn where the wheel shows it.
await expect(years.getByRole('option', {selected: true})).toBeVisible();
return {