Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: this keeps infinite and scroll-timeline animations too, and their finished never settles, so one inside the sheet would hold the proof until the 60 s test timeout. Nothing here runs one today. Keeping only animations with a finite end, as DropdownMenuItemAudit.a11y.chromium.spec.ts does, guards it:

.filter(
  animation =>
    animation.playState !== 'finished' &&
    Number.isFinite(Number(animation.effect?.getComputedTiming().endTime)),
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This copy stays identical to the one in #8209, and nothing in either element runs such an animation today. The follow-up that moves settlesAt into the interaction harness will keep only animations with a finite end, once for both specs.

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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 {
Expand Down
Loading