Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix state is not reset when feature flag API request fails #13090

Merged
merged 1 commit into from
Jan 20, 2025
Merged
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
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
Loading