From 16a330b9d923b7f729395fd67ea89b5f1b03f3cd Mon Sep 17 00:00:00 2001 From: Lukas Grossmann Date: Tue, 19 Mar 2024 19:31:48 +0100 Subject: [PATCH 1/3] adding project test Signed-off-by: Lukas Grossmann --- test/ui/cluster-ui-test.ts | 6 ++- test/ui/common/conditions.ts | 16 ++++++ test/ui/suite/component.ts | 18 ------- test/ui/suite/project.ts | 98 ++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 test/ui/suite/project.ts diff --git a/test/ui/cluster-ui-test.ts b/test/ui/cluster-ui-test.ts index bc9ecf2a2..e78db5d86 100644 --- a/test/ui/cluster-ui-test.ts +++ b/test/ui/cluster-ui-test.ts @@ -5,10 +5,11 @@ import * as fs from 'fs-extra'; import * as path from 'path'; -import { createComponentTest } from './suite/component'; +//import { createComponentTest } from './suite/component'; import { checkExtension } from './suite/extension'; import { checkOpenshiftView } from './suite/openshift'; import { loginTest } from './suite/login'; +import { projectTest } from './suite/project'; describe('Extension cluster-dependant UI tests', function () { const kubeConfig = path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], '.kube', 'config'); @@ -33,5 +34,6 @@ describe('Extension cluster-dependant UI tests', function () { checkExtension(); checkOpenshiftView(); loginTest(); - createComponentTest(contextFolder); + projectTest(); + //createComponentTest(contextFolder); }); \ No newline at end of file diff --git a/test/ui/common/conditions.ts b/test/ui/common/conditions.ts index 0d0385558..e4865161a 100644 --- a/test/ui/common/conditions.ts +++ b/test/ui/common/conditions.ts @@ -46,6 +46,22 @@ export async function itemExists(title: string, view: ViewSection, timeout = 100 }, timeout); } +export async function itemHasText(title: string, text: string, view: ViewSection, timeout = 10_000 ): Promise { + return view.getDriver().wait(async () => { + try { + const item = await view.findItem(title); + if (item) { + const itemText = await item.getText(); + if (itemText.includes(text)) { + return item; + } + } + } catch (err) { + return null; + } + }, timeout) +} + export async function waitForInputProgress(input: InputBox, shouldExist: boolean, timeout = 5000) { return input.getDriver().wait(async () => { const hasProgress = await input.hasProgress(); diff --git a/test/ui/suite/component.ts b/test/ui/suite/component.ts index 41ac46cd0..296a1ce40 100644 --- a/test/ui/suite/component.ts +++ b/test/ui/suite/component.ts @@ -12,8 +12,6 @@ import { VIEWS, MENUS, NOTIFICATIONS, INPUTS, COMPONENTS } from '../common/const export function createComponentTest(contextFolder: string) { describe('Component creation', function () { - const cluster = process.env.CLUSTER_URL || 'https://api.crc.testing:6443'; - const clusterName = cluster; let view: SideBarView; let explorer: ViewSection; @@ -56,22 +54,6 @@ export function createComponentTest(contextFolder: string) { } }); - it('Create a new project', async function () { - this.timeout(30000); - await explorer.expand(); - const clusterItem = await explorer.findItem(clusterName) as TreeItem; - await clusterItem.expand(); - await new Promise((res) => { setTimeout(res, 2_500); }); - const menu = await clusterItem.openContextMenu(); - await menu.select(MENUS.newProject); - - const input = await InputBox.create(); - await input.setText(projectName); - await input.confirm(); - - await itemExists(projectName, explorer); - }); - it.skip('Create a new component from scratch', async function () { this.timeout(120_000); const newComponent = (await (await components.findWelcomeContent()).getButtons())[1]; diff --git a/test/ui/suite/project.ts b/test/ui/suite/project.ts new file mode 100644 index 000000000..aaec1f839 --- /dev/null +++ b/test/ui/suite/project.ts @@ -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 { SideBarView, ViewSection, EditorView, InputBox, ActivityBar, NotificationType, Workbench, TreeItem, VSBrowser } from 'vscode-extension-tester'; +import { itemExists, itemHasText, notificationExists } from '../common/conditions'; +import { INPUTS, NOTIFICATIONS, VIEWS } from '../common/constants'; +import { activateCommand } from '../common/command-activator'; +//import { expect } from 'chai'; + +export function projectTest() { + describe('Work with project', function () { + + const cluster = process.env.CLUSTER_URL || 'https://api.crc.testing:6443'; + const clusterName = cluster; + + let view: SideBarView; + let explorer: ViewSection; + + let projectName: string; + let anotherProjectName: string; + + before(async function () { + view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView(); + explorer = await view.getContent().getSection(VIEWS.appExplorer); + }); + + beforeEach(async function () { + const notificationCenter = await new Workbench().openNotificationsCenter(); + const notifications = await notificationCenter.getNotifications(NotificationType.Any); + if (notifications.length > 0) { + await notificationCenter.close(); + } + await new EditorView().closeAllEditors(); + }); + + it('Create a new project', async function () { + this.timeout(30_000); + await explorer.expand(); + const clusterItem = await explorer.findItem(clusterName) as TreeItem; + await clusterItem.expand(); + await activateCommand('>OpenShift: New Project') + + const input = await InputBox.create(); + projectName = getProjectName(); + await input.setText(projectName); + await input.confirm(); + + await itemExists(projectName, explorer); + }); + + it('Project can be changed', async function () { + this.timeout(30_000); + anotherProjectName = getProjectName(); + await activateCommand('>OpenShift: New Project'); + + let input = await InputBox.create(); + await input.setText(anotherProjectName); + await input.confirm(); + + const item = await itemExists(anotherProjectName, explorer) as TreeItem; + + const changeActiveProjectButton = await item.getActionButton('Change Active Project'); + await changeActiveProjectButton.click(); + + input = await InputBox.create(); + await new Promise((res) => {setTimeout(res, 1_000)}); + await input.setText(projectName); + await input.confirm(); + + await itemExists(projectName, explorer); + }); + + it('Delete a project', async function () { + this.timeout(30_000); + await activateCommand('>OpenShift: Delete Project'); + const input = await InputBox.create(); + await new Promise((res) => {setTimeout(res, 1_000)}); + await input.setText(projectName); + await input.confirm(); + + const notif = await notificationExists(NOTIFICATIONS.deleteProjectWarning(projectName), VSBrowser.instance.driver); + + await notif.takeAction(INPUTS.yes); + + await notificationExists(NOTIFICATIONS.projectDeleteSuccess(projectName), VSBrowser.instance.driver); + + await itemHasText(projectName, 'Missing Project. Create new or set active Project', explorer); + }); + + + function getProjectName() { + return `project${Math.floor(Math.random() * 100)}` + } + + }) +} \ No newline at end of file From 7be0310351880fec7525520413a62dc3ccf3b84d Mon Sep 17 00:00:00 2001 From: Lukas Grossmann Date: Wed, 27 Mar 2024 08:52:43 +0100 Subject: [PATCH 2/3] Skipping unstable and outdated tests Signed-off-by: Lukas Grossmann --- test/ui/suite/openshift.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/ui/suite/openshift.ts b/test/ui/suite/openshift.ts index a41f58f02..663fb13df 100644 --- a/test/ui/suite/openshift.ts +++ b/test/ui/suite/openshift.ts @@ -66,7 +66,8 @@ export function checkOpenshiftView() { }); }); - describe('Components', function() { + //Unstable and replaced by createComponent tests + describe.skip('Components', function() { let section: ViewSection; let welcome: WelcomeContentSection; From 82c73733c68e1debf02109ec346836fbc1196510 Mon Sep 17 00:00:00 2001 From: Lukas Grossmann Date: Wed, 3 Apr 2024 14:58:37 +0200 Subject: [PATCH 3/3] Remove unused import and test Signed-off-by: Lukas Grossmann --- test/ui/cluster-ui-test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/ui/cluster-ui-test.ts b/test/ui/cluster-ui-test.ts index e78db5d86..7acbad49d 100644 --- a/test/ui/cluster-ui-test.ts +++ b/test/ui/cluster-ui-test.ts @@ -5,7 +5,6 @@ import * as fs from 'fs-extra'; import * as path from 'path'; -//import { createComponentTest } from './suite/component'; import { checkExtension } from './suite/extension'; import { checkOpenshiftView } from './suite/openshift'; import { loginTest } from './suite/login'; @@ -35,5 +34,4 @@ describe('Extension cluster-dependant UI tests', function () { checkOpenshiftView(); loginTest(); projectTest(); - //createComponentTest(contextFolder); }); \ No newline at end of file