Skip to content

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

TypeScript

test(Lightbox): the zoom proofs arm their holds before the gesture (#10480)

Christopher Chedeau8f4ddc13f020
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 c914f6885e..3de4ac6f41 100644
--- a/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts
+++ b/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts
@@ -25,6 +25,7 @@ import {PNG} from 'pngjs';
import {
CONTROL_RGB,
animationStoryboard,
+ armHold,
blockMainThread,
BusyWindowTooLateError,
busyWindowProof,
@@ -36,7 +37,6 @@ import {
flick,
frames,
freezeTimers,
- holdAnimations,
installLongTaskLog,
installTimerGate,
markElement,
@@ -559,6 +559,11 @@ test('past the minimum the zoom gives way, then springs back on springs.settle',
const centre = {x: 201, y: before.stage.y + before.stage.height / 2};
let shown = 1;
let pinchScale = 1;
+ // Armed before the lift starts the settle. A hold sent after it comes a
+ // round trip late, and a loaded runner can find the settle over.
+ const hold = await armHold(page, photo, {
+ judges: {target: photo, property: 'scale'},
+ });
await driver.play(
pinch({
center: centre,
@@ -582,10 +587,7 @@ test('past the minimum the zoom gives way, then springs back on springs.settle',
// (past its 8 px hysteresis); UIKit's law maps it to the shown zoom.
const recognizerScale = pinchScale / (300 - 8);
expect(shown).toBeCloseTo(1 / (2 - recognizerScale), 2);
- const [settle] = await waitForAnimation(photo);
- const held = await holdAnimations(page, photo, {
- judges: {target: photo, property: 'scale'},
- });
+ const held = await hold.held();
const duration = Math.max(...held.map(a => a.curveEndMs));
const samples = curveOf(
await sampleCurve(photo, timeline(duration)),
@@ -600,7 +602,7 @@ test('past the minimum the zoom gives way, then springs back on springs.settle',
'curves/lightbox-zoom-past-minimum',
{
[`${testInfo.project.name}.json`]: JSON.stringify(
- {settle, held, samples, result},
+ {held, samples, result},
null,
1,
),
@@ -681,11 +683,12 @@ test('a double tap zooms until the photo fills the screen, about the tapped poin
const before = await state();
const at = {x: 120, y: before.stage.y + before.stage.height / 2};
const tapped = photoPointAt(before, at);
- await driver.play(doubleTap(at));
- const [zoom] = await waitForAnimation(photo);
- const held = await holdAnimations(page, photo, {
+ // Armed before the taps, so the zoom is held as it starts.
+ const hold = await armHold(page, photo, {
judges: {target: photo, property: 'scale'},
});
+ await driver.play(doubleTap(at));
+ const held = await hold.held();
const duration = Math.max(...held.map(a => a.curveEndMs));
const samples = curveOf(
await sampleCurve(photo, timeline(duration)),
@@ -701,7 +704,7 @@ test('a double tap zooms until the photo fills the screen, about the tapped poin
'curves/lightbox-double-tap-zoom',
{
[`${testInfo.project.name}.json`]: JSON.stringify(
- {zoom, held, samples, result},
+ {held, samples, result},
null,
1,
),
@@ -1349,6 +1352,11 @@ test(
}),
{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,
@@ -1368,13 +1376,13 @@ test(
cellScale: 0.4,
},
);
- await waitForAnimation(photo);
+ const held = await hold.held();
await freezeTimers(page);
const {storyboard: settle} = await animationStoryboard(page, {
name: 'lightbox-return-from-past-minimum',
clip,
scope: photo,
- judges: {target: photo, property: 'scale'},
+ held,
measure,
columns: 6,
cellScale: 0.35,
@@ -1398,14 +1406,18 @@ test(
const now = await state();
return {scale: +now.scale.toFixed(3), x: +now.x.toFixed(1)};
};
+ // Armed before the taps, so the zoom is held as it starts.
+ const hold = await armHold(page, photo, {
+ judges: {target: photo, property: 'scale'},
+ });
await driver.play(doubleTap({x: 120, y: s.stage.y + s.stage.height / 2}));
- await waitForAnimation(photo);
+ const held = await hold.held();
await freezeTimers(page);
const {storyboard: zoomIn} = await animationStoryboard(page, {
name: 'lightbox-double-tap-zoom-in',
clip,
scope: photo,
- judges: {target: photo, property: 'scale'},
+ held,
measure,
columns: 6,
cellScale: 0.35,