From 531cd1567aa6a4975912b4e255997e86c6723a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Thu, 5 Mar 2026 15:04:29 +0800 Subject: [PATCH] feat: implement drag gesture in GestureSimulator --- e2e/src/tests/utils/gesture-simulator.spec.ts | 22 +++++++++++++++++ e2e/src/utils/GestureSimulator.ts | 24 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/e2e/src/tests/utils/gesture-simulator.spec.ts b/e2e/src/tests/utils/gesture-simulator.spec.ts index 27a9fec..9cda577 100644 --- a/e2e/src/tests/utils/gesture-simulator.spec.ts +++ b/e2e/src/tests/utils/gesture-simulator.spec.ts @@ -74,4 +74,26 @@ test.describe('GestureSimulator - Swipe', () => { await expect(image).toBeVisible(); }); + + test('should perform drag', async ({ page }) => { + await page.goto('/products'); + const simulator = new GestureSimulator(page); + + const firstCard = page.locator('.card').first(); + const secondCard = page.locator('.card').nth(1); + + const firstCardInitialPosition = await firstCard.boundingBox(); + + await simulator.drag({ + source: firstCard, + target: secondCard, + duration: 500, + }); + + const firstCardFinalPosition = await firstCard.boundingBox(); + + if (firstCardInitialPosition && firstCardFinalPosition) { + expect(firstCardFinalPosition.y).toBeGreaterThan(firstCardInitialPosition.y); + } + }); }); \ No newline at end of file diff --git a/e2e/src/utils/GestureSimulator.ts b/e2e/src/utils/GestureSimulator.ts index 1202445..38377d5 100644 --- a/e2e/src/utils/GestureSimulator.ts +++ b/e2e/src/utils/GestureSimulator.ts @@ -121,4 +121,28 @@ export class GestureSimulator { await this.page.waitForTimeout(100); await this.page.touchscreen.tap(x, y); } + + async drag(options: DragOptions): Promise { + const { source, target, duration } = options; + + const sourceBox = await source.boundingBox(); + const targetBox = await target.boundingBox(); + + if (!sourceBox || !targetBox) { + throw new Error('Source or target element not visible'); + } + + const startX = sourceBox.x + sourceBox.width / 2; + const startY = sourceBox.y + sourceBox.height / 2; + const endX = targetBox.x + targetBox.width / 2; + const endY = targetBox.y + targetBox.height / 2; + + await this.swipe({ + startX, + startY, + endX, + endY, + duration, + }); + } } \ No newline at end of file