Skip to content

Commit 28f5759

Browse files
committed
smoketest: improve preferences smoketest reliability
1 parent 5292f76 commit 28f5759

4 files changed

Lines changed: 39 additions & 35 deletions

File tree

test/smoke/src/areas/editor/editor.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function setup() {
1919
const app = this.app as Application;
2020
await app.workbench.quickopen.openFile('www');
2121

22-
const references = await app.workbench.editor.findReferences('app', 7);
22+
const references = await app.workbench.editor.findReferences('www', 'app', 7);
2323

2424
await references.waitForReferencesCountInTitle(3);
2525
await references.waitForReferencesCount(3);
@@ -53,7 +53,7 @@ export function setup() {
5353
const app = this.app as Application;
5454
await app.workbench.quickopen.openFile('app.js');
5555

56-
await app.workbench.editor.gotoDefinition('express', 11);
56+
await app.workbench.editor.gotoDefinition('app.js', 'express', 11);
5757

5858
await app.workbench.editors.waitForActiveTab('index.d.ts');
5959
});
@@ -62,7 +62,7 @@ export function setup() {
6262
const app = this.app as Application;
6363
await app.workbench.quickopen.openFile('app.js');
6464

65-
const peek = await app.workbench.editor.peekDefinition('express', 11);
65+
const peek = await app.workbench.editor.peekDefinition('app.js', 'express', 11);
6666

6767
await peek.waitForFile('index.d.ts');
6868
});

test/smoke/src/areas/editor/editor.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ import { Code } from '../../vscode/code';
1010
const RENAME_BOX = '.monaco-editor .monaco-editor.rename-box';
1111
const RENAME_INPUT = `${RENAME_BOX} .rename-input`;
1212
const EDITOR = filename => `.monaco-editor[data-uri$="${filename}"]`;
13+
const VIEW_LINES = filename => `${EDITOR(filename)} .view-lines`;
14+
const LINE_NUMBERS = filename => `${EDITOR(filename)} .margin .margin-view-overlays .line-numbers`;
1315

1416
export class Editor {
1517

16-
private static readonly VIEW_LINES = '.monaco-editor .view-lines';
17-
private static readonly LINE_NUMBERS = '.monaco-editor .margin .margin-view-overlays .line-numbers';
1818
private static readonly FOLDING_EXPANDED = '.monaco-editor .margin .margin-view-overlays>:nth-child(${INDEX}) .folding';
1919
private static readonly FOLDING_COLLAPSED = `${Editor.FOLDING_EXPANDED}.collapsed`;
2020

2121
constructor(private code: Code, private commands: Commands) { }
2222

23-
async findReferences(term: string, line: number): Promise<References> {
24-
await this.clickOnTerm(term, line);
23+
async findReferences(filename: string, term: string, line: number): Promise<References> {
24+
await this.clickOnTerm(filename, term, line);
2525
await this.commands.runCommand('Find All References');
2626
const references = new References(this.code);
2727
await references.waitUntilOpen();
2828
return references;
2929
}
3030

3131
async rename(filename: string, line: number, from: string, to: string): Promise<void> {
32-
await this.clickOnTerm(from, line);
32+
await this.clickOnTerm(filename, from, line);
3333
await this.commands.runCommand('Rename Symbol');
3434

3535
await this.code.waitForActiveElement(RENAME_INPUT);
@@ -38,53 +38,59 @@ export class Editor {
3838
await this.code.dispatchKeybinding('enter');
3939
}
4040

41-
async gotoDefinition(term: string, line: number): Promise<void> {
42-
await this.clickOnTerm(term, line);
41+
async gotoDefinition(filename: string, term: string, line: number): Promise<void> {
42+
await this.clickOnTerm(filename, term, line);
4343
await this.commands.runCommand('Go to Definition');
4444
}
4545

46-
async peekDefinition(term: string, line: number): Promise<References> {
47-
await this.clickOnTerm(term, line);
46+
async peekDefinition(filename: string, term: string, line: number): Promise<References> {
47+
await this.clickOnTerm(filename, term, line);
4848
await this.commands.runCommand('Peek Definition');
4949
const peek = new References(this.code);
5050
await peek.waitUntilOpen();
5151
return peek;
5252
}
5353

54-
async waitForHighlightingLine(line: number): Promise<void> {
55-
const currentLineIndex = await this.getViewLineIndex(line);
54+
async waitForHighlightingLine(filename: string, line: number): Promise<void> {
55+
const currentLineIndex = await this.getViewLineIndex(filename, line);
5656
if (currentLineIndex) {
5757
await this.code.waitForElement(`.monaco-editor .view-overlays>:nth-child(${currentLineIndex}) .current-line`);
5858
return;
5959
}
6060
throw new Error('Cannot find line ' + line);
6161
}
6262

63-
async getSelector(term: string, line: number): Promise<string> {
64-
const lineIndex = await this.getViewLineIndex(line);
65-
const classNames = await this.getClassSelectors(term, lineIndex);
66-
return `${Editor.VIEW_LINES}>:nth-child(${lineIndex}) span span.${classNames[0]}`;
63+
private async getSelector(filename: string, term: string, line: number): Promise<string> {
64+
const lineIndex = await this.getViewLineIndex(filename, line);
65+
const classNames = await this.getClassSelectors(filename, term, lineIndex);
66+
67+
return `${VIEW_LINES(filename)}>:nth-child(${lineIndex}) span span.${classNames[0]}`;
6768
}
6869

69-
async foldAtLine(line: number): Promise<any> {
70-
const lineIndex = await this.getViewLineIndex(line);
70+
async foldAtLine(filename: string, line: number): Promise<any> {
71+
const lineIndex = await this.getViewLineIndex(filename, line);
7172
await this.code.waitAndClick(Editor.FOLDING_EXPANDED.replace('${INDEX}', '' + lineIndex));
7273
await this.code.waitForElement(Editor.FOLDING_COLLAPSED.replace('${INDEX}', '' + lineIndex));
7374
}
7475

75-
async unfoldAtLine(line: number): Promise<any> {
76-
const lineIndex = await this.getViewLineIndex(line);
76+
async unfoldAtLine(filename: string, line: number): Promise<any> {
77+
const lineIndex = await this.getViewLineIndex(filename, line);
7778
await this.code.waitAndClick(Editor.FOLDING_COLLAPSED.replace('${INDEX}', '' + lineIndex));
7879
await this.code.waitForElement(Editor.FOLDING_EXPANDED.replace('${INDEX}', '' + lineIndex));
7980
}
8081

81-
async waitUntilShown(line: number): Promise<void> {
82-
await this.getViewLineIndex(line);
82+
private async clickOnTerm(filename: string, term: string, line: number): Promise<void> {
83+
const selector = await this.getSelector(filename, term, line);
84+
await this.code.waitAndClick(selector);
8385
}
8486

85-
async clickOnTerm(term: string, line: number): Promise<void> {
86-
const selector = await this.getSelector(term, line);
87-
await this.code.waitAndClick(selector);
87+
async waitForEditorFocus(filename: string, lineNumber: number, selectorPrefix = ''): Promise<void> {
88+
const editor = [selectorPrefix || '', EDITOR(filename)].join(' ');
89+
const line = `${editor} .view-lines > .view-line:nth-child(${lineNumber})`;
90+
const textarea = `${editor} textarea`;
91+
92+
await this.code.waitAndClick(line);
93+
await this.code.waitForActiveElement(textarea);
8894
}
8995

9096
async waitForTypeInEditor(filename: string, text: string, selectorPrefix = ''): Promise<any> {
@@ -105,14 +111,14 @@ export class Editor {
105111
return this.code.waitForTextContent(selector, undefined, c => accept(c.replace(/\u00a0/g, ' ')));
106112
}
107113

108-
private async getClassSelectors(term: string, viewline: number): Promise<string[]> {
109-
const elements = await this.code.waitForElements(`${Editor.VIEW_LINES}>:nth-child(${viewline}) span span`, false, els => els.some(el => el.textContent === term));
114+
private async getClassSelectors(filename: string, term: string, viewline: number): Promise<string[]> {
115+
const elements = await this.code.waitForElements(`${VIEW_LINES(filename)}>:nth-child(${viewline}) span span`, false, els => els.some(el => el.textContent === term));
110116
const { className } = elements.filter(r => r.textContent === term)[0];
111117
return className.split(/\s/g);
112118
}
113119

114-
private async getViewLineIndex(line: number): Promise<number> {
115-
const elements = await this.code.waitForElements(Editor.LINE_NUMBERS, false, els => {
120+
private async getViewLineIndex(filename: string, line: number): Promise<number> {
121+
const elements = await this.code.waitForElements(LINE_NUMBERS(filename), false, els => {
116122
return els.some(el => el.textContent === `${line}`);
117123
});
118124

test/smoke/src/areas/preferences/settings.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export enum ActivityBarPosition {
1616
}
1717

1818
const SEARCH_INPUT = '.settings-search-input input';
19-
const EDITOR = '.editable-preferences-editor-container .monaco-editor textarea';
2019

2120
export class SettingsEditor {
2221

@@ -27,8 +26,7 @@ export class SettingsEditor {
2726
await this.code.waitAndClick(SEARCH_INPUT);
2827
await this.code.waitForActiveElement(SEARCH_INPUT);
2928

30-
await this.code.dispatchKeybinding('down');
31-
await this.code.waitForActiveElement(EDITOR);
29+
await this.editor.waitForEditorFocus('settings.json', 1, '.editable-preferences-editor-container');
3230

3331
await this.code.dispatchKeybinding('right');
3432
await this.editor.waitForTypeInEditor('settings.json', `"${setting}": ${value}`, '.editable-preferences-editor-container');

test/smoke/src/areas/statusbar/statusbar.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function setup() {
7575
await app.workbench.quickopen.waitForQuickOpenOpened();
7676

7777
await app.workbench.quickopen.submit(':15');
78-
await app.workbench.editor.waitForHighlightingLine(15);
78+
await app.workbench.editor.waitForHighlightingLine('app.js', 15);
7979
});
8080

8181
it(`verifies if changing EOL is reflected in the status bar`, async function () {

0 commit comments

Comments
 (0)