-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #854 from zcervink/853
Create UI test for testing whether the autocompletion works
- Loading branch information
Showing
6 changed files
with
121 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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); | ||
|
@@ -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'); | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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]; | ||
} |