Skip to content

Commit

Permalink
Cypress e2e Test - Verifies users can start, stop, launch and delete …
Browse files Browse the repository at this point in the history
…a running workbench from project details page (#3637)

* Initial WIP version of resource creation test

* Experimental changes to poll the UI for updates

* Working version if resource is present

* increase card timeout and delete active wait

* Added changes to find namespace from variables

* Final changes to read variables, cleaned up utils

* Small change to a comment

* Dummy change to trigger mocks

* Save changes on cypress-RHOAIENG-12649

* Changed file directories and names as requested on a PR comment

* Saving changes to current branch

* Additional directory/file name changes

* Additional changes to save

* Resolving timeout issue breaking mock tests, also resolved latest PR comments

* Further changes for this test

* Changes to revert the exist method appended to getCardView.

* Fixed linting

* Linting fixes

* Final comments added

* Fixed merge conflict

* Small change to page object name

* dummy commit

* Removed RHOAI bug workaround

* Removed comments

* Last comment change

* Initial commit

* WIP Test

* Committing running test

---------

Co-authored-by: Fede Alonso <fealonso@redhat.com>
  • Loading branch information
antowaddle and FedeAlonso authored Jan 13, 2025
1 parent ebc2c66 commit 95d2b64
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# testWorkbenchControlSuite.cy.ts Test Data #
controlSuiteTestNamespace: 'dsp-wb-controls-test'
controlSuiteTestDescription: 'This is a test description.'
15 changes: 15 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ class NotebookConfirmModal extends Modal {
}
}

class NotebookDeleteModal extends Modal {
constructor() {
super('Delete workbench?');
}

findDeleteModal() {
return cy.get('[data-testid="delete-modal-input"]');
}

findDeleteWorkbenchButton() {
return cy.contains('span.pf-v6-c-button__text', 'Delete workbench');
}
}

class NotebookRow extends TableRow {
shouldHaveNotebookImageName(name: string) {
this.find().find(`[data-label="Notebook image"]`).find('span').should('have.text', name);
Expand Down Expand Up @@ -484,6 +498,7 @@ class NotFoundSpawnerPage {
export const workbenchPage = new WorkbenchPage();
export const createSpawnerPage = new CreateSpawnerPage();
export const notebookConfirmModal = new NotebookConfirmModal();
export const notebookDeleteModal = new NotebookDeleteModal();
export const editSpawnerPage = new EditSpawnerPage();
export const storageModal = new StorageModal();
export const notFoundSpawnerPage = new NotFoundSpawnerPage();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import type { WBControlSuiteTestData } from '~/__tests__/cypress/cypress/types';
import { projectDetails, projectListPage } from '~/__tests__/cypress/cypress/pages/projects';
import {
workbenchPage,
createSpawnerPage,
notebookConfirmModal,
notebookDeleteModal,
} from '~/__tests__/cypress/cypress/pages/workbench';
import { HTPASSWD_CLUSTER_ADMIN_USER } from '~/__tests__/cypress/cypress/utils/e2eUsers';
import { loadWBControlSuiteFixture } from '~/__tests__/cypress/cypress/utils/dataLoader';
import { createCleanProject } from '~/__tests__/cypress/cypress/utils/projectChecker';
import { deleteOpenShiftProject } from '~/__tests__/cypress/cypress/utils/oc_commands/project';

describe('Start, Stop, Launch and Delete a Workbench in RHOAI', () => {
let controlSuiteTestNamespace: string;
let controlSuiteTestDescription: string;

// Setup: Load test data and ensure clean state
before(() => {
return loadWBControlSuiteFixture('e2e/dataScienceProjects/testWorkbenchControlSuite.yaml')
.then((fixtureData: WBControlSuiteTestData) => {
controlSuiteTestNamespace = fixtureData.controlSuiteTestNamespace;
controlSuiteTestDescription = fixtureData.controlSuiteTestDescription;

if (!controlSuiteTestNamespace) {
throw new Error('Project name is undefined or empty in the loaded fixture');
}
cy.log(`Loaded project name: ${controlSuiteTestNamespace}`);
return createCleanProject(controlSuiteTestNamespace);
})
.then(() => {
cy.log(
`Project ${controlSuiteTestNamespace} confirmed to be created and verified successfully`,
);
});
});
after(() => {
// Delete provisioned Project
if (controlSuiteTestNamespace) {
cy.log(`Deleting Project ${controlSuiteTestNamespace} after the test has finished.`);
deleteOpenShiftProject(controlSuiteTestNamespace);
}
});

it(
'Starting, Stopping, Launching and Deleting a Workbench',
{ tags: ['@Sanity', '@SanitySet1', '@ODS-1818', '@ODS-1823', '@Dashboard'] },
() => {
const workbenchName = controlSuiteTestNamespace.replace('dsp-', '');

// Authentication and navigation
cy.step('Log into the application');
cy.visitWithLogin('/', HTPASSWD_CLUSTER_ADMIN_USER);

// Project navigation and select workbences
cy.step(`Navigate to workbenches tab of Project ${controlSuiteTestNamespace}`);
projectListPage.navigate();
projectListPage.filterProjectByName(controlSuiteTestNamespace);
projectListPage.findProjectLink(controlSuiteTestNamespace).click();
projectDetails.findSectionTab('workbenches').click();

// Create workbench
cy.step(`Create workbench ${controlSuiteTestNamespace}`);
workbenchPage.findCreateButton().click();
createSpawnerPage.getNameInput().fill(workbenchName);
createSpawnerPage.getDescriptionInput().type(controlSuiteTestDescription);
createSpawnerPage.findNotebookImage('code-server-notebook').click();
createSpawnerPage.findSubmitButton().click();

// Wait for workbench to run
cy.step(`Wait for workbench ${workbenchName} to display a "Running" status`);
const notebookRow = workbenchPage.getNotebookRow(workbenchName);
notebookRow.findNotebookDescription(controlSuiteTestDescription);
notebookRow.expectStatusLabelToBe('Running', 120000);
notebookRow.shouldHaveNotebookImageName('code-server');
notebookRow.shouldHaveContainerSize('Small');

// Stop workbench
cy.step('Stop workbench and validate it has been stopped');
notebookRow.findNotebookStop().click();
notebookConfirmModal.findStopWorkbenchButton().click();
notebookRow.expectStatusLabelToBe('Stopped', 120000);

// Restart workbench and confirm initiation
cy.step('Restart workbench and validate it starts successfully');
notebookRow.findNotebookStart().click();
notebookRow.expectStatusLabelToBe('Running', 120000);

// Delete workbench
cy.step('Delete workbench and confirm deleteion');
notebookRow.findKebab().click();
notebookRow.findKebabAction('Delete workbench').click();
notebookDeleteModal.findDeleteModal().click();
notebookDeleteModal.findDeleteModal().type(workbenchName);
notebookDeleteModal.findDeleteWorkbenchButton().click();
workbenchPage.findEmptyState().should('exist');
},
);
});
5 changes: 5 additions & 0 deletions frontend/src/__tests__/cypress/cypress/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export type WBEditTestData = {
pvcEditDisplayName: string;
};

export type WBControlSuiteTestData = {
controlSuiteTestNamespace: string;
controlSuiteTestDescription: string;
};

export type CommandLineResult = {
code: number;
stdout: string;
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/__tests__/cypress/cypress/utils/dataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
PVCReplacements,
ResourcesData,
WBEditTestData,
WBControlSuiteTestData,
} from '~/__tests__/cypress/cypress/types';

// Load fixture function that returns DataScienceProjectData
Expand Down Expand Up @@ -36,3 +37,12 @@ export const loadPVCEditFixture = (fixturePath: string): Cypress.Chainable<WBEdi
return data;
});
};
export const loadWBControlSuiteFixture = (
fixturePath: string,
): Cypress.Chainable<WBControlSuiteTestData> => {
return cy.fixture(fixturePath, 'utf8').then((yamlContent: string) => {
const data = yaml.load(yamlContent) as WBControlSuiteTestData;

return data;
});
};

0 comments on commit 95d2b64

Please sign in to comment.