feat: implement pinch gesture in GestureSimulator

This commit is contained in:
张翔
2026-03-05 14:58:28 +08:00
parent 656480a95d
commit 302fafef49
2 changed files with 51 additions and 0 deletions
@@ -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();
});
});
+28
View File
@@ -69,4 +69,32 @@ export class GestureSimulator {
duration: 800,
});
}
async pinch(options: PinchOptions): Promise<void> {
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();
}
}