Skip to content

Commit

Permalink
Update ProjectList Cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-o0o committed Apr 25, 2024
1 parent d5464e3 commit 7f510a2
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 5 deletions.
137 changes: 132 additions & 5 deletions frontend/src/__tests__/cypress/cypress/e2e/projects/ProjectList.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ 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';

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

describe('Data science projects details', () => {
it('should not have option to create new project', () => {
Expand Down Expand Up @@ -44,18 +58,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 Down Expand Up @@ -108,6 +128,113 @@ 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();

// Verify initial run rows exist
projectListPage.getProjectRow('Test Project').should('exist');

// 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').should('exist');
});

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

// Verify initial run rows exist
projectListPage.getProjectRow('Test Project').should('exist');

// 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').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 7f510a2

Please sign in to comment.