Skip to content

Commit

Permalink
Making projectTest runable on GHA
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Grossmann <[email protected]>
  • Loading branch information
Lukas Grossmann authored and vrubezhny committed Sep 10, 2024
1 parent 5ff9e8e commit 1d0fa85
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test/ui/cluster-ui-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ describe('Extension cluster-dependant UI tests', function () {
checkExtension();
checkOpenshiftView();
loginTest();
projectTest();
projectTest(true);
kubernetesContextTest();
});
5 changes: 5 additions & 0 deletions test/ui/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export const INPUTS = {

export const MENUS = {
newProject: 'New Project',
newNamespace: 'New Namespace',
delete: 'Delete',
deleteProject: 'Delete Project',
deleteNamespace: 'Delete Namespace',
bindService: 'Bind Service',
startDev: 'Start Dev',
startDevPodman: 'Start Dev on Podman',
Expand All @@ -65,7 +67,10 @@ export const COMPONENTS = {
export const NOTIFICATIONS = {
deleteProjectWarning: (projectName: string) =>
`Do you want to delete Project '${projectName}'?`,
deleteNamespaceWarning: (namespaceName: string) =>
`Do you want to delete Namespace '${namespaceName}'?`,
projectDeleteSuccess: (projectName: string) => `Project '${projectName}' successfully deleted`,
namespaceDeleteSuccess: (projectName: string) => `Namespace '${projectName}' successfully deleted`,
savePasswordPrompt: 'Do you want to save username and password?',
loginSuccess: (cluster: string) => `Successfully logged in to '${cluster}'`,
doYouWantLogOut: 'Do you want to logout of cluster?',
Expand Down
2 changes: 2 additions & 0 deletions test/ui/public-ui-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { testCreateServerlessFunction } from './suite/serverlessFunction';
import * as sourceMapSupport from 'source-map-support';
import { testComponentContextMenu } from './suite/componentContextMenu';
import { testComponentCommands } from './suite/componentCommands';
import { projectTest } from './suite/project';

sourceMapSupport.install();

Expand Down Expand Up @@ -49,5 +50,6 @@ describe('Extension public-facing UI tests', function() {
checkAboutCommand(clusterIsSet);
testComponentContextMenu();
testComponentCommands(contextFolder);
projectTest(false)
});
});
57 changes: 38 additions & 19 deletions test/ui/suite/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
*-----------------------------------------------------------------------------------------------*/

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 { itemExists, notificationExists } from '../common/conditions';
import { INPUTS, MENUS, NOTIFICATIONS, VIEWS } from '../common/constants';
//import { expect } from 'chai';

export function projectTest() {
export function projectTest(isOpenshiftCluster: boolean) {
describe('Work with project', function () {

const cluster = process.env.CLUSTER_URL || 'https://api.crc.testing:6443';
const clusterName = cluster;

const newProject = isOpenshiftCluster ? MENUS.newProject : MENUS.newNamespace;
const changeProject = isOpenshiftCluster ? 'Change Active Project' : 'Change Active Namespace';
const deleteProject = isOpenshiftCluster ? MENUS.deleteProject : MENUS.deleteNamespace;

let view: SideBarView;
let explorer: ViewSection;

Expand All @@ -24,6 +27,10 @@ export function projectTest() {
before(async function () {
view = await (await new ActivityBar().getViewControl(VIEWS.openshift)).openView();
explorer = await view.getContent().getSection(VIEWS.appExplorer);
await explorer.expand();
const actions = await explorer.getActions();
await actions[3].click();
await itemExists(clusterName, explorer);
});

beforeEach(async function () {
Expand All @@ -37,13 +44,15 @@ export function projectTest() {

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 contextMenu = await clusterItem.openContextMenu();
await contextMenu.select(newProject);

await new Promise((res) => { setTimeout(res, 500) });

const input = await InputBox.create();
projectName = getProjectName();
const input = await InputBox.create();
await input.setText(projectName);
await input.confirm();

Expand All @@ -53,15 +62,19 @@ export function projectTest() {
it('Project can be changed', async function () {
this.timeout(30_000);
anotherProjectName = getProjectName();
await activateCommand('>OpenShift: New Project');

const clusterItem = await explorer.findItem(clusterName) as TreeItem;
await clusterItem.expand();
const contextMenu = await clusterItem.openContextMenu();
await contextMenu.select(newProject);

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');
const changeActiveProjectButton = await item.getActionButton(changeProject);
await changeActiveProjectButton.click();

input = await InputBox.create();
Expand All @@ -74,25 +87,31 @@ export function projectTest() {

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 projectItem = await explorer.findItem(projectName);
const contextMenu = await projectItem.openContextMenu();

const notif = await notificationExists(NOTIFICATIONS.deleteProjectWarning(projectName), VSBrowser.instance.driver);
await contextMenu.select(deleteProject);

await notif.takeAction(INPUTS.yes);
let notif;

await notificationExists(NOTIFICATIONS.projectDeleteSuccess(projectName), VSBrowser.instance.driver);
if (isOpenshiftCluster) {
notif = await notificationExists(NOTIFICATIONS.deleteProjectWarning(projectName), VSBrowser.instance.driver)
} else {
notif = await notificationExists(NOTIFICATIONS.deleteNamespaceWarning(projectName), VSBrowser.instance.driver);
}

await itemHasText(projectName, 'Missing Project. Create new or set active Project', explorer);
await notif.takeAction(INPUTS.yes);

if (isOpenshiftCluster) {
await notificationExists(NOTIFICATIONS.projectDeleteSuccess(projectName), VSBrowser.instance.driver);
} else {
await notificationExists(NOTIFICATIONS.namespaceDeleteSuccess(projectName), VSBrowser.instance.driver);
}
});


function getProjectName() {
return `project${Math.floor(Math.random() * 100)}`
}

})
}

0 comments on commit 1d0fa85

Please sign in to comment.