-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
Copy pathfixtures.ts
74 lines (58 loc) · 2.05 KB
/
fixtures.ts
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
import { expect } from '@playwright/test';
import type { E2ELocator, E2EPage, E2EPageOptions, EventSpy, ScreenshotFn } from '@utils/test/playwright';
import type { SelectModalOption } from '../select-modal-interface';
export class SelectModalPage {
private page: E2EPage;
private multiple?: boolean;
private options: SelectModalOption[] = [];
// Locators
modal!: E2ELocator;
selectModal!: E2ELocator;
// Event spies
ionModalDidDismiss!: EventSpy;
constructor(page: E2EPage) {
this.page = page;
}
async setup(config: E2EPageOptions, options: SelectModalOption[], multiple = false) {
const { page } = this;
await page.setContent(
`
<ion-modal>
<ion-select-modal></ion-select-modal>
</ion-modal>
<script>
const selectModal = document.querySelector('ion-select-modal');
selectModal.options = ${JSON.stringify(options)};
selectModal.multiple = ${multiple};
selectModal.closeText = 'Close me';
</script>
`,
config
);
const ionModalDidPresent = await page.spyOnEvent('ionModalDidPresent');
this.ionModalDidDismiss = await page.spyOnEvent('ionModalDidDismiss');
this.modal = page.locator('ion-modal');
this.selectModal = page.locator('ion-select-modal');
this.multiple = multiple;
this.options = options;
await this.modal.evaluate((modal: HTMLIonModalElement) => modal.present());
await ionModalDidPresent.next();
}
async screenshot(screenshot: ScreenshotFn, name: string) {
await expect(this.selectModal).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');
}
private getOption(value: string) {
const { multiple, selectModal } = this;
const selector = multiple ? 'ion-checkbox' : 'ion-radio';
const index = this.options.findIndex((o) => o.value === value);
return selectModal.locator(selector).nth(index);
}
}