Skip to content

Commit

Permalink
Merge pull request #854 from zcervink/853
Browse files Browse the repository at this point in the history
Create UI test for testing whether the autocompletion works
  • Loading branch information
msivasubramaniaan authored Jan 4, 2023
2 parents 9125090 + 542375d commit 1a862dd
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 52 deletions.
25 changes: 25 additions & 0 deletions test/ui-test/Utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os = require('os');
import path = require('path');
import { StatusBar, By, WebElement } from 'vscode-extension-tester';

/**
* @author Zbynek Cervinka <[email protected]>
*/
export class Utilities {
public deleteFileInHomeDir(filename: string): void {
/* eslint-disable */
const fs = require('fs');
const homeDir = os.homedir();
const pathtofile = path.join(homeDir, filename);

if (fs.existsSync(pathtofile)) {
fs.rmSync(pathtofile, { recursive: true, force: true });
}
}

public async getSchemaLabel(text: string): Promise<WebElement> | undefined {
const statusbar = new StatusBar();
const schemalabel = await statusbar.findElements(By.xpath('.//a[@aria-label="' + text + ', Select JSON Schema"]'));
return schemalabel[0];
}
}
2 changes: 2 additions & 0 deletions test/ui-test/allTestsSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { extensionUIAssetsTest } from './extensionUITest';
import { contentAssistSuggestionTest } from './contentAssistTest';
import { customTagsTest } from './customTagsTest';
import { schemaIsSetTest } from './schemaIsSetTest';
import { autocompletionTest } from './autocompletionTest';

describe('VSCode YAML - UI tests', () => {
extensionUIAssetsTest();
contentAssistSuggestionTest();
customTagsTest();
schemaIsSetTest();
autocompletionTest();
});
50 changes: 50 additions & 0 deletions test/ui-test/autocompletionTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect } from 'chai';
import { WebDriver, VSBrowser, Key, InputBox, TextEditor, WebElement } from 'vscode-extension-tester';
import { Utilities } from './Utilities';

/**
* @author Zbynek Cervinka <[email protected]>
*/
export function autocompletionTest(): void {
describe('Verify autocompletion completes what should be completed', () => {
it('Autocompletion works as expected', async function () {
this.timeout(30000);

const driver: WebDriver = VSBrowser.instance.driver;
await driver.actions().sendKeys(Key.F1).perform();

let input = await InputBox.create();
await input.setText('>new file');
await input.confirm();
await input.confirm();

await driver.actions().sendKeys(Key.chord(TextEditor.ctlKey, 's')).perform();
input = await InputBox.create();
await input.setText('~/kustomization.yaml');
await input.confirm();

// wait until the schema is set and prepared
(await VSBrowser.instance.driver.wait(async () => {
this.timeout(10000);
const utils = new Utilities();
return await utils.getSchemaLabel('kustomization.yaml');
}, 10000)) as WebElement | undefined;

await driver.actions().sendKeys('api').perform();
await new TextEditor().toggleContentAssist(true);
await driver.actions().sendKeys(Key.ENTER).perform();

const editor = new TextEditor();
const text = await editor.getText();

if (text != 'apiVersion: ') {
expect.fail("The 'apiVersion: ' string has not been autocompleted.");
}
});

afterEach(async function () {
const utils = new Utilities();
utils.deleteFileInHomeDir('kustomization.yaml');
});
});
}
33 changes: 14 additions & 19 deletions test/ui-test/contentAssistTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path');
import os = require('os');
import { WebDriver, VSBrowser, Key, InputBox, TextEditor, ContentAssist } from 'vscode-extension-tester';
import { expect } from 'chai';
import { WebDriver, VSBrowser, Key, InputBox, TextEditor, ContentAssist, WebElement } from 'vscode-extension-tester';
import { Utilities } from './Utilities';

/**
* @author Zbynek Cervinka <[email protected]>
Expand All @@ -23,35 +23,30 @@ export function contentAssistSuggestionTest(): void {
await input.setText('~/kustomization.yaml');
await input.confirm();

await delay(2000);
await driver.actions().sendKeys('api').perform();
// wait until the schema is set and prepared
(await VSBrowser.instance.driver.wait(async () => {
this.timeout(10000);
const utils = new Utilities();
return await utils.getSchemaLabel('kustomization.yaml');
}, 10000)) as WebElement | undefined;

await driver.actions().sendKeys('api').perform();
const contentAssist: ContentAssist | void = await new TextEditor().toggleContentAssist(true);

// find if an item with given label is present
if (contentAssist instanceof ContentAssist) {
const hasItem = await contentAssist.hasItem('apiVersion');
if (!hasItem) {
throw new Error("The 'apiVersion' string did not appear in the content assist's suggestion list.");
expect.fail("The 'apiVersion' string did not appear in the content assist's suggestion list.");
}
} else {
throw new Error("The 'apiVersion' string did not appear in the content assist's suggestion list.");
expect.fail("The 'apiVersion' string did not appear in the content assist's suggestion list.");
}
});

afterEach(async function () {
/* eslint-disable */
const fs = require('fs');
const homeDir = os.homedir();
const pathtofile = path.join(homeDir, 'kustomization.yaml');

if (fs.existsSync(pathtofile)) {
fs.rmSync(pathtofile, { recursive: true, force: true });
}
const utils = new Utilities();
utils.deleteFileInHomeDir('kustomization.yaml');
});
});
}

function delay(milliseconds: number): Promise<number> {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
}
39 changes: 24 additions & 15 deletions test/ui-test/customTagsTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import path = require('path');
import os = require('os');
import { By, WebDriver, VSBrowser, Key, TextEditor, Workbench, InputBox, ContentAssist } from 'vscode-extension-tester';
import { expect } from 'chai';
import {
By,
WebDriver,
VSBrowser,
Key,
TextEditor,
Workbench,
InputBox,
ContentAssist,
WebElement,
} from 'vscode-extension-tester';
import { Utilities } from './Utilities';

/**
* @author Zbynek Cervinka <[email protected]>
Expand Down Expand Up @@ -29,10 +39,15 @@ export function customTagsTest(): void {

await driver.actions().sendKeys(Key.chord(TextEditor.ctlKey, 's')).perform();
input = await InputBox.create();
await input.setText('~/customTagsTestFile.yaml');
await input.setText('~/kustomization.yaml');
await input.confirm();

await delay(2000);
// wait until the schema is set and prepared
(await VSBrowser.instance.driver.wait(async () => {
this.timeout(30000);
const utils = new Utilities();
return await utils.getSchemaLabel('kustomization.yaml');
}, 30000)) as WebElement | undefined;
await driver.actions().sendKeys('custom').perform();

const contentAssist: ContentAssist | void = await new TextEditor().toggleContentAssist(true);
Expand All @@ -41,22 +56,16 @@ export function customTagsTest(): void {
if (contentAssist instanceof ContentAssist) {
const hasItem = await contentAssist.hasItem('customTag1');
if (!hasItem) {
throw new Error("The 'customTag1' custom tag did not appear in the content assist's suggestion list.");
expect.fail("The 'customTag1' custom tag did not appear in the content assist's suggestion list.");
}
} else {
throw new Error("The 'customTag1' custom tag did not appear in the content assist's suggestion list.");
expect.fail("The 'customTag1' custom tag did not appear in the content assist's suggestion list.");
}
});

afterEach(async function () {
/* eslint-disable */
const fs = require('fs');
const homeDir = os.homedir();
const pathtofile = path.join(homeDir, 'customTagsTestFile.yaml');

if (fs.existsSync(pathtofile)) {
fs.rmSync(pathtofile, { recursive: true, force: true });
}
const utils = new Utilities();
utils.deleteFileInHomeDir('kustomization.yaml');
});
});
}
Expand Down
24 changes: 6 additions & 18 deletions test/ui-test/schemaIsSetTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path = require('path');
import os = require('os');
import { WebDriver, VSBrowser, Key, InputBox, TextEditor, StatusBar, By, WebElement } from 'vscode-extension-tester';
import { WebDriver, VSBrowser, Key, InputBox, TextEditor, WebElement } from 'vscode-extension-tester';
import { Utilities } from './Utilities';

/**
* @author Zbynek Cervinka <[email protected]>
Expand All @@ -25,25 +24,14 @@ export function schemaIsSetTest(): void {

(await VSBrowser.instance.driver.wait(async () => {
this.timeout(10000);
return await getSchemaLabel({ text: 'kustomization.yaml' });
const utils = new Utilities();
return await utils.getSchemaLabel('kustomization.yaml');
}, 10000)) as WebElement | undefined;
});

afterEach(async function () {
/* eslint-disable */
const fs = require('fs');
const homeDir = os.homedir();
const pathtofile = path.join(homeDir, 'kustomization.yaml');

if (fs.existsSync(pathtofile)) {
fs.rmSync(pathtofile, { recursive: true, force: true });
}
const utils = new Utilities();
utils.deleteFileInHomeDir('kustomization.yaml');
});
});
}

async function getSchemaLabel({ text }: { text: string; }): Promise<WebElement> | undefined {
const statusbar = new StatusBar();
var schemalabel = await statusbar.findElements(By.xpath('.//a[@aria-label="' + text + ', Select JSON Schema"]'));
return schemalabel[0];
}

0 comments on commit 1a862dd

Please sign in to comment.