Skip to content

Commit

Permalink
Add create/edit hardware profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
DaoDaoNoCode committed Dec 20, 2024
1 parent ca3be32 commit b61a5ce
Show file tree
Hide file tree
Showing 27 changed files with 1,746 additions and 166 deletions.
3 changes: 3 additions & 0 deletions frontend/src/__mocks__/mockHardwareProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type MockResourceConfigType = {
enabled?: boolean;
nodeSelectors?: NodeSelector[];
tolerations?: Toleration[];
annotations?: Record<string, string>;
};

export const mockHardwareProfile = ({
Expand Down Expand Up @@ -49,6 +50,7 @@ export const mockHardwareProfile = ({
value: 'va;ue',
},
],
annotations,
}: MockResourceConfigType): HardwareProfileKind => ({
apiVersion: 'dashboard.opendatahub.io/v1alpha1',
kind: 'HardwareProfile',
Expand All @@ -59,6 +61,7 @@ export const mockHardwareProfile = ({
namespace,
resourceVersion: '1309350',
uid,
annotations,
},
spec: {
identifiers,
Expand Down
210 changes: 210 additions & 0 deletions frontend/src/__tests__/cypress/cypress/pages/hardwareProfile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Contextual } from '~/__tests__/cypress/cypress/pages/components/Contextual';
import { K8sNameDescriptionField } from '~/__tests__/cypress/cypress/pages/components/subComponents/K8sNameDescriptionField';
import { Modal } from '~/__tests__/cypress/cypress/pages/components/Modal';
import { TableRow } from './components/table';

class HardwareProfileTableToolbar extends Contextual<HTMLElement> {
Expand Down Expand Up @@ -104,4 +106,212 @@ class HardwareProfile {
}
}

class NodeSelectorRow extends TableRow {
shouldHaveKey(name: string) {
this.find().find(`[data-label=Key]`).should('have.text', name);
return this;
}

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

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

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

class TolerationRow extends TableRow {
shouldHaveOperator(name: string) {
this.find().find(`[data-label=Operator]`).should('have.text', name);
return this;
}

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

shouldHaveTolerationSeconds(toleration: string) {
this.find().find(`[data-label="Toleration seconds"]`).should('have.text', toleration);
return this;
}

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

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

class ManageHardwareProfile {
k8sNameDescription = new K8sNameDescriptionField('hardware-profile-name-desc');

findAddTolerationButton() {
return cy.findByTestId('add-toleration-button');
}

findAddNodeSelectorButton() {
return cy.findByTestId('add-node-selector-button');
}

findSubmitButton() {
return cy.findByTestId('hardware-profile-create-button');
}

findTolerationTable() {
return cy.findByTestId('hardware-profile-tolerations-table');
}

findNodeSelectorTable() {
return cy.findByTestId('hardware-profile-node-selectors-table');
}

getTolerationTableRow(name: string) {
return new TolerationRow(() =>
this.findTolerationTable().find(`[data-label=Key]`).contains(name).parents('tr'),
);
}

getNodeSelectorTableRow(name: string) {
return new NodeSelectorRow(() =>
this.findNodeSelectorTable().find(`[data-label=Key]`).contains(name).parents('tr'),
);
}
}

class CreateHardwareProfile extends ManageHardwareProfile {
visit() {
cy.visitWithLogin('/hardwareProfiles/Create');
this.wait();
}

private wait() {
this.findSubmitButton().contains('Create hardware profile');
cy.testA11y();
}
}

class EditHardwareProfile extends ManageHardwareProfile {
visit(name: string) {
cy.visitWithLogin(`/hardwareProfiles/edit/${name}`);
cy.testA11y();
}

findErrorText() {
return cy.findByTestId('problem-loading-hardware-profile');
}

findViewAllHardwareProfilesButton() {
return cy.findByTestId('view-all-hardware-profiles');
}
}

class DuplicateHardwareProfile extends ManageHardwareProfile {
visit(name: string) {
cy.visitWithLogin(`/hardwareProfiles/duplicate/${name}`);
cy.testA11y();
}

findErrorText() {
return cy.findByTestId('problem-loading-hardware-profile');
}

findViewAllHardwareProfilesButton() {
return cy.findByTestId('view-all-hardware-profiles');
}
}

class TolerationModal extends Modal {
constructor(edit = false) {
super(edit ? 'Edit toleration' : 'Add toleration');
}

findTolerationKeyInput() {
return this.find().findByTestId('toleration-key-input');
}

findTolerationValueAlert() {
return this.find().findByTestId('toleration-value-alert');
}

findTolerationSecondRadioCustom() {
return this.find().findByTestId('toleration-seconds-radio-custom');
}

findTolerationSecondAlert() {
return this.find().findByTestId('toleration-seconds-alert');
}

findTolerationValueInput() {
return this.find().findByTestId('toleration-value-input');
}

private findTolerationOperatorSelect() {
return this.find().findByTestId('toleration-operator-select');
}

private findTolerationEffectSelect() {
return this.find().findByTestId('toleration-effect-select');
}

findOperatorOptionExist() {
return this.findTolerationOperatorSelect().findSelectOption(
'Exists A toleration "matches" a taint if the keys are the same and the effects are the same. No value should be specified.',
);
}

findOperatorOptionEqual() {
return this.findTolerationOperatorSelect().findSelectOption(
'Equal A toleration "matches" a taint if the keys are the same, the effects are the same, and the values are equal.',
);
}

findEffectOptionNoExecute() {
return this.findTolerationEffectSelect().findSelectOption(
'NoExecute Pods will be evicted from the node if they do not tolerate the taint.',
);
}

findPlusButton() {
return this.find().findByRole('button', { name: 'Plus' });
}

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

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

findNodeSelectorKeyInput() {
return this.find().findByTestId('node-selector-key-input');
}

findNodeSelectorValueInput() {
return this.find().findByTestId('node-selector-value-input');
}

findNodeSelectorSubmitButton() {
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 editHardwareProfile = new EditHardwareProfile();
export const duplicateHardwareProfile = new DuplicateHardwareProfile();
Loading

0 comments on commit b61a5ce

Please sign in to comment.