|
| 1 | +/*----------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Red Hat, Inc. All rights reserved. |
| 3 | + * Licensed under the MIT License. See LICENSE file in the project root for license information. |
| 4 | + *-----------------------------------------------------------------------------------------------*/ |
| 5 | +import { expect } from 'chai'; |
| 6 | +import { ActivityBar, CustomTreeSection, EditorView, InputBox, SideBarView, VSBrowser, ViewSection, WebDriver, Workbench } from 'vscode-extension-tester'; |
| 7 | +import { VIEWS } from '../common/constants'; |
| 8 | +import { RegistryWebViewEditor } from '../common/ui/webview/registryWebViewEditor'; |
| 9 | +import { notificationExists } from '../common/conditions'; |
| 10 | + |
| 11 | +export function testDevfileRegistries() { |
| 12 | + describe('Devfile Registries', () => { |
| 13 | + let view: SideBarView; |
| 14 | + let registrySection: ViewSection; |
| 15 | + let driver: WebDriver; |
| 16 | + |
| 17 | + before(async function context() { |
| 18 | + this.timeout(10000); |
| 19 | + driver = VSBrowser.instance.driver; |
| 20 | + view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView(); |
| 21 | + await new Promise(res => setTimeout(res, 5000)); |
| 22 | + await (await new Workbench().openNotificationsCenter()).clearAllNotifications(); |
| 23 | + registrySection = await view.getContent().getSection(VIEWS.compRegistries); |
| 24 | + }); |
| 25 | + |
| 26 | + it('registry actions are available', async function test() { |
| 27 | + this.timeout(5000); |
| 28 | + expect(await Promise.all((await registrySection.getActions()).map(async item => await item.getLabel()))).to.has.members(['Add Registry', 'Open Registry View', 'Refresh Components Types View']); |
| 29 | + }); |
| 30 | + |
| 31 | + it('default Devfile registry is present', async function test() { |
| 32 | + this.timeout(5000); |
| 33 | + await registrySection.expand(); |
| 34 | + const registry = await registrySection.findItem(VIEWS.devFileRegistry); |
| 35 | + expect(registry).not.undefined; |
| 36 | + expect(await registry.getText()).to.equal('DefaultDevfileRegistry'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('add new Devfile registry', async function test() { |
| 40 | + this.timeout(10000); |
| 41 | + const addAction = await registrySection.getAction('Add Registry'); |
| 42 | + await addAction.click(); |
| 43 | + const input = await InputBox.create(); |
| 44 | + // insert registry name into input box |
| 45 | + await input.setText('stageRegistry'); |
| 46 | + await input.confirm(); |
| 47 | + // insert staging devfile registry url |
| 48 | + await input.setText('https://stage.registry.devfile.io'); |
| 49 | + await input.confirm(); |
| 50 | + // pick unsecured registry |
| 51 | + await input.selectQuickPick('No'); |
| 52 | + await new Promise((res) => { setTimeout(res, 2000); }); |
| 53 | + // check registry exists |
| 54 | + await registrySection.expand(); |
| 55 | + const stageRegistry = await (registrySection as CustomTreeSection).findItem('stageRegistry'); |
| 56 | + expect(stageRegistry).not.undefined; |
| 57 | + }); |
| 58 | + |
| 59 | + it('edit existing Devfile registry', async function test() { |
| 60 | + this.timeout(10000); |
| 61 | + await registrySection.expand(); |
| 62 | + const stageRegistry = await (registrySection as CustomTreeSection).findItem('stageRegistry'); |
| 63 | + const menu = await stageRegistry.openContextMenu(); |
| 64 | + await (await menu.getItem('Edit')).select(); |
| 65 | + const input = await InputBox.create(); |
| 66 | + // insert registry name into input box |
| 67 | + await input.setText('editedRegistry'); |
| 68 | + await input.confirm(); |
| 69 | + // insert staging devfile registry url |
| 70 | + await input.setText('https://stage.registry.devfile.io'); |
| 71 | + await input.confirm(); |
| 72 | + // pick unsecured registry |
| 73 | + await input.selectQuickPick('No'); |
| 74 | + await new Promise((res) => { setTimeout(res, 2000); }); |
| 75 | + // check registry exists |
| 76 | + await registrySection.expand(); |
| 77 | + const editedRegistry = await (registrySection as CustomTreeSection).findItem('editedRegistry'); |
| 78 | + expect(editedRegistry).not.undefined; |
| 79 | + }); |
| 80 | + |
| 81 | + it('remove Devfile registry', async function test() { |
| 82 | + this.timeout(10000); |
| 83 | + await registrySection.expand(); |
| 84 | + let stageRegistry = await registrySection.findItem('editedRegistry'); |
| 85 | + const menu = await stageRegistry.openContextMenu(); |
| 86 | + await (await menu.getItem('Remove')).select(); |
| 87 | + // find and confirm notification about registry deletion |
| 88 | + const notification = await notificationExists('Remove registry \'editedRegistry\'?', driver); |
| 89 | + await notification.takeAction('Yes'); |
| 90 | + await new Promise((res) => { setTimeout(res, 2000); }); |
| 91 | + stageRegistry = await registrySection.findItem('editedRegistry'); |
| 92 | + expect(stageRegistry).is.undefined; |
| 93 | + }); |
| 94 | + |
| 95 | + it('open Devfile registry view from Section action', async function test() { |
| 96 | + this.timeout(10000); |
| 97 | + await (await registrySection.getAction('Open Registry View')).click(); |
| 98 | + // open editor tab by title |
| 99 | + const editorView = new EditorView(); |
| 100 | + const editor = await editorView.openEditor('Devfile Registry'); |
| 101 | + expect(await editor.getTitle()).to.include('Devfile Registry'); |
| 102 | + }); |
| 103 | + |
| 104 | + it('open Devfile registry view from item\'s context menu and verify the content of the registry', async function test() { |
| 105 | + this.timeout(10000); |
| 106 | + await new EditorView().closeAllEditors(); |
| 107 | + const devfileRegistry = await registrySection.findItem('DefaultDevfileRegistry'); |
| 108 | + await devfileRegistry.select(); |
| 109 | + const menu = await devfileRegistry.openContextMenu(); |
| 110 | + await (await menu.getItem('Open in Editor')).select(); |
| 111 | + await new Promise((res) => { setTimeout(res, 3000); }); |
| 112 | + // check opened editor tab by title |
| 113 | + const editorView = new EditorView(); |
| 114 | + const editor = await editorView.openEditor('Devfile Registry - DefaultDevfileRegistry'); |
| 115 | + expect(await editor.getTitle()).to.include('Devfile Registry - DefaultDevfileRegistry'); |
| 116 | + // initialize web view editor |
| 117 | + const webView = new RegistryWebViewEditor('Devfile Registry - DefaultDevfileRegistry'); |
| 118 | + await webView.initializeEditor(); |
| 119 | + expect(await webView.getRegistryStackNames()).to.include.members(['Quarkus Java', 'Node.js Runtime', 'Python', 'Maven Java', 'Vert.x Java', 'Go Runtime', 'React']); |
| 120 | + }); |
| 121 | + |
| 122 | + after(async function context() { |
| 123 | + this.timeout(10000); |
| 124 | + await (await new Workbench().openNotificationsCenter()).clearAllNotifications(); |
| 125 | + await new EditorView().closeAllEditors(); |
| 126 | + }); |
| 127 | + |
| 128 | + }); |
| 129 | +} |
0 commit comments