-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathtest.utils.ts
More file actions
56 lines (49 loc) · 1.82 KB
/
test.utils.ts
File metadata and controls
56 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { expect } from '@playwright/test';
import type { E2EPage, ScreenshotFn } from '@utils/test/playwright';
/**
* Drag distances that reveal options without crossing the full swipe
* threshold (`optsWidth` + `SWIPE_MARGIN`). A narrower options panel
* requires a shorter drag.
*/
export const DRAG_DISTANCE_SINGLE_OPTION = 100;
export const DRAG_DISTANCE_MULTIPLE_OPTIONS = 150;
/**
* The number of drag steps used when revealing options. A higher step
* count slows the drag velocity, keeping it below the full swipe
* threshold in WebKit. See `dragElementBy` for more details.
*/
export const DRAG_STEPS_UNDER_FULL_SWIPE = 15;
/**
* Warning: This function will fail when in RTL mode.
* TODO(FW-3711): Remove the `directions` config when this issue preventing
* tests from passing in RTL mode is resolved.
*/
export const testSlidingItem = async (
page: E2EPage,
itemID: string,
screenshotNameSuffix: string,
screenshot: ScreenshotFn,
openStart = false
) => {
const item = page.locator(`#${itemID}`);
// passing a param into the eval callback is tricky due to execution context
// so just do the check outside the callback instead to make things easy
if (openStart) {
await item.evaluate(async (el: HTMLIonItemSlidingElement) => {
await el.open('start');
});
} else {
await item.evaluate(async (el: HTMLIonItemSlidingElement) => {
await el.open('end');
});
}
// opening animation takes longer than waitForChanges accounts for
// especially if another item sliding is already open,
// so we wait to ensure the opened item is closed before
// opening another
await page.waitForTimeout(500);
await expect(item).toHaveScreenshot(screenshot(`item-sliding-${screenshotNameSuffix}`));
await item.evaluate(async (el: HTMLIonItemSlidingElement) => {
await el.close();
});
};