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

test: [M3-7483] - Add test to delete users on "Users & Grants" page #10093

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
mockGetUsers,
mockUpdateUser,
mockUpdateUserGrants,
mockDeleteUser,
} from 'support/intercepts/account';
import {
mockAppendFeatureFlags,
Expand Down Expand Up @@ -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', () => {
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// click the "Cancel" button will do nothing
// clicking the "Cancel" button will dismiss the dialog and do nothing

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with this small adjustment; it'll make it align with the comment for the next assertion too.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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')
.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');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cy.findByText(additionalUser.username).should('not.exist');
ui.toast.assertMessage(`User ${additionalUser.username} has been deleted successfully.`);
cy.findByText(additionalUser.username).should('not.exist');

This wasn't a ticket requirement, but it would be good to have the toast notification covered too!

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed!

});
});
15 changes: 15 additions & 0 deletions packages/manager/cypress/support/intercepts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<null> => {
return cy.intercept(
'DELETE',
apiMatcher(`account/users/${username}`),
makeResponse()
);
};

/**
* Intercepts GET request to fetch account user grants and mocks response.
*
Expand Down