-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathfixtures.ts
More file actions
53 lines (41 loc) · 1.16 KB
/
fixtures.ts
File metadata and controls
53 lines (41 loc) · 1.16 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
import type { Locator } from '@playwright/test';
import { expect } from '@playwright/test';
import type { E2EPage } from '@utils/test/playwright';
interface CheckRadioKeyboardOptions {
method: 'keyboard';
key: 'Space' | 'Enter';
selector?: string;
}
interface CheckRadioMouseOptions {
method: 'mouse';
selector?: string;
}
type CheckRadioOptions = CheckRadioKeyboardOptions | CheckRadioMouseOptions;
export class RadioFixture {
readonly page: E2EPage;
private radio!: Locator;
constructor(page: E2EPage) {
this.page = page;
}
async checkRadio(options: CheckRadioOptions) {
const { page } = this;
const selector = options.selector ?? 'ion-radio';
const radio = (this.radio = page.locator(selector));
if (options.method === 'keyboard') {
await radio.focus();
await page.keyboard.press(options.key);
} else {
await radio.click();
}
await page.waitForChanges();
return radio;
}
async expectChecked(state: boolean) {
const { radio } = this;
if (state) {
await expect(radio).toHaveClass(/radio-checked/);
} else {
await expect(radio).not.toHaveClass(/radio-checked/);
}
}
}