Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libs/cypress/e2e/fleets/createFleet.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ describe('Create fleet form', () => {
fleetDetailsPage.title.should('have.text', 'sample-fleet');
});

it('allows navigating between previous and current step when there are validation errors', () => {
fleetsPage.openCreateFleetFormButton.click();
createFleetWizardPage = new CreateFleetWizardPage();

createFleetWizardPage.newFleetNameField.type('another-fleet');
createFleetWizardPage.nextFleetWizardButton.should('be.enabled').click();

createFleetWizardPage.newFleetSystemImageField.type('invalid!oci').blur();
createFleetWizardPage.nextFleetWizardButton.should('be.disabled');
createFleetWizardPage.backFleetWizardButton.click();
createFleetWizardPage.nextFleetWizardButton.should('be.enabled').click();

createFleetWizardPage.newFleetSystemImageField.should('be.visible').should('have.value', 'invalid!oci');
});

it('disables the create fleet button if a fleet with the same name exists', () => {
const existingFleetName = 'eu-west-prod-001';
fleetsPage.fleetRow(existingFleetName).should('exist');
Expand Down
4 changes: 4 additions & 0 deletions libs/cypress/pages/CreateFleetWizardPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export class CreateFleetWizardPage {
return cy.contains('button', 'Next');
}

get backFleetWizardButton() {
return cy.contains('button', 'Back');
}

get addConfigurationButton() {
return cy.contains('button', 'Add configuration');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ const getValidStepIds = (formikErrors: FormikErrors<FleetFormValues>): string[]
return validStepIds;
};

// Do not disable the current step where there could be validation errors
const isDisabledStep = (stepId: string, validStepIds: string[]) => {
const validIndex = validStepIds.indexOf(stepId);
return validIndex === -1 || validIndex !== orderedIds.indexOf(stepId);
const stepIdx = orderedIds.findIndex((orderedStepId) => orderedStepId === stepId);
return orderedIds.some((orderedId, orderedStepIdx) => {
return orderedStepIdx < stepIdx && !validStepIds.includes(orderedId);
});
Comment on lines +62 to +65
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the condition is quite confusing TBH.
Can't we just pass a current step ID to this function and return early ?

Suggested change
const stepIdx = orderedIds.findIndex((orderedStepId) => orderedStepId === stepId);
return orderedIds.some((orderedId, orderedStepIdx) => {
return orderedStepIdx < stepIdx && !validStepIds.includes(orderedId);
});
const isDisabledStep = (currentStepId: string, stepId: string, validStepIds: string[]) => {
if (currentStepId === stepId) {
return false; //current step is never disabled
}
const validIndex = validStepIds.indexOf(stepId);
return validIndex === -1 || validIndex !== orderedIds.indexOf(stepId);
}

also we use this condition in multiple wizards - maybe its worth making it a common func.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, the initial bug would not be fixed: When on step 2 with some invalid input, users can go back to step 1. And now clicking on "Next" does nothing since the step with the error is a "future step" from the POV of the new current step.

I agree that it would be better to unify the check for the disabled steps in the different Wizards.
I can see two options:

  • Use in the CreateFleetWizard the pattern we have in the other wizards, that for step N+2, they check the steps N, N+1.
  • Make this function reusable and use it in all the wizards.

Personally I find the second one better in the long run, even though it's harder to understand. We could properly document it and it would not require new custom logic for any new Wizards.

};

const CreateFleetWizard = () => {
Expand Down
Loading