-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathfixtures.ts
More file actions
78 lines (61 loc) · 2.19 KB
/
fixtures.ts
File metadata and controls
78 lines (61 loc) · 2.19 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { expect } from '@playwright/test';
import type { E2EPage, E2ELocator, EventSpy, E2EPageOptions, ScreenshotFn } from '@utils/test/playwright';
import type { SelectPopoverOption } from '../select-popover-interface';
export class SelectPopoverPage {
private page: E2EPage;
private multiple?: boolean;
private options: SelectPopoverOption[] = [];
// Locators
popover!: E2ELocator;
selectPopover!: E2ELocator;
// Event spies
ionPopoverDidDismiss!: EventSpy;
constructor(page: E2EPage) {
this.page = page;
}
async setup(config: E2EPageOptions, options: SelectPopoverOption[], multiple = false) {
const { page } = this;
await page.setContent(
`
<ion-popover>
<ion-select-popover></ion-select-popover>
</ion-popover>
<script>
const selectPopover = document.querySelector('ion-select-popover');
selectPopover.options = ${JSON.stringify(options)};
selectPopover.multiple = ${multiple};
</script>
`,
config
);
const ionPopoverDidPresent = await page.spyOnEvent('ionPopoverDidPresent');
this.ionPopoverDidDismiss = await page.spyOnEvent('ionPopoverDidDismiss');
this.popover = page.locator('ion-popover');
this.selectPopover = page.locator('ion-select-popover');
this.multiple = multiple;
this.options = options;
await this.popover.evaluate((popover: HTMLIonPopoverElement) => popover.present());
await ionPopoverDidPresent.next();
}
async screenshot(screenshot: ScreenshotFn, name: string) {
await expect(this.selectPopover).toHaveScreenshot(screenshot(name));
}
async clickOption(value: string) {
const option = this.getOption(value);
await option.click();
}
async pressSpaceOnOption(value: string) {
const option = this.getOption(value);
await option.press('Space');
}
async pressEnterOnOption(value: string) {
const option = this.getOption(value);
await option.press('Enter');
}
private getOption(value: string) {
const { multiple, selectPopover } = this;
const selector = multiple ? 'ion-checkbox' : 'ion-radio';
const index = this.options.findIndex((o) => o.value === value);
return selectPopover.locator(selector).nth(index);
}
}