Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding project test #4012

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/ui/cluster-ui-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

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';
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');
Expand All @@ -33,5 +33,5 @@ describe('Extension cluster-dependant UI tests', function () {
checkExtension();
checkOpenshiftView();
loginTest();
createComponentTest(contextFolder);
projectTest();
});
16 changes: 16 additions & 0 deletions test/ui/common/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewItem> {
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();
Expand Down
18 changes: 0 additions & 18 deletions test/ui/suite/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion test/ui/suite/openshift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
98 changes: 98 additions & 0 deletions test/ui/suite/project.ts
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 { 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)}`
}

})
}
Loading