-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathEditorPanel.ts
More file actions
57 lines (50 loc) · 1.64 KB
/
Copy pathEditorPanel.ts
File metadata and controls
57 lines (50 loc) · 1.64 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
import { expect, type Locator, type Page } from "@playwright/test";
export class EditorPanel {
readonly monacoEditor: Locator;
private usingMonaco = true;
constructor(private page: Page) {
this.monacoEditor = page.locator(".monaco-editor").nth(0);
}
async enableMonaco(): Promise<void> {
await this.setMonaco(true);
}
async disableMonaco(): Promise<void> {
await this.setMonaco(false);
}
private async setMonaco(enabled: boolean): Promise<void> {
await this.page.locator('[data-tooltip="Settings"]').click();
const monacoSwitch = this.page.getByRole("switch", {
name: "Use Monaco Editor",
});
if ((await monacoSwitch.isChecked()) !== enabled) {
await monacoSwitch.click();
}
if (enabled) {
await expect(monacoSwitch).toBeChecked();
} else {
await expect(monacoSwitch).not.toBeChecked();
}
const closeButton = this.page.locator(".settings-dialog a.close");
await expect(closeButton).toBeVisible();
await closeButton.click();
this.usingMonaco = enabled;
}
async clearEditor(editor: string): Promise<void> {
if (this.usingMonaco) {
await this.monacoEditor.click();
await this.page.keyboard.press("Control+A");
await this.page.keyboard.press("Backspace");
await this.page.keyboard.press("Backspace");
} else {
await this.page.getByTestId(`editor-${editor}`).clear();
}
}
async write(text: string, editor: string): Promise<void> {
await this.clearEditor(editor);
if (this.usingMonaco) {
await this.page.keyboard.type(text);
} else {
await this.page.getByTestId(`editor-${editor}`).fill(text);
}
}
}