feat: implement drag gesture in GestureSimulator
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -121,4 +121,28 @@ export class GestureSimulator {
|
||||
await this.page.waitForTimeout(100);
|
||||
await this.page.touchscreen.tap(x, y);
|
||||
}
|
||||
|
||||
async drag(options: DragOptions): Promise<void> {
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user