From 12ff5fc1f379df3cf4b0856276acd78decee41d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 5 Mar 2026 14:59:06 +0800 Subject: [PATCH] feat: implement long press and double tap gestures --- e2e/src/tests/utils/gesture-simulator.spec.ts | 20 ++++++++++++++++ e2e/src/utils/GestureSimulator.ts | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/e2e/src/tests/utils/gesture-simulator.spec.ts b/e2e/src/tests/utils/gesture-simulator.spec.ts index 8441616..27a9fec 100644 --- a/e2e/src/tests/utils/gesture-simulator.spec.ts +++ b/e2e/src/tests/utils/gesture-simulator.spec.ts @@ -54,4 +54,24 @@ test.describe('GestureSimulator - Swipe', () => { expect(transform).toBeTruthy(); }); + + test('should perform long press', async ({ page }) => { + await page.goto('/'); + const simulator = new GestureSimulator(page); + + const card = page.locator('.card').first(); + await simulator.longPress(card, 1000); + + await expect(card).toBeVisible(); + }); + + test('should perform double tap', async ({ page }) => { + await page.goto('/products'); + const simulator = new GestureSimulator(page); + + const image = page.locator('.product-image').first(); + await simulator.doubleTap(image); + + await expect(image).toBeVisible(); + }); }); \ No newline at end of file diff --git a/e2e/src/utils/GestureSimulator.ts b/e2e/src/utils/GestureSimulator.ts index 715f088..1202445 100644 --- a/e2e/src/utils/GestureSimulator.ts +++ b/e2e/src/utils/GestureSimulator.ts @@ -97,4 +97,28 @@ export class GestureSimulator { await this.page.touchscreen.touchEnd(); await this.page.touchscreen.touchEnd(); } + + async longPress(element: Locator, duration: number = 1000): Promise { + const box = await element.boundingBox(); + if (!box) throw new Error('Element not visible'); + + const x = box.x + box.width / 2; + const y = box.y + box.height / 2; + + await this.page.touchscreen.tap(x, y); + await this.page.waitForTimeout(duration); + await this.page.touchscreen.touchEnd(); + } + + async doubleTap(element: Locator): Promise { + const box = await element.boundingBox(); + if (!box) throw new Error('Element not visible'); + + const x = box.x + box.width / 2; + const y = box.y + box.height / 2; + + await this.page.touchscreen.tap(x, y); + await this.page.waitForTimeout(100); + await this.page.touchscreen.tap(x, y); + } } \ No newline at end of file