-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
258 additions
and
23 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
98 changes: 98 additions & 0 deletions
98
test/ui/common/ui/webviewView/openshiftTerminalWebviewView.ts
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,98 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
import { By, Key, WebElement, WebviewView } from 'vscode-extension-tester'; | ||
import { WebviewViewForm } from './webviewViewForm'; | ||
|
||
export class OpenshiftTerminalWebviewView extends WebviewViewForm { | ||
|
||
public constructor() { | ||
super(); | ||
} | ||
|
||
public async getTerminalText(): Promise<string> { | ||
const copyKeys = [`${Key.CONTROL}${Key.SHIFT}a`,`${Key.CONTROL}${Key.SHIFT}c`] | ||
await this.sendKeysToTerminal(copyKeys); | ||
const cb = await import('clipboardy'); | ||
return await cb.read(); | ||
} | ||
|
||
public async getActiveTabName(): Promise<string> { | ||
let text: string; | ||
await this.enterWebviewView(async (webviewView) => { | ||
const activeTab = await this.getActiveTab(webviewView); | ||
text = await activeTab.getText(); | ||
}) | ||
return text; | ||
} | ||
|
||
public async closeTab(name: string): Promise<void> { | ||
await this.enterWebviewView(async (webviewView) => { | ||
const closeButton = await webviewView.findWebElement(By.xpath( | ||
`//div[div[contains(text(),"${name}")]]//*[@data-testid="CloseIcon"]` | ||
)); | ||
await closeButton.click(); | ||
}) | ||
} | ||
|
||
public async closeActiveTab(): Promise<void> { | ||
await this.enterWebviewView(async (webviewView) => { | ||
await webviewView.findWebElement(By.xpath('//button[@aria-selected = "true"]//*[@data-testid = "TerminalIcon"]')); | ||
}); | ||
} | ||
|
||
public async closeAllInactiveTabs(): Promise<void> { | ||
await this.enterWebviewView(async (webviewView) => { | ||
const closeButtons = await webviewView.findWebElements(By.xpath('//button[@aria-selected = "false"]//*[@data-testid = "TerminalIcon"]')); | ||
for (const button of closeButtons) { | ||
await button.click(); | ||
} | ||
}) | ||
} | ||
|
||
public async switchToTab(name: string): Promise<void> { | ||
await this.enterWebviewView(async (webviewView) => { | ||
const tabs = await this.getTerminalTabs(webviewView); | ||
for (const tab of tabs) { | ||
const text = await tab.getText(); | ||
if (text === name) { | ||
await tab.click(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public async sendKeysToTerminal(keys: string[]): Promise<void> { | ||
await this.enterWebviewView(async (webviewView) => { | ||
const terminal = await this.getTerminalInstance(webviewView); | ||
await terminal.click(); | ||
for (const key of keys) { | ||
await terminal.sendKeys(key); | ||
} | ||
}); | ||
} | ||
|
||
public async isAnyTabOpened(): Promise<boolean> { | ||
let tabs: WebElement[]; | ||
await this.enterWebviewView(async (webviewView) => { | ||
tabs = await this.getTerminalTabs(webviewView); | ||
}); | ||
return tabs.length > 0; | ||
} | ||
|
||
private async getActiveTab(webviewView: WebviewView): Promise<WebElement> { | ||
return await webviewView.findWebElement(By.xpath('//button[@aria-selected = "true"]//div[*[name() = "svg"]]/div')) | ||
} | ||
|
||
private async getTerminalTabs(webviewView: WebviewView): Promise<WebElement[]> { | ||
return await webviewView.findWebElements(By.xpath('//div[*[name() = "svg"]]/div')) | ||
} | ||
|
||
private async getTerminalInstance(webviewView: WebviewView): Promise<WebElement> { | ||
return await webviewView.findWebElement(By.xpath('//textarea[@aria-label = "Terminal input"]')); | ||
} | ||
|
||
|
||
|
||
} |
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,20 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
import { WebviewView } from 'vscode-extension-tester'; | ||
|
||
export abstract class WebviewViewForm { | ||
|
||
public async enterWebviewView<T>(callbackFunction: (webviewView: WebviewView) => Promise<T>): Promise<T> { | ||
const webviewView = new WebviewView(); | ||
await webviewView.switchToFrame(); | ||
let retValue: T; | ||
try { | ||
retValue = await callbackFunction(webviewView); | ||
} finally { | ||
await webviewView.switchBack(); | ||
} | ||
return retValue; | ||
} | ||
} |
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
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,118 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
import { | ||
ActivityBar, | ||
EditorView, | ||
Key, | ||
SideBarView, | ||
ViewItem, | ||
ViewSection, | ||
} from 'vscode-extension-tester'; | ||
import { collapse } from '../common/overdrives'; | ||
import { MENUS, VIEWS } from '../common/constants'; | ||
import { itemExists } from '../common/conditions'; | ||
import { OpenshiftTerminalWebviewView } from '../common/ui/webviewView/openshiftTerminalWebviewView'; | ||
import { expect } from 'chai'; | ||
|
||
export function testComponentContextMenu() { | ||
describe('Component Context Menu', function() { | ||
let view: SideBarView; | ||
let section: ViewSection; | ||
let component: ViewItem; | ||
let openshiftTerminal: OpenshiftTerminalWebviewView; | ||
|
||
const componentName = 'nodejs-starter'; | ||
const expectedTerminalName = `odo dev: ${componentName}`; | ||
|
||
before(async function context() { | ||
this.timeout(10_000); | ||
await new EditorView().closeAllEditors(); | ||
view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView(); | ||
for (const item of [ | ||
VIEWS.appExplorer, | ||
VIEWS.compRegistries, | ||
VIEWS.serverlessFunctions, | ||
VIEWS.debugSessions, | ||
]) { | ||
await collapse(await view.getContent().getSection(item)); | ||
} | ||
|
||
section = await view.getContent().getSection(VIEWS.components); | ||
}); | ||
|
||
it('Start Dev works', async function() { | ||
this.timeout(60_000) | ||
//start dev | ||
component = await itemExists(componentName, section); | ||
const contextMenu = await component.openContextMenu(); | ||
await contextMenu.select(MENUS.startDev); | ||
|
||
//check openshift terminal for tab name | ||
openshiftTerminal = new OpenshiftTerminalWebviewView(); | ||
const terminalName = await openshiftTerminal.getActiveTabName(); | ||
expect(terminalName).to.contain(expectedTerminalName) | ||
|
||
//decline odo telemetry | ||
await openshiftTerminal.sendKeysToTerminal(['n', Key.ENTER]) | ||
|
||
//wait for start dev to finish | ||
await itemExists(`${componentName} (dev starting)`, section); | ||
await itemExists(`${componentName} (dev running)`, section, 30_000); | ||
|
||
//check terminal content | ||
const terminalText = await openshiftTerminal.getTerminalText(); | ||
expect(terminalText).to.contain(`Developing using the "${componentName}" Devfile`); | ||
expect(terminalText).to.contain('Running on the cluster in Dev mode'); | ||
expect(terminalText).to.contain('Pod is Running'); | ||
expect(terminalText).to.contain('Waiting for the application to be ready'); | ||
expect(terminalText).to.contain('Keyboard Commands'); | ||
}); | ||
|
||
it('Stop Dev works', async function() { | ||
this.timeout(80_000); | ||
|
||
//stop dev | ||
const contextMenu = await component.openContextMenu(); | ||
await contextMenu.select(MENUS.stopDev); | ||
|
||
//wait for dev to stop | ||
await itemExists(`${componentName} (dev stopping)`, section); | ||
await itemExists(componentName, section, 60_000); | ||
|
||
//check for terminal content | ||
const terminalText = await openshiftTerminal.getTerminalText(); | ||
expect(terminalText).to.include('Finished executing the application'); | ||
expect(terminalText).to.include('Press any key to close this terminal'); | ||
|
||
//close tab and check | ||
await openshiftTerminal.sendKeysToTerminal([Key.ENTER]); | ||
expect(await openshiftTerminal.isAnyTabOpened()).to.be.false; | ||
}); | ||
|
||
it('Stop Dev works by pressing Ctrl+c', async function() { | ||
this.timeout(80_000) | ||
//start dev | ||
const contextMenu = await component.openContextMenu(); | ||
await contextMenu.select(MENUS.startDev); | ||
|
||
//wait for start dev to finish | ||
await itemExists(`${componentName} (dev starting)`, section); | ||
await itemExists(`${componentName} (dev running)`, section, 30_000); | ||
|
||
//stop dev | ||
await openshiftTerminal.sendKeysToTerminal([`${Key.CONTROL}c`]); | ||
|
||
//wait for stop dev to finish | ||
await itemExists(`${componentName} (dev stopping)`, section); | ||
await itemExists(componentName, section, 60_000); | ||
|
||
//check for terminal content | ||
const terminalText = await openshiftTerminal.getTerminalText(); | ||
expect(terminalText).to.include('Finished executing the application'); | ||
expect(terminalText).to.include('Press any key to close this terminal'); | ||
}) | ||
}); | ||
} |
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