Skip to content

Commit

Permalink
Add tests for node resources table
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Jan 6, 2025
1 parent c8b53b0 commit 4f35e68
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 178 deletions.
13 changes: 10 additions & 3 deletions frontend/src/__mocks__/mockHardwareProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ export const mockHardwareProfile = ({
displayName = 'Nvidia GPU',
identifiers = [
{
displayName: 'Memory',
displayName: 'RAM',
identifier: 'memory',
minCount: '5Gi',
maxCount: '2Gi',
minCount: '2Gi',
maxCount: '5Gi',
defaultCount: '2Gi',
},
{
displayName: 'CPU',
identifier: 'cpu',
minCount: '1',
maxCount: '2',
defaultCount: '1',
},
],
description = '',
enabled = true,
Expand Down
61 changes: 61 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/hardwareProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ class HardwareProfile {
}
}

class NodeResourceRow extends TableRow {
shouldHaveResourceLabel(name: string) {
this.find().find(`[data-label="Resource label"]`).should('have.text', name);
return this;
}

shouldHaveResourceIdentifier(name: string) {
this.find().find(`[data-label="Resource identifier"]`).should('have.text', name);
return this;
}

findEditAction() {
return this.find().findByRole('button', { name: 'Edit node resource' });
}

findDeleteAction() {
return this.find().findByRole('button', { name: 'Remove node resource' });
}
}

class NodeSelectorRow extends TableRow {
shouldHaveKey(name: string) {
this.find().find(`[data-label=Key]`).should('have.text', name);
Expand Down Expand Up @@ -162,6 +182,10 @@ class ManageHardwareProfile {
return cy.findByTestId('add-node-selector-button');
}

findAddNodeResourceButton() {
return cy.findByTestId('add-node-resource-button');
}

findSubmitButton() {
return cy.findByTestId('hardware-profile-create-button');
}
Expand All @@ -174,6 +198,10 @@ class ManageHardwareProfile {
return cy.findByTestId('hardware-profile-node-selectors-table');
}

findNodeResourceTable() {
return cy.findByTestId('hardware-profile-node-resources-table');
}

getTolerationTableRow(name: string) {
return new TolerationRow(() =>
this.findTolerationTable().find(`[data-label=Key]`).contains(name).parents('tr'),
Expand All @@ -185,6 +213,15 @@ class ManageHardwareProfile {
this.findNodeSelectorTable().find(`[data-label=Key]`).contains(name).parents('tr'),
);
}

getNodeResourceTableRow(name: string) {
return new NodeResourceRow(() =>
this.findNodeResourceTable()
.find(`[data-label="Resource identifier"]`)
.contains(name)
.parents('tr'),
);
}
}

class CreateHardwareProfile extends ManageHardwareProfile {
Expand Down Expand Up @@ -307,11 +344,35 @@ class NodeSelectorModal extends Modal {
}
}

class NodeResourceModal extends Modal {
constructor(edit = false) {
super(edit ? 'Edit node resource' : 'Add node resource');
}

findNodeResourceLabelInput() {
return this.find().findByTestId('node-resource-label-input');
}

findNodeResourceIdentifierInput() {
return this.find().findByTestId('node-resource-identifier-input');
}

findNodeResourceExistingErrorMessage() {
return this.find().findByTestId('resource-identifier-error');
}

findNodeResourceSubmitButton() {
return this.find().findByTestId('modal-submit-button');
}
}

export const hardwareProfile = new HardwareProfile();
export const createHardwareProfile = new CreateHardwareProfile();
export const createTolerationModal = new TolerationModal(false);
export const editTolerationModal = new TolerationModal(true);
export const createNodeSelectorModal = new NodeSelectorModal(false);
export const editNodeSelectorModal = new NodeSelectorModal(true);
export const createNodeResourceModal = new NodeResourceModal(false);
export const editNodeResourceModal = new NodeResourceModal(true);
export const editHardwareProfile = new EditHardwareProfile();
export const duplicateHardwareProfile = new DuplicateHardwareProfile();
Loading

0 comments on commit 4f35e68

Please sign in to comment.