From 6ceb76ad50dfc23baabdb440c7f003042b3238d2 Mon Sep 17 00:00:00 2001 From: Cassie Liu Date: Mon, 22 Jan 2024 13:41:37 -0500 Subject: [PATCH 1/3] M3-7483 Add test to delete users on "Users & Grants" page --- .../e2e/core/account/user-permissions.spec.ts | 92 +++++++++++++++++++ .../cypress/support/intercepts/account.ts | 15 +++ 2 files changed, 107 insertions(+) diff --git a/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts b/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts index 2fb3cbbbf16..1535d5504ef 100644 --- a/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts +++ b/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts @@ -10,6 +10,7 @@ import { mockGetUsers, mockUpdateUser, mockUpdateUserGrants, + mockDeleteUser, } from 'support/intercepts/account'; import { mockAppendFeatureFlags, @@ -904,4 +905,95 @@ describe('User permission management', () => { // redirects to the new user's "User Permissions" page cy.url().should('endWith', `/users/${newUser.username}/permissions`); }); + + it('can delete users', () => { + const mockUser = accountUserFactory.build({ + username: randomLabel(), + restricted: false, + }); + + const username = randomLabel(); + const additionalUser = accountUserFactory.build({ + username: username, + email: `${username}@test.com`, + restricted: false, + }); + + const mockUserGrantsUpdated = grantsFactory.build(); + const mockUserGrants = { + ...mockUserGrantsUpdated, + global: undefined, + }; + + mockGetUsers([mockUser, additionalUser]).as('getUsers'); + mockGetUser(mockUser); + mockGetUserGrants(mockUser.username, mockUserGrants); + mockGetUserGrants(additionalUser.username, mockUserGrants); + mockDeleteUser(additionalUser.username).as('deleteUser'); + + // Navigate to Users & Grants page, find mock user, click its "User Permissions" button. + cy.visitWithLogin('/account/users'); + cy.wait('@getUsers'); + + mockGetUsers([mockUser]).as('getUsers'); + + // Confirm that the "Users & Grants" page initially lists the main and additional users + cy.findByText(mockUser.username).should('be.visible'); + cy.findByText(additionalUser.username) + .should('be.visible') + .closest('tr') + .within(() => { + ui.button + .findByTitle('Delete') + .should('be.visible') + .should('be.enabled') + .click(); + }); + + // the "Confirm Deletion" dialog opens + ui.dialog.findByTitle('Confirm Deletion').within(() => { + ui.button.findByTitle('Cancel').should('be.visible').click(); + }); + // click the "Cancel" button will do nothing + cy.findByText(mockUser.username).should('be.visible'); + cy.findByText(additionalUser.username).should('be.visible'); + + // clickl the "x" button will dismiss the dialog and do nothing + cy.findByText(additionalUser.username) + .should('be.visible') + .closest('tr') + .within(() => { + ui.button + .findByTitle('Delete') + .should('be.visible') + .should('be.enabled') + .click(); + }); + ui.dialog.findByTitle('Confirm Deletion').within(() => { + cy.get('[data-testid="CloseIcon"]').should('be.visible').click(); + }); + cy.findByText(mockUser.username).should('be.visible'); + cy.findByText(additionalUser.username).should('be.visible'); + + // delete the user + cy.findByText(additionalUser.username) + .should('be.visible') + .closest('tr') + .within(() => { + ui.button + .findByTitle('Delete') + .should('be.visible') + .should('be.enabled') + .click(); + }); + + // the "Confirm Deletion" dialog opens + ui.dialog.findByTitle('Confirm Deletion').within(() => { + ui.button.findByTitle('Delete').should('be.visible').click(); + }); + cy.wait(['@deleteUser', '@getUsers']); + + // the user is deleted + cy.findByText(additionalUser.username).should('not.exist'); + }); }); diff --git a/packages/manager/cypress/support/intercepts/account.ts b/packages/manager/cypress/support/intercepts/account.ts index 41f092a814d..76191d0309f 100644 --- a/packages/manager/cypress/support/intercepts/account.ts +++ b/packages/manager/cypress/support/intercepts/account.ts @@ -121,6 +121,21 @@ export const mockUpdateUser = ( ); }; +/** + * Intercepts DELETE request to remove account user. + * + * @param username - Username of user to delete. + * + * @returns Cypress chainable. + */ +export const mockDeleteUser = (username: string): Cypress.Chainable => { + return cy.intercept( + 'DELETE', + apiMatcher(`account/users/${username}`), + makeResponse() + ); +}; + /** * Intercepts GET request to fetch account user grants and mocks response. * From f7e7f72f950780a89c9c5916a1dd669c312fc25e Mon Sep 17 00:00:00 2001 From: Cassie Liu Date: Tue, 23 Jan 2024 12:42:38 -0500 Subject: [PATCH 2/3] fix comments --- .../cypress/e2e/core/account/user-permissions.spec.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts b/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts index 1535d5504ef..e27d91f325d 100644 --- a/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts +++ b/packages/manager/cypress/e2e/core/account/user-permissions.spec.ts @@ -925,6 +925,12 @@ describe('User permission management', () => { global: undefined, }; + // TODO: Parent/Child - M3-7559 clean up when feature is live in prod and feature flag is removed. + mockAppendFeatureFlags({ + parentChildAccountAccess: makeFeatureFlagData(false), + }).as('getFeatureFlags'); + mockGetFeatureFlagClientstream().as('getClientStream'); + mockGetUsers([mockUser, additionalUser]).as('getUsers'); mockGetUser(mockUser); mockGetUserGrants(mockUser.username, mockUserGrants); @@ -958,7 +964,7 @@ describe('User permission management', () => { cy.findByText(mockUser.username).should('be.visible'); cy.findByText(additionalUser.username).should('be.visible'); - // clickl the "x" button will dismiss the dialog and do nothing + // clicking the "x" button will dismiss the dialog and do nothing cy.findByText(additionalUser.username) .should('be.visible') .closest('tr') @@ -994,6 +1000,9 @@ describe('User permission management', () => { cy.wait(['@deleteUser', '@getUsers']); // the user is deleted + ui.toast.assertMessage( + `User ${additionalUser.username} has been deleted successfully.` + ); cy.findByText(additionalUser.username).should('not.exist'); }); }); From e7774de8701b7fdd77122630ba5232ee2b5c4ee2 Mon Sep 17 00:00:00 2001 From: Cassie Liu Date: Tue, 23 Jan 2024 12:44:12 -0500 Subject: [PATCH 3/3] Added changeset: Add regression tests for deleting users on Users & Grants page. --- packages/manager/.changeset/pr-10093-tests-1706031852395.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/manager/.changeset/pr-10093-tests-1706031852395.md diff --git a/packages/manager/.changeset/pr-10093-tests-1706031852395.md b/packages/manager/.changeset/pr-10093-tests-1706031852395.md new file mode 100644 index 00000000000..14db1f8585d --- /dev/null +++ b/packages/manager/.changeset/pr-10093-tests-1706031852395.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Add regression tests for deleting users on Users & Grants page. ([#10093](https://github.com/linode/manager/pull/10093))