Skip to content

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

TypeScript

test(Lightbox): the pinch trace and the return film wait out their races (#10506)

Christopher Chedeau4b252590b8a9
diff --git a/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts b/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts
index 5ffaedadd3..2068496225 100644
--- a/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts
+++ b/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts
@@ -36,8 +36,10 @@ import {
drag,
flick,
frames,
+ freezePageOn,
freezePageWhen,
freezeTimers,
+ holdAnimations,
installLongTaskLog,
installPageFreeze,
installTimerGate,
@@ -53,7 +55,6 @@ import {
thawPage,
timeline,
touchDriver,
- touchStoryboard,
traceRendering,
trackMarker,
waitForAnimation,
@@ -1226,12 +1227,41 @@ test('the zoom settles and the pinch do no Layout or Paint per frame', async ({
const before = await state();
let zoom = {from: 0, to: 0};
let pinchWindow = {from: 0, to: 0};
- const trace = await traceRendering(page, async () => {
+ // The zoom is announced in a polite live region, the page's or the
+ // viewer's own, which empties 2 s later and lays out then. The pinch is
+ // traced once that has happened.
+ const politeRegions =
+ '[data-astryx-live-region="polite"], [data-astryx-modal-live-region="polite"]';
+ await page.evaluate(selector => {
+ const record = window as unknown as {zoomAnnounced?: boolean};
+ new MutationObserver(() => {
+ const regions = document.querySelectorAll(selector);
+ if (Array.from(regions).some(region => region.textContent !== '')) {
+ record.zoomAnnounced = true;
+ }
+ }).observe(document, {childList: true, characterData: true, subtree: true});
+ }, politeRegions);
+ const zoomTrace = await traceRendering(page, async () => {
await driver.play(
doubleTap({x: 201, y: before.stage.y + before.stage.height / 2}),
);
[zoom] = await waitForAnimation(photo);
await waitForRest(photo);
+ });
+ await expect
+ .poll(async () =>
+ page.evaluate(
+ selector =>
+ (window as unknown as {zoomAnnounced?: boolean}).zoomAnnounced ===
+ true &&
+ Array.from(document.querySelectorAll(selector)).every(
+ region => region.textContent === '',
+ ),
+ politeRegions,
+ ),
+ )
+ .toBe(true);
+ const pinchTrace = await traceRendering(page, async () => {
const start = Date.now();
await driver.play(
pinch({
@@ -1244,17 +1274,17 @@ test('the zoom settles and the pinch do no Layout or Paint per frame', async ({
);
pinchWindow = {from: start, to: Date.now()};
});
- const during = countBetween(trace, zoom.from + 50, zoom.to - 50);
+ const during = countBetween(zoomTrace, zoom.from + 50, zoom.to - 50);
expect(during.Layout ?? 0, JSON.stringify(during)).toBe(0);
expect(during.Paint ?? 0, JSON.stringify(during)).toBe(0);
// While the fingers move: no layout (a style write per event, composited).
const moving = countBetween(
- trace,
+ pinchTrace,
pinchWindow.from + 100,
pinchWindow.to - 150,
);
expect(moving.Layout ?? 0, JSON.stringify(moving)).toBe(0);
- expect(trace.longTasks).toEqual([]);
+ expect([...zoomTrace.longTasks, ...pinchTrace.longTasks]).toEqual([]);
});
test('the zoomed photo is redrawn sharp', async ({page}, testInfo) => {
@@ -1369,9 +1399,10 @@ test('the zoomed photo is redrawn sharp', async ({page}, testInfo) => {
});
test(
- 'storyboard: pinch to zoom and the return from past the minimum',
+ 'storyboard: the return from past the minimum',
{tag: '@storyboard'},
async ({page}, testInfo) => {
+ await installPageFreeze(page);
const {driver, photo, state} = await openViewer(page);
await installTimerGate(page);
const viewport = page.viewportSize() ?? {width: 402, height: 714};
@@ -1386,9 +1417,10 @@ test(
y: +now.y.toFixed(1),
};
};
- const spread = await touchStoryboard(
- page,
- driver,
+ // A pinch zooms in, then a squeeze past the minimum lets go. Only the
+ // return is filmed: a film of each gesture's steps takes longer than the
+ // test on a loaded runner.
+ await driver.play(
pinch({
center: centre,
fromDistance: 80,
@@ -1397,16 +1429,12 @@ test(
hz: 30,
restMs: 100,
}),
- {name: 'lightbox-pinch-zoom', clip, measure, columns: 5, cellScale: 0.4},
);
- // Armed before the squeeze, so the return is held as it starts.
- const hold = await armHold(page, photo, {
- judges: {target: photo, property: 'scale'},
- newOnly: true,
- });
- const squeeze = await touchStoryboard(
- page,
- driver,
+ await waitForRest(photo);
+ // Frozen in the lift's own task, the return starts held at its start, and
+ // the hold takes it there however late this process reacts.
+ await freezePageOn(page, 'touchend');
+ await driver.play(
pinch({
center: centre,
fromDistance: 300,
@@ -1415,15 +1443,11 @@ test(
hz: 30,
restMs: 100,
}),
- {
- name: 'lightbox-pinch-past-minimum',
- clip,
- measure,
- columns: 5,
- cellScale: 0.4,
- },
);
- const held = await hold.held();
+ const held = await holdAnimations(page, photo, {
+ judges: {target: photo, property: 'scale'},
+ });
+ await thawPage(page);
await freezeTimers(page);
const {storyboard: settle} = await animationStoryboard(page, {
name: 'lightbox-return-from-past-minimum',
@@ -1434,8 +1458,6 @@ test(
columns: 6,
cellScale: 0.35,
});
- await spread.write(testInfo);
- await squeeze.write(testInfo);
await settle.write(testInfo);
},
);