Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/automation/src/peek.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 References {
9
10
private static readonly REFERENCES_WIDGET = '.monaco-editor .zone-widget .zone-widget-container.peekview-widget.reference-zone-widget.results-loaded';
11
private static readonly REFERENCES_TITLE_FILE_NAME = `${References.REFERENCES_WIDGET} .head .peekview-title .filename`;
12
private static readonly REFERENCES_TITLE_COUNT = `${References.REFERENCES_WIDGET} .head .peekview-title .meta`;
13
private static readonly REFERENCES = `${References.REFERENCES_WIDGET} .body .ref-tree.inline .monaco-list-row .highlight`;
14
15
constructor(private code: Code) { }
16
17
async waitUntilOpen(): Promise<void> {
18
await this.code.waitForElement(References.REFERENCES_WIDGET);
19
}
20
21
async waitForReferencesCountInTitle(count: number): Promise<void> {
22
await this.code.waitForTextContent(References.REFERENCES_TITLE_COUNT, undefined, titleCount => {
23
const matches = titleCount.match(/\d+/);
24
return matches ? parseInt(matches[0]) === count : false;
25
});
26
}
27
28
async waitForReferencesCount(count: number): Promise<void> {
29
await this.code.waitForElements(References.REFERENCES, false, result => result && result.length === count);
30
}
31
32
async waitForFile(file: string): Promise<void> {
33
await this.code.waitForTextContent(References.REFERENCES_TITLE_FILE_NAME, file);
34
}
35
36
async close(): Promise<void> {
37
// Sometimes someone else eats up the `Escape` key
38
let count = 0;
39
while (true) {
40
41
try {
42
await this.code.dispatchKeybinding('escape', async () => { await this.code.waitForElement(References.REFERENCES_WIDGET, el => !el, 10); });
43
return;
44
} catch (err) {
45
if (++count > 5) {
46
throw err;
47
}
48
}
49
}
50
}
51
}
52
53