An open source design system that's fully customizable and agent ready
TypeScript
test(core): an edge press in a pager settle stops the scene to press (#10428)
Christopher Chedeau480c30c83182
diff --git a/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts b/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.tsindex 02a12cf9bd..ac50dcf621 100644--- a/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts+++ b/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts@@ -21,8 +21,12 @@ import {} from '@astryxdesign/a11y-spec/playwright';import {drag,+ freezePageWhen,+ installPageFreeze,+ installTimerGate,openStory,tap,+ thawPage,touchDriver,webInputDriver,withStorybook,@@ -43,8 +47,12 @@ async function open(page: Page,story: Story,mode: Mode,- {rtl = false}: {rtl?: boolean} = {},+ {rtl = false, freeze = false}: {rtl?: boolean; freeze?: boolean} = {},) {+ // A proof that stops the scene needs the page's clock before the story loads.+ if (freeze) {+ await installPageFreeze(page);+ }if (rtl) {await page.goto(`${storybook()}/iframe.html?id=core-carousel--${story}&viewMode=story&args=mode:${mode}&globals=direction:rtl`,@@ -355,8 +363,8 @@ test('an edge button steps about one view: the viewport less half an item, on th});/**- * Flicks the row (toward the start with `back`) and presses the edge button- * once the row shows past `until`; true if it was still held.+ * Flicks the row (toward the start with `back`), then presses the edge button+ * while the paging still holds the row past `until`. True if it was held.*/async function pressInSettle(page: Page,@@ -370,21 +378,32 @@ async function pressInSettle(if (next == null) {throw new Error('no edge button');}+ // The settle's frames go through the gate, so the freeze below holds them.+ await installTimerGate(page);+ await scroller.evaluate(el => el.setAttribute('data-press-in-settle', ''));await swipe(page, scroller, {px: 80, ms: 80, rtl: back});- const past = async () =>- scroller.evaluate(- (el, arg) => {- const first = el.firstElementChild as HTMLElement;- const shown =- el.getBoundingClientRect().left - first.getBoundingClientRect().left;- const isPast = arg.back ? shown < arg.until : shown >= arg.until;- return first.style.translate === '' || isPast;- },- {until, back},- );- await expect.poll(past, {intervals: [5]}).toBe(true);+ // The scene stops in the first frame where the paging holds the row past+ // `until`. A read from this process comes a round trip late, and a loaded+ // runner can miss the whole pass in that time. A settle that hands the row+ // back first fails here, by name.+ await freezePageWhen(+ page,+ ({at, isBack}) => {+ const el = document.querySelector('[data-press-in-settle]');+ const items = Array.from(el?.children ?? []) as HTMLElement[];+ if (el == null || items.length === 0) {+ return false;+ }+ const shown =+ el.getBoundingClientRect().left - items[0].getBoundingClientRect().left;+ const isHeld = items.some(item => item.style.translate !== '');+ return isHeld && (isBack ? shown < at : shown >= at);+ },+ {at: until, isBack: back},+ );const held = await isTakenOver(scroller);await page.mouse.click(next.x + next.width / 2, next.y + next.height / 2);+ await thawPage(page);return held;}@@ -405,7 +424,9 @@ async function restingOffset(scroller: Locator) {}test('an edge press late in a settle steps on to a stop', async ({page}) => {- const {scroller} = await open(page, 'snap-paging-three-up', 'paging');+ const {scroller} = await open(page, 'snap-paging-three-up', 'paging', {+ freeze: true,+ });const stops = await stopsOf(scroller);expect(await pressInSettle(page, scroller, stops[3] * 0.9)).toBe(true);const at = await restingOffset(scroller);@@ -418,7 +439,9 @@ for (const holdMs of [150, 40]) {test(`during an edge button's move, a ${holdMs} ms touch on the row ${holdMs > 85 ? 'stops it where it shows' : 'lets it run on'}, and the row rests on a stop`, async ({page,}) => {- const {scroller} = await open(page, 'snap-paging-three-up', 'paging');+ const {scroller} = await open(page, 'snap-paging-three-up', 'paging', {+ freeze: true,+ });const stops = await stopsOf(scroller);const box = await scroller.boundingBox();if (box == null) {@@ -440,7 +463,9 @@ test.describe('with a finger and a mouse', () => {test.use({hasTouch: true, isMobile: false});test('Shift+wheel during an edge press goes to a stop', async ({page}) => {- const {scroller} = await open(page, 'snap-paging-three-up', 'paging');+ const {scroller} = await open(page, 'snap-paging-three-up', 'paging', {+ freeze: true,+ });const stops = await stopsOf(scroller);expect(await pressInSettle(page, scroller, stops[3] * 0.9)).toBe(true);// Where the row shows at the wheel, and any native scroll while held.@@ -505,7 +530,9 @@ test.describe('with a finger and a mouse', () => {test('an edge press after a flick back near the end shows no space past the last item', async ({page,}) => {- const {scroller} = await open(page, 'snap-paging-three-up', 'paging');+ const {scroller} = await open(page, 'snap-paging-three-up', 'paging', {+ freeze: true,+ });const stops = await stopsOf(scroller);// One stop from the end, where the edge button still shows.await scroller.evaluate((el, left) => {