From 029dc5ef6cfe481dbb08025cd3d5969bd3072e4c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 3 Jan 2025 16:22:01 -0800 Subject: [PATCH] fix lint snippets --- docs/src/touch-events.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/src/touch-events.md b/docs/src/touch-events.md index 881688e70c..2ee72f57b7 100644 --- a/docs/src/touch-events.md +++ b/docs/src/touch-events.md @@ -48,14 +48,16 @@ async function pan(locator: Locator, deltaX?: number, deltaY?: number, steps?: n clientX: centerX + deltaX * i / steps, clientY: centerY + deltaY * i / steps, }]; - await locator.dispatchEvent('touchmove', { touches, changedTouches: touches, targetTouches: touches }); + await locator.dispatchEvent('touchmove', + { touches, changedTouches: touches, targetTouches: touches }); } await locator.dispatchEvent('touchend'); } test(`pan gesture to move the map`, async ({ page }) => { - await page.goto('https://www.google.com/maps/place/@37.4117722,-122.0713234,15z', { waitUntil: 'commit' }); + await page.goto('https://www.google.com/maps/place/@37.4117722,-122.0713234,15z', + { waitUntil: 'commit' }); await page.getByRole('button', { name: 'Keep using web' }).click(); await expect(page.getByRole('button', { name: 'Keep using web' })).not.toBeVisible(); // Get the map element. @@ -77,7 +79,7 @@ import { test, expect, devices, type Locator } from '@playwright/test'; test.use({ ...devices['Pixel 7'] }); async function pinch(locator: Locator, - arg: { deltaX?: number, deltaY?: number, steps?: number, direction?: 'in' | 'out' }) { + arg: { deltaX?: number, deltaY?: number, steps?: number, direction?: 'in' | 'out' }) { const { centerX, centerY } = await locator.evaluate((target: HTMLElement) => { const bounds = target.getBoundingClientRect(); const centerX = bounds.left + bounds.width / 2; @@ -102,23 +104,26 @@ async function pinch(locator: Locator, clientY: centerY, }, ]; - await locator.dispatchEvent('touchstart', { touches, changedTouches: touches, targetTouches: touches }); + await locator.dispatchEvent('touchstart', + { touches, changedTouches: touches, targetTouches: touches }); // Move the touch points towards or away from each other. for (let i = 1; i <= steps; i++) { + const offset = (arg.direction === 'in' ? (deltaX - i * stepDeltaX) : (stepDeltaX * (i + 1))); const touches = [ { identifier: 0, - clientX: centerX - (arg.direction === 'in' ? (deltaX - i * stepDeltaX) : (stepDeltaX * (i + 1))), + clientX:centerX - offset, clientY: centerY, }, { identifier: 0, - clientX: centerX + (arg.direction === 'in' ? (deltaX - i * stepDeltaX) : (stepDeltaX * (i + 1))), + clientX: centerX + offset, clientY: centerY, }, ]; - await locator.dispatchEvent('touchmove', { touches, changedTouches: touches, targetTouches: touches }); + await locator.dispatchEvent('touchmove', + { touches, changedTouches: touches, targetTouches: touches }); } await locator.dispatchEvent('touchend', { touches: [], changedTouches: [], targetTouches: [] });