Skip to content

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

TypeScript

test(SnapPaging): a trackpad swipe reaches the page as one gesture (#10526)

Christopher Chedeauccb4a6dca4e5
diff --git a/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts b/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts
index f8a8f8457b..6b15789713 100644
--- a/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts
+++ b/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts
@@ -445,6 +445,12 @@ for (const mode of ['paging', 'item'] as const) {
const TRACKPAD_IN_CHROMIUM =
"Chromium's CDP wheels read as a mouse's wheel; the trackpad cases run in WebKit";
+/**
+ * How long after its last wheel the gesture host ends a horizontal trackpad
+ * scroll, ms. A gap this long or longer starts a new gesture.
+ */
+const TRACKPAD_SCROLL_END_MS = 220;
+
/**
* Reports a coarse primary pointer to script, before the story loads: a
* tablet with a trackpad, whose wheels a desktop context can inject.
@@ -492,15 +498,21 @@ for (const pointer of ['coarse', 'fine'] as const) {
throw new Error('no scroller');
}
const input = await webInputDriver(page);
- // 40 steps of 6.5 px, a trackpad's continuous scroll: 260 px, past half
- // of a view.
- for (let i = 0; i < 40; i++) {
- await input.wheel({
- x: box.x + box.width / 2,
- y: box.y + box.height / 2,
- dx: 6.5,
- });
- }
+ // 40 steps, 7 and 6 px in turn, one a frame: a trackpad's continuous
+ // scroll of 260 px, past half of a view. WebKit delivers whole px. A
+ // step that reaches the page after the scroll ended would start a
+ // second, shorter swipe, which settles back. So that gap fails here,
+ // by name.
+ await input.wheelBurst({
+ x: box.x + box.width / 2,
+ y: box.y + box.height / 2,
+ steps: Array.from({length: 40}, (_, i) => ({
+ dx: i % 2 === 0 ? 7 : 6,
+ })),
+ // WebKit stamps wheels in whole ms, so the longest gap that keeps
+ // one scroll is 1 ms shorter than the end.
+ maxGapMs: TRACKPAD_SCROLL_END_MS - 1,
+ });
await settled(scroller);
await expect
.poll(async () => offset(scroller))