-
Notifications
You must be signed in to change notification settings - Fork 40.1k
Expand file tree
/
Copy pathsettings.ts
More file actions
97 lines (83 loc) · 3.99 KB
/
settings.ts
File metadata and controls
97 lines (83 loc) · 3.99 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Editor } from './editor';
import { Editors } from './editors';
import { Code } from './code';
import { QuickAccess } from './quickaccess';
import { Quality } from './application';
const SEARCH_BOX_NATIVE_EDIT_CONTEXT = '.settings-editor .suggest-input-container .monaco-editor .native-edit-context';
const SEARCH_BOX_TEXTAREA = '.settings-editor .suggest-input-container .monaco-editor textarea';
export class SettingsEditor {
constructor(private code: Code, private editors: Editors, private editor: Editor, private quickaccess: QuickAccess) { }
/**
* Write a single setting key value pair.
*
* Warning: You may need to set `editor.wordWrap` to `"on"` if this is called with a really long
* setting.
*/
async addUserSetting(setting: string, value: string): Promise<void> {
await this.openUserSettingsFile();
await this.code.dispatchKeybinding('right');
await this.editor.waitForEditorSelection('settings.json', this.acceptEditorSelection);
await this.editor.waitForTypeInEditor('settings.json', `"${setting}": ${value},`);
await this.editors.saveOpenedFile();
}
/**
* Write several settings faster than multiple calls to {@link addUserSetting}.
*
* Warning: You will likely also need to set `editor.wordWrap` to `"on"` if `addUserSetting` is
* called after this in the test.
*/
async addUserSettings(settings: [key: string, value: string][]): Promise<void> {
await this.openUserSettingsFile();
await this.code.dispatchKeybinding('right');
await this.editor.waitForEditorSelection('settings.json', this.acceptEditorSelection);
await this.editor.waitForTypeInEditor('settings.json', settings.map(v => `"${v[0]}": ${v[1]},`).join(''));
await this.editors.saveOpenedFile();
}
async clearUserSettings(): Promise<void> {
await this.openUserSettingsFile();
await this.quickaccess.runCommand('editor.action.selectAll');
await this.code.dispatchKeybinding('Delete');
await this.editor.waitForEditorContents('settings.json', contents => contents === '');
await this.editor.waitForTypeInEditor('settings.json', `{`); // will auto close }
await this.editors.saveOpenedFile();
await this.quickaccess.runCommand('workbench.action.closeActiveEditor');
}
async openUserSettingsFile(): Promise<void> {
await this.quickaccess.runCommand('workbench.action.openSettingsJson');
await this.editor.waitForEditorFocus('settings.json', 1);
}
async openUserSettingsUI(): Promise<void> {
await this.quickaccess.runCommand('workbench.action.openSettings2');
await this.code.waitForActiveElement(this._editContextSelector());
}
async searchSettingsUI(query: string): Promise<void> {
await this.openUserSettingsUI();
await this.code.waitAndClick(this._editContextSelector());
if (process.platform === 'darwin') {
await this.code.dispatchKeybinding('cmd+a');
} else {
await this.code.dispatchKeybinding('ctrl+a');
}
await this.code.dispatchKeybinding('Delete');
await this.code.waitForElements('.settings-editor .settings-count-widget', false, results => !results || (results?.length === 1 && !results[0].textContent));
await this.code.waitForTypeInEditor(this._editContextSelector(), query);
await this.code.waitForElements('.settings-editor .settings-count-widget', false, results => results?.length === 1 && results[0].textContent.includes('Found'));
}
private _editContextSelector() {
return this.code.quality === Quality.Stable ? SEARCH_BOX_TEXTAREA : SEARCH_BOX_NATIVE_EDIT_CONTEXT;
}
private acceptEditorSelection(s: {
selectionStart: number;
selectionEnd: number;
}): boolean {
if (this.code.quality === Quality.Stable) {
return true;
} else {
return s.selectionStart === 1 && s.selectionEnd === 1;
}
}
}