Skip to content

Commit

Permalink
Merge pull request #2733 from ashley-o0o/cypress/ProjectList3836
Browse files Browse the repository at this point in the history
Update ProjectList Cypress test
  • Loading branch information
openshift-merge-bot[bot] authored May 2, 2024
2 parents 1b56d25 + ce57961 commit e7bb999
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 7 deletions.
135 changes: 128 additions & 7 deletions frontend/src/__tests__/cypress/cypress/e2e/projects/ProjectList.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,25 @@ import { createProjectModal, projectListPage } from '~/__tests__/cypress/cypress
import { deleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal';
import { ProjectKind } from '~/k8sTypes';
import { incrementResourceVersion } from '~/__mocks__/mockUtils';
import { ProjectModel, ProjectRequestModel } from '~/__tests__/cypress/cypress/utils/models';
import {
NotebookModel,
PodModel,
ProjectModel,
ProjectRequestModel,
RouteModel,
} from '~/__tests__/cypress/cypress/utils/models';
import { mock200Status } from '~/__mocks__/mockK8sStatus';
import { mockNotebookK8sResource, mockRouteK8sResource } from '~/__mocks__';
import { mockPodK8sResource } from '~/__mocks__/mockPodK8sResource';
import { asProjectAdminUser } from '~/__tests__/cypress/cypress/utils/users';
import { notebookConfirmModal } from '~/__tests__/cypress/cypress/pages/workbench';
import { testPagination } from '~/__tests__/cypress/cypress/utils/pagination';

const mockProject = mockProjectK8sResource({});
const initIntercepts = () => {
cy.interceptK8sList(ProjectModel, mockK8sResourceList([mockProject]));
};

describe('Data science projects details', () => {
it('should not have option to create new project', () => {
asProjectAdminUser({ isSelfProvisioner: false });
Expand Down Expand Up @@ -45,18 +59,24 @@ describe('Data science projects details', () => {
cy.url().should('include', '/projects/test-project');
});

it('should test url for workbench creation', () => {
initIntercepts();
projectListPage.visit();
projectListPage.findCreateWorkbenchButton().click();

cy.url().should('include', '/projects/test-project/spawner');
});

it('should list the new project', () => {
cy.interceptK8sList(ProjectModel, mockK8sResourceList([mockProjectK8sResource({})]));
initIntercepts();
projectListPage.visit();
projectListPage.shouldHaveProjects();
const projectRow = projectListPage.getProjectRow('Test Project');
projectRow.shouldHaveProjectIcon();
});

it('should delete project', () => {
const mockProject = mockProjectK8sResource({});
cy.interceptK8sList(ProjectModel, mockK8sResourceList([mockProject]));

initIntercepts();
projectListPage.visit();
projectListPage.getProjectRow('Test Project').findKebabAction('Delete project').click();
deleteModal.shouldBeOpen();
Expand All @@ -83,15 +103,15 @@ describe('Data science projects details', () => {

it('validate pagination', () => {
const totalItems = 50;
const mockProject: ProjectKind[] = Array.from({ length: totalItems }, (_, i) =>
const mockProjects: ProjectKind[] = Array.from({ length: totalItems }, (_, i) =>
mockProjectK8sResource({
k8sName: `ds-project-${i}`,
displayName: `DS Project ${i}`,
isDSProject: true,
}),
);
mockProjectK8sResource({});
cy.interceptK8sList(ProjectModel, mockK8sResourceList(mockProject));
cy.interceptK8sList(ProjectModel, mockK8sResourceList(mockProjects));
projectListPage.visit();

// top pagination
Expand Down Expand Up @@ -133,6 +153,107 @@ describe('Data science projects details', () => {
projectListPage.findProjectLink('DS Project 2').should('not.exist');
projectListPage.findProjectLink('renamed').should('not.exist');
});

describe('Table filter', () => {
it('filter by name', () => {
initIntercepts();
projectListPage.visit();

// Select the "Name" filter
const projectListToolbar = projectListPage.getTableToolbar();
projectListToolbar.findFilterMenuOption('filter-dropdown-select', 'Name').click();
projectListToolbar.findSearchInput().type('Test Project');
// Verify only rows with the typed run name exist
projectListPage.getProjectRow('Test Project').find().should('exist');
});

it('filter by user', () => {
initIntercepts();
projectListPage.visit();

// Select the "User" filter
const projectListToolbar = projectListPage.getTableToolbar();
projectListToolbar.findFilterMenuOption('filter-dropdown-select', 'User').click();
projectListToolbar.findSearchInput().type('test-user');
// Verify only rows with the typed run user exist
projectListPage.getProjectRow('Test Project').find().should('exist');
});
});

it('Validate that clicking on switch toggle will open modal to stop workbench', () => {
cy.interceptK8sList(ProjectModel, mockK8sResourceList([mockProjectK8sResource({})]));
cy.interceptK8s('PATCH', NotebookModel, mockNotebookK8sResource({})).as('stopWorkbench');
cy.interceptK8sList(PodModel, mockK8sResourceList([mockPodK8sResource({})]));
cy.interceptK8s(RouteModel, mockRouteK8sResource({ notebookName: 'test-notebook' })).as(
'getWorkbench',
);
cy.interceptK8sList(
{ model: NotebookModel, ns: 'test-project' },
mockK8sResourceList([
mockNotebookK8sResource({
opts: {
spec: {
template: {
spec: {
containers: [
{
name: 'test-notebook',
image: 'test-image:latest',
},
],
},
},
},
metadata: {
name: 'test-notebook',
labels: {
'opendatahub.io/notebook-image': 'true',
},
annotations: {
'opendatahub.io/image-display-name': 'Test image',
},
},
},
}),
]),
);
projectListPage.visit();
cy.wait('@getWorkbench');
const projectTableRow = projectListPage.getProjectRow('Test Project');
projectTableRow.findEnableSwitch().click();

//stop workbench
notebookConfirmModal.findStopWorkbenchButton().should('be.enabled');
cy.interceptK8s(
NotebookModel,
mockNotebookK8sResource({
opts: {
metadata: {
labels: {
'opendatahub.io/notebook-image': 'true',
},
annotations: {
'kubeflow-resource-stopped': '2023-02-14T21:45:14Z',
'opendatahub.io/image-display-name': 'Test image',
},
},
},
}),
);
cy.interceptK8sList(PodModel, mockK8sResourceList([mockPodK8sResource({ isRunning: false })]));

notebookConfirmModal.findStopWorkbenchButton().click();
cy.wait('@stopWorkbench').then((interception) => {
expect(interception.request.body).to.containSubset([
{
op: 'add',
path: '/metadata/annotations/kubeflow-resource-stopped',
},
]);
});
projectTableRow.findNotebookStatusText().should('have.text', 'Stopped ');
projectTableRow.findNotebookRouteLink().should('have.attr', 'aria-disabled', 'true');
});
});

const deletedMockProjectResource = (resource: ProjectKind): ProjectKind =>
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';
import { appChrome } from '~/__tests__/cypress/cypress/pages/appChrome';
import { DeleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal';
import { TableRow } from './components/table';
import { TableToolbar } from './components/TableToolbar';

class ProjectListToolbar extends TableToolbar {}
class NotebookRow extends TableRow {
findNotebookImageAvailability() {
return cy.findByTestId('notebook-image-availability');
Expand All @@ -21,6 +23,18 @@ class ProjectRow extends TableRow {
shouldHaveProjectIcon() {
return this.find().findByTestId('ds-project-image').should('exist');
}

findEnableSwitch() {
return this.find().pfSwitch('notebook-status-switch');
}

findNotebookRouteLink() {
return this.find().findByTestId('notebook-route-link');
}

findNotebookStatusText() {
return this.find().findByTestId('notebook-status-text');
}
}

class ProjectListPage {
Expand All @@ -44,6 +58,11 @@ class ProjectListPage {
return this;
}

shouldReturnNotFound() {
cy.findByTestId('not-found-page').should('exist');
return this;
}

shouldBeEmpty() {
cy.findByTestId('no-data-science-project').should('exist');
return this;
Expand All @@ -64,6 +83,22 @@ class ProjectListPage {
findProjectLink(projectName: string) {
return this.findProjectsTable().findByRole('link', { name: projectName });
}

findEmptyResults() {
return cy.findByTestId('no-result-found-title');
}

findSortButton(name: string) {
return this.findProjectsTable().find('thead').findByRole('button', { name });
}

getTableToolbar() {
return new ProjectListToolbar(() => cy.findByTestId('dashboard-table-toolbar'));
}

findCreateWorkbenchButton() {
return cy.findByRole('button', { name: 'Create a workbench' });
}
}

class CreateEditProjectModal extends Modal {
Expand Down

0 comments on commit e7bb999

Please sign in to comment.