Skip to content

Commit

Permalink
Fix state is not reset when feature flag API request fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Jan 15, 2025
1 parent 55afa4f commit 86849a7
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cypress/e2e/po/components/card.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default class CardPo extends ComponentPo {
return this.self().get('[data-testid="card-body-slot"]');
}

getError(): CypressChainable {
return this.self().get('[data-testid="card-body-slot"] > .text-error');
}

getActionButton(): CypressChainable {
return this.self().get('[data-testid="card-actions-slot"]');
}
Expand Down
11 changes: 11 additions & 0 deletions cypress/e2e/po/pages/global-settings/feature-flags.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export class FeatureFlagsPagePo extends RootClusterPage {
return card.getBody().contains(label);
}

/**
* Get card body error
* @param error
* @returns
*/
cardActionError(error: string): CypressChainable {
const card = new CardPo();

return card.getError().contains(error);
}

/**
* Click action button
* @param label Activate or Deactivate
Expand Down
37 changes: 37 additions & 0 deletions cypress/e2e/tests/pages/global-settings/feature-flags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,43 @@ describe('Feature Flags', { testIsolation: 'off' }, () => {
sideNav.groups().contains('Legacy').should('not.exist');
});

it('error when toggling a feature flag is handled correctly', { tags: ['@globalSettings', '@adminUser'] }, () => {
// Check Current State: should be disabled by default
FeatureFlagsPagePo.navTo();
featureFlagsPage.list().details('unsupported-storage-drivers', 0).should('include.text', 'Disabled');

// Intercept the request to change the feature flag and return an error - 403, permission denied
cy.intercept({
method: 'PUT',
pathname: '/v1/management.cattle.io.features/unsupported-storage-drivers',
times: 1,
}, {
statusCode: 403,
body: {
type: 'error',
links: {},
code: 'Forbidden',
message: 'User does not have permission'
}
}).as('updateFeatureFlag');

// Activate
featureFlagsPage.list().elementWithName('unsupported-storage-drivers').scrollIntoView().should('be.visible');
featureFlagsPage.list().clickRowActionMenuItem('unsupported-storage-drivers', 'Activate');
featureFlagsPage.cardActionButton('Activate').click();

cy.wait(`@updateFeatureFlag`).its('response.statusCode').should('eq', 403);

// Check Updated State: should be active
featureFlagsPage.list().details('unsupported-storage-drivers', 0).should('include.text', 'Disabled');

// Check error message is displayed
featureFlagsPage.cardActionError('User does not have permission');

// Press cancel
featureFlagsPage.cardActionButton('Cancel').click();
});

it('standard user has only read access to Feature Flag page', { tags: ['@globalSettings', '@standardUser'] }, () => {
// verify action menus are hidden for standard user

Expand Down
7 changes: 6 additions & 1 deletion shell/list/management.cattle.io.feature.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export default {
watch: {
showPromptUpdate(show) {
if (show) {
// Clear last error
this.error = null;
this.showModal = true;
} else {
this.showModal = false;
Expand Down Expand Up @@ -140,7 +143,9 @@ export default {
btnCB(true);
this.close();
} catch (err) {
this.error = err;
// An error occurred, so toggle back the value - the call failed, so the change was not made
this.update.spec.value = !this.update.enabled;
this.error = err.message || err;
btnCB(false);
}
},
Expand Down

0 comments on commit 86849a7

Please sign in to comment.