Cypress tests: users (#2148)

* add users tests

* delete multiple users from list test

* users from search bar

* remove unnecessary its

* fix group test

* force add group click
This commit is contained in:
Jenny 2022-02-28 12:48:52 -05:00 committed by GitHub
parent 5c64ab6a4a
commit baf2380d1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 8 deletions

View file

@ -30,6 +30,7 @@ describe("User creation", () => {
const attributesTab = new AttributesTab();
let itemId = "user_crud";
let itemIdWithGroups = "user_with_groups_crud";
let itemIdWithCred = "user_crud_cred";
before(() => {
@ -63,12 +64,23 @@ describe("User creation", () => {
it("Create user test", () => {
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
// Create
createUserPage.goToCreateUser();
createUserPage.createUser(itemId);
createUserPage.save();
masthead.checkNotificationMessage("The user has been created");
});
it("Create user with groups test", () => {
itemIdWithGroups += (Math.random() + 1).toString(36).substring(7);
// Add user from search bar
createUserPage.goToCreateUser();
createUserPage.createUser(itemIdWithGroups);
createUserPage.toggleAddGroupModal();
const groupsListCopy = groupsList.slice(0, 1);
@ -87,6 +99,7 @@ describe("User creation", () => {
it("Create user with credentials test", () => {
itemIdWithCred += "_" + (Math.random() + 1).toString(36).substring(7);
// Add user from search bar
createUserPage.goToCreateUser();
createUserPage.createUser(itemIdWithCred);
@ -104,6 +117,15 @@ describe("User creation", () => {
.clickSetPasswordBtn();
});
it("Search existing user test", () => {
listingPage.searchItem(itemId).itemExist(itemId);
});
it("Search non-existing user test", () => {
listingPage.searchItem("user_DNE");
cy.findByTestId(listingPage.emptyState).should("exist");
});
it("User details test", () => {
sidebarPage.waitForPageLoad();
listingPage.searchItem(itemId).itemExist(itemId);
@ -162,7 +184,7 @@ describe("User creation", () => {
userGroupsPage.goToGroupsTab();
userGroupsPage.toggleAddGroupModal();
const groupsListCopy = groupsList.slice(1, 2);
const groupsListCopy = groupsList.slice(0, 1);
groupsListCopy.forEach((element) => {
cy.findByTestId(`${element}-check`).click();
@ -213,10 +235,12 @@ describe("User creation", () => {
);
});
// TODO: Fix this test so it passes.
it.skip("Delete user test", () => {
it("Delete user from search bar test", () => {
// Delete
listingPage.deleteItem(itemId);
sidebarPage.waitForPageLoad();
listingPage.searchItem(itemId).itemExist(itemId);
listingPage.deleteItemFromSearchBar(itemId);
modalUtils.checkModalTitle("Delete user?").confirmModal();
@ -226,6 +250,18 @@ describe("User creation", () => {
listingPage.itemExist(itemId, false);
});
it("Delete user with groups test", () => {
// Delete
listingPage.deleteItem(itemIdWithGroups);
modalUtils.checkModalTitle("Delete user?").confirmModal();
masthead.checkNotificationMessage("The user has been deleted");
sidebarPage.waitForPageLoad();
listingPage.itemExist(itemIdWithGroups, false);
});
it("Delete user with credential test", () => {
// Delete
listingPage.deleteItem(itemIdWithCred);

View file

@ -29,8 +29,10 @@ export default class ListingPage {
private searchInput = '.pf-c-toolbar__item [type="search"]:visible';
private tableToolbar = ".pf-c-toolbar";
private itemsRows = "table:visible";
private deleteUserButton = "delete-user-btn";
private emptyListImg =
'[role="tabpanel"]:not([hidden]) [data-testid="empty-state"]';
public emptyState = "empty-state";
private progressBar = '[role="progressbar"]';
private itemRowDrpDwn = ".pf-c-dropdown__toggle";
private itemRowSelect = ".pf-c-select__toggle:nth-child(1)";
@ -209,6 +211,13 @@ export default class ListingPage {
return this;
}
deleteItemFromSearchBar(itemName: string) {
this.markItemRow(itemName);
cy.findByTestId(this.deleteUserButton).click();
return this;
}
exportItem(itemName: string) {
this.clickRowDetails(itemName);
this.clickDetailMenu("Export");

View file

@ -36,9 +36,9 @@ export default class CreateUserPage {
goToCreateUser() {
cy.get("body").then((body) => {
if (body.find("[data-testid=search-users-title]").length > 0) {
cy.findByTestId(this.searchPgCreateUserBtn).click();
cy.findByTestId(this.searchPgCreateUserBtn).click({ force: true });
} else {
cy.findByTestId(this.addUserBtn).click();
cy.findByTestId(this.addUserBtn).click({ force: true });
}
});

View file

@ -16,7 +16,7 @@ export default class UserGroupsPage {
}
toggleAddGroupModal() {
cy.findByTestId(this.addGroupButton).click();
cy.findByTestId(this.addGroupButton).click({ force: true });
return this;
}

View file

@ -223,6 +223,7 @@ export default function UsersSection() {
<Button
variant={ButtonVariant.plain}
onClick={toggleDeleteDialog}
data-testid="delete-user-btn"
isDisabled={selectedRows.length === 0}
>
{t("deleteUser")}