From 302fafef49d35f6708f619a8825804aa1a7f244a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 5 Mar 2026 14:58:28 +0800 Subject: [PATCH] feat: implement pinch gesture in GestureSimulator --- e2e/src/tests/utils/gesture-simulator.spec.ts | 23 +++++++++++++++ e2e/src/utils/GestureSimulator.ts | 28 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/e2e/src/tests/utils/gesture-simulator.spec.ts b/e2e/src/tests/utils/gesture-simulator.spec.ts index f787d80..8441616 100644 --- a/e2e/src/tests/utils/gesture-simulator.spec.ts +++ b/e2e/src/tests/utils/gesture-simulator.spec.ts @@ -31,4 +31,27 @@ test.describe('GestureSimulator - Swipe', () => { const afterScrollY = await page.evaluate(() => window.scrollY); expect(afterScrollY).toBeLessThan(initialScrollY); }); + + test('should perform pinch zoom', async ({ page }) => { + await page.goto('/products'); + const simulator = new GestureSimulator(page); + + const image = page.locator('.product-image').first(); + await image.click(); + + await simulator.pinch({ + centerX: 200, + centerY: 300, + startDistance: 100, + endDistance: 50, + duration: 300, + }); + + const transform = await image.evaluate((el) => { + const style = window.getComputedStyle(el); + return style.transform; + }); + + expect(transform).toBeTruthy(); + }); }); \ No newline at end of file diff --git a/e2e/src/utils/GestureSimulator.ts b/e2e/src/utils/GestureSimulator.ts index c809255..715f088 100644 --- a/e2e/src/utils/GestureSimulator.ts +++ b/e2e/src/utils/GestureSimulator.ts @@ -69,4 +69,32 @@ export class GestureSimulator { duration: 800, }); } + + async pinch(options: PinchOptions): Promise { + const { centerX, centerY, startDistance, endDistance, duration } = options; + + const startDistanceX = startDistance / 2; + const startDistanceY = startDistance / 2; + const endDistanceX = endDistance / 2; + const endDistanceY = endDistance / 2; + + const steps = 10; + const stepDuration = duration / steps; + + await this.page.touchscreen.tap(centerX - startDistanceX, centerY - startDistanceY); + await this.page.touchscreen.tap(centerX + startDistanceX, centerY + startDistanceY); + + for (let i = 1; i <= steps; i++) { + const progress = i / steps; + const currentDistanceX = startDistanceX + (endDistanceX - startDistanceX) * progress; + const currentDistanceY = startDistanceY + (endDistanceY - startDistanceY) * progress; + + await this.page.touchscreen.touchMove(centerX - currentDistanceX, centerY - currentDistanceY); + await this.page.touchscreen.touchMove(centerX + currentDistanceX, centerY + currentDistanceY); + await this.page.waitForTimeout(stepDuration); + } + + await this.page.touchscreen.touchEnd(); + await this.page.touchscreen.touchEnd(); + } } \ No newline at end of file