-
Notifications
You must be signed in to change notification settings - Fork 20
/
CustomEditor.ts
56 lines (50 loc) · 1.58 KB
/
CustomEditor.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
import { Key } from 'webdriverio'
import { Editor, InputBox } from '../index.js'
import { PageDecorator, IPageDecorator } from '../utils.js'
import { Editor as EditorLocators } from '../../locators/1.73.0.js'
import { CMD_KEY } from '../../constants.js'
export interface CustomEditor extends IPageDecorator<typeof EditorLocators> {}
/**
* Page object for custom editors
*
* @category Editor
*/
@PageDecorator(EditorLocators)
export class CustomEditor extends Editor<typeof EditorLocators> {
/**
* @private
*/
public locatorKey = 'Editor' as const
/**
* Check if the editor has unsaved changes
* @returns Promise resolving to true if there are unsaved changes, false otherwise
*/
async isDirty (): Promise<boolean> {
const tab = await this.getTab()
const klass = await tab.elem.getAttribute('class')
return klass.includes('dirty')
}
/**
* Save the editor
*/
async save (): Promise<void> {
await browser.action('key')
.down(CMD_KEY).down('s')
.up(CMD_KEY).up('s')
.perform()
}
/**
* Open the Save as prompt
*
* @returns InputBox serving as a simple file dialog
*/
async saveAs (): Promise<InputBox> {
await browser.action('key')
.down(CMD_KEY).down(Key.Shift).down('s')
.up(CMD_KEY).down(Key.Shift).up('s')
.perform()
const inputBox = browser.$(this.locatorMap.InputBox.elem as string)
await inputBox.waitForExist({ timeout: 5000 })
return new InputBox(this.locatorMap)
}
}