Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/quickinput.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Code } from './code';
7
8
export class QuickInput {
9
10
private static QUICK_INPUT = '.quick-input-widget';
11
private static QUICK_INPUT_INPUT = `${QuickInput.QUICK_INPUT} .quick-input-box input`;
12
private static QUICK_INPUT_ROW = `${QuickInput.QUICK_INPUT} .quick-input-list .monaco-list-row`;
13
private static QUICK_INPUT_FOCUSED_ELEMENT = `${QuickInput.QUICK_INPUT_ROW}.focused .monaco-highlighted-label`;
14
// Note: this only grabs the label and not the description or detail
15
private static QUICK_INPUT_ENTRY_LABEL = `${QuickInput.QUICK_INPUT_ROW} .quick-input-list-row > .monaco-icon-label .label-name`;
16
private static QUICK_INPUT_ENTRY_LABEL_SPAN = `${QuickInput.QUICK_INPUT_ROW} .monaco-highlighted-label`;
17
18
constructor(private code: Code) { }
19
20
async waitForQuickInputOpened(retryCount?: number): Promise<void> {
21
await this.code.waitForActiveElement(QuickInput.QUICK_INPUT_INPUT, retryCount);
22
}
23
24
async type(value: string): Promise<void> {
25
await this.code.waitForSetValue(QuickInput.QUICK_INPUT_INPUT, value);
26
}
27
28
async waitForQuickInputElementFocused(): Promise<void> {
29
await this.code.waitForTextContent(QuickInput.QUICK_INPUT_FOCUSED_ELEMENT);
30
}
31
32
async waitForQuickInputElementText(): Promise<string> {
33
return this.code.waitForTextContent(QuickInput.QUICK_INPUT_ENTRY_LABEL_SPAN);
34
}
35
36
async closeQuickInput(): Promise<void> {
37
await this.code.dispatchKeybinding('escape', () => this.waitForQuickInputClosed());
38
}
39
40
async waitForQuickInputElements(accept: (names: string[]) => boolean): Promise<void> {
41
await this.code.waitForElements(QuickInput.QUICK_INPUT_ENTRY_LABEL, false, els => accept(els.map(e => e.textContent)));
42
}
43
44
async waitForQuickInputClosed(): Promise<void> {
45
await this.code.waitForElement(QuickInput.QUICK_INPUT, r => !!r && r.attributes.style.indexOf('display: none;') !== -1);
46
}
47
48
async selectQuickInputElement(index: number, keepOpen?: boolean): Promise<void> {
49
await this.waitForQuickInputOpened();
50
for (let from = 0; from < index; from++) {
51
await this.code.dispatchKeybinding('down', async () => { });
52
}
53
await this.code.dispatchKeybinding('enter', async () => {
54
if (!keepOpen) {
55
await this.waitForQuickInputClosed();
56
}
57
});
58
}
59
}
60
61