An open source design system that's fully customizable and agent ready
TypeScript
test(Lightbox): the coasting-photo landing stops the scene to land (#10466)
Christopher Chedeau23a18476438c
diff --git a/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.ts b/packages/core/src/Lightbox/__tests__/LightboxZoom.interaction.browser.spec.tsindex 3de4ac6f41..5ffaedadd3 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,+ freezePageWhen,freezeTimers,installLongTaskLog,+ installPageFreeze,installTimerGate,markElement,openStory,@@ -48,6 +50,7 @@ import {springStep,startBusyControl,startScreencast,+ thawPage,timeline,touchDriver,touchStoryboard,@@ -836,21 +839,57 @@ test('a zoomed flick coasts and stops at the far edge', async ({page}) => {test('a finger landing on a coasting photo stops it where it shows', async ({page,}) => {+ // The page clock that lets the scene stop mid-coast, before the story+ // loads.+ await installPageFreeze(page);const {driver, photo, state} = await openViewer(page);+ await installTimerGate(page);const before = await state();const mid = {x: 201, y: before.stage.y + before.stage.height / 2};await driver.play(doubleTap(mid));await waitForAnimation(photo);await waitForRest(photo);+ // The photo's offset at the flick's lift, read in the page.+ await recordLiftOffset(photo);+ await photo.evaluate(el => el.setAttribute('data-freeze-photo', ''));+ // The scene stops once the coast has carried the photo 10 px past the+ // lift, however late this process reacts. A poll from here can land the+ // finger after the coast ends.+ const coasting = freezePageWhen(+ page,+ () => {+ const lift = (globalThis as unknown as {__liftOffset?: number})+ .__liftOffset;+ const img = document.querySelector('[data-freeze-photo]') as Element;+ const translate = getComputedStyle(img).translate;+ const x = translate === 'none' ? 0 : parseFloat(translate);+ return (+ lift != null &&+ x < lift - 10 &&+ img.getAnimations().some(a => a.playState === 'running')+ );+ },+ undefined,+ );await driver.play(flick(mid, {velocity: {x: -900, y: 0}, durationMs: 80, hz: 120}),);- // The finger lands once the coast has carried the photo on past the- // release, then rests 250 ms and lifts without moving.- const released = (await state()).x;- await expect- .poll(async () => (await state()).x, {timeout: 2000})- .toBeLessThan(released - 10);+ await coasting;+ // The landing must find the coast still running, or it proves nothing.+ await photo.evaluate(el => {+ // The pointer event comes first, and the photo stops on it.+ window.addEventListener(+ 'pointerdown',+ () => {+ (globalThis as unknown as {coastAtTouch?: boolean}).coastAtTouch = el+ .getAnimations()+ .some(a => a.playState === 'running');+ },+ {capture: true, once: true},+ );+ });+ // The finger lands in the frozen scene. The scene thaws after the first+ // read, and the finger rests 250 ms and lifts without moving.const reads: PhotoState[] = [];await driver.play([@@ -858,11 +897,19 @@ test('a finger landing on a coasting photo stops it where it shows', async ({{t: 250, fingers: []},],{- onEvent: async () => {+ onEvent: async (_step, index) => {reads.push(await state());+ if (index === 0) {+ await thawPage(page);+ }},},);+ expect(+ await page.evaluate(+ () => (globalThis as unknown as {coastAtTouch?: boolean}).coastAtTouch,+ ),+ ).toBe(true);// Read at the touch-down and at the lift.expect(reads).toHaveLength(2);const [{x: caughtX}, {x: heldX, stage, fit, scale}] = reads;