From 6a970e6cb7b73138ca700584eee883b51259cecb Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 2 Feb 2022 12:44:52 +0100 Subject: [PATCH] updated and fixed user test (#1956) * updated and fixed user test * Update cypress/integration/users_test.spec.ts * fixed the confirm button test id * fixed tests * fix * removed unused refresh Co-authored-by: Jenny <32821331+jenny-s51@users.noreply.github.com> --- cypress/integration/clients_saml_test.spec.ts | 19 +- cypress/integration/clients_test.spec.ts | 2 +- .../identity_providers_test.spec.ts | 2 +- .../integration/partial_import_test.spec.ts | 1 + cypress/integration/users_test.spec.ts | 384 ++++++++---------- .../pages/admin_console/SidebarPage.ts | 7 +- .../admin_console/manage/RoleMappingTab.ts | 1 - .../realm_settings/RealmSettingsPage.ts | 52 +-- cypress/support/util/AdminClient.ts | 5 + cypress/support/util/ModalUtils.ts | 8 +- src/client-scopes/add/MapperDialog.test.tsx | 4 +- src/client-scopes/add/MapperDialog.tsx | 3 +- src/clients/keys/ImportKeyDialog.tsx | 2 + src/clients/scopes/AddScopeDialog.tsx | 3 +- .../confirm-dialog/ConfirmDialog.test.tsx | 2 +- .../confirm-dialog/ConfirmDialog.tsx | 3 +- src/groups/GroupsModal.tsx | 1 + src/identity-providers/ManageOrderDialog.tsx | 2 + src/realm-settings/AddMessageBundleModal.tsx | 1 + src/realm-settings/AddUserEmailModal.tsx | 1 + src/realm-settings/JavaKeystoreModal.tsx | 1 + src/realm-settings/NewClientPolicyForm.tsx | 13 +- src/realm-settings/RSAGeneratedModal.tsx | 1 + src/realm-settings/RSAModal.tsx | 1 + src/sessions/LogoutAllSessionsModal.tsx | 1 + src/sessions/RevocationModal.tsx | 1 + src/user/UserCredentials.tsx | 6 +- src/user/UserIdPModal.tsx | 1 + src/user/UsersSection.tsx | 43 +- src/user/UsersTabs.tsx | 5 + 30 files changed, 289 insertions(+), 287 deletions(-) diff --git a/cypress/integration/clients_saml_test.spec.ts b/cypress/integration/clients_saml_test.spec.ts index 4db45779ea..1e045c35cd 100644 --- a/cypress/integration/clients_saml_test.spec.ts +++ b/cypress/integration/clients_saml_test.spec.ts @@ -4,7 +4,10 @@ import ListingPage from "../support/pages/admin_console/ListingPage"; import SidebarPage from "../support/pages/admin_console/SidebarPage"; import ModalUtils from "../support/util/ModalUtils"; import AdminClient from "../support/util/AdminClient"; -import { keycloakBefore } from "../support/util/keycloak_hooks"; +import { + keycloakBefore, + keycloakBeforeEach, +} from "../support/util/keycloak_hooks"; const loginPage = new LoginPage(); const masthead = new Masthead(); @@ -22,6 +25,8 @@ describe("Clients SAML tests", () => { clientId: samlClientName, publicClient: false, }); + keycloakBefore(); + loginPage.logIn(); }); after(() => { @@ -29,8 +34,7 @@ describe("Clients SAML tests", () => { }); beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); + keycloakBeforeEach(); sidebarPage.goToClients(); listingPage.searchItem(samlClientName).goToItemDetails(samlClientName); }); @@ -62,6 +66,8 @@ describe("Clients SAML tests", () => { clientId, protocol: "saml", }); + keycloakBefore(); + loginPage.logIn(); }); after(() => { @@ -69,8 +75,7 @@ describe("Clients SAML tests", () => { }); beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); + keycloakBeforeEach(); sidebarPage.goToClients(); listingPage.searchItem(clientId).goToItemDetails(clientId); cy.findByTestId("keysTab").click(); @@ -87,7 +92,11 @@ describe("Clients SAML tests", () => { }); it("disable client signature", () => { + cy.intercept( + "auth/admin/realms/master/clients/*/certificates/saml.signing" + ).as("load"); cy.findByTestId("clientSignature").click({ force: true }); + cy.waitFor("@load"); modalUtils .checkModalTitle('Disable "Client signature required"') diff --git a/cypress/integration/clients_test.spec.ts b/cypress/integration/clients_test.spec.ts index 564ff9066c..10c2013fb5 100644 --- a/cypress/integration/clients_test.spec.ts +++ b/cypress/integration/clients_test.spec.ts @@ -282,7 +282,7 @@ describe("Clients test", () => { cy.findByTestId("mappersTab").click(); cy.findByText("Add predefined mapper").click(); cy.get("table input").first().click(); - cy.findByTestId("modalConfirm").click(); + cy.findByTestId("confirm").click(); masthead.checkNotificationMessage("Mapping successfully created"); }); }); diff --git a/cypress/integration/identity_providers_test.spec.ts b/cypress/integration/identity_providers_test.spec.ts index 06e115130c..18697d1c83 100644 --- a/cypress/integration/identity_providers_test.spec.ts +++ b/cypress/integration/identity_providers_test.spec.ts @@ -128,7 +128,7 @@ describe("Identity provider test", () => { listingPage.goToItemDetails("facebook"); addMapperPage.goToMappersTab(); listingPage.deleteItem("facebook attribute importer"); - cy.findByTestId("modalConfirm").click(); + cy.findByTestId("confirm").click(); }); it("clean up providers", () => { diff --git a/cypress/integration/partial_import_test.spec.ts b/cypress/integration/partial_import_test.spec.ts index 1f7ac14f81..dcab99a324 100644 --- a/cypress/integration/partial_import_test.spec.ts +++ b/cypress/integration/partial_import_test.spec.ts @@ -17,6 +17,7 @@ describe("Partial import test", () => { beforeEach(() => { keycloakBefore(); loginPage.logIn(); + sidebarPage.waitForPageLoad(); // doing this from the UI has the added bonus of putting you in the test realm sidebarPage.goToCreateRealm(); diff --git a/cypress/integration/users_test.spec.ts b/cypress/integration/users_test.spec.ts index 2b8f88545e..8c6765e2c6 100644 --- a/cypress/integration/users_test.spec.ts +++ b/cypress/integration/users_test.spec.ts @@ -6,8 +6,10 @@ import ListingPage from "../support/pages/admin_console/ListingPage"; import UserDetailsPage from "../support/pages/admin_console/manage/users/UserDetailsPage"; import AttributesTab from "../support/pages/admin_console/manage/AttributesTab"; import ModalUtils from "../support/util/ModalUtils"; -import { keycloakBefore } from "../support/util/keycloak_hooks"; -import GroupModal from "../support/pages/admin_console/manage/groups/GroupModal"; +import { + keycloakBefore, + keycloakBeforeEach, +} from "../support/util/keycloak_hooks"; import UserGroupsPage from "../support/pages/admin_console/manage/users/UserGroupsPage"; import AdminClient from "../support/util/AdminClient"; import CredentialsPage from "../support/pages/admin_console/manage/users/CredentialsPage"; @@ -15,38 +17,7 @@ import CredentialsPage from "../support/pages/admin_console/manage/users/Credent let groupName = "group"; let groupsList: string[] = []; -describe("Group creation", () => { - const loginPage = new LoginPage(); - const masthead = new Masthead(); - const sidebarPage = new SidebarPage(); - const groupModal = new GroupModal(); - - beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); - sidebarPage.goToGroups(); - }); - - function createNewGroup() { - groupName += "_" + (Math.random() + 1).toString(36).substring(7); - - sidebarPage.waitForPageLoad(); - groupModal.open().fillGroupForm(groupName).clickCreate(); - - groupsList = [...groupsList, groupName]; - masthead.checkNotificationMessage("Group created"); - - sidebarPage.goToGroups(); - } - - it("Add groups to be joined", () => { - for (let i = 0; i <= 2; i++) { - createNewGroup(); - } - }); -}); - -describe("Users test", () => { +describe("User creation", () => { const loginPage = new LoginPage(); const sidebarPage = new SidebarPage(); const createUserPage = new CreateUserPage(); @@ -60,217 +31,208 @@ describe("Users test", () => { let itemId = "user_crud"; let itemIdWithCred = "user_crud_cred"; + const adminClient = new AdminClient(); - describe("User creation", () => { - beforeEach(() => { - keycloakBefore(); - loginPage.logIn(); - cy.intercept( - "/auth/admin/realms/master/components?type=org.keycloak.storage.UserStorageProvider" - ).as("brute-force"); - sidebarPage.goToUsers(); + before(() => { + for (let i = 0; i <= 2; i++) { + groupName += "_" + (Math.random() + 1).toString(36).substring(7); + adminClient.createGroup(groupName); + groupsList = [...groupsList, groupName]; + } + + keycloakBefore(); + loginPage.logIn(); + }); + + beforeEach(() => { + keycloakBeforeEach(); + sidebarPage.goToUsers(); + }); + + after(() => { + adminClient.deleteGroups(); + }); + + it("Go to create User page", () => { + createUserPage.goToCreateUser(); + cy.url().should("include", "users/add-user"); + + // Verify Cancel button works + createUserPage.cancel(); + cy.url().should("not.include", "/add-user"); + }); + + it("Create user test", () => { + itemId += "_" + (Math.random() + 1).toString(36).substring(7); + + // Create + createUserPage.goToCreateUser(); + + createUserPage.createUser(itemId); + + createUserPage.toggleAddGroupModal(); + + const groupsListCopy = groupsList.slice(0, 1); + + groupsListCopy.forEach((element) => { + cy.findByTestId(`${element}-check`).click(); }); - after(async () => { - await new AdminClient().deleteGroups(); - }); + createUserPage.joinGroups(); - it("Go to create User page", () => { - createUserPage.goToCreateUser(); - cy.url().should("include", "users/add-user"); + createUserPage.save(); - // Verify Cancel button works - createUserPage.cancel(); - cy.url().should("not.include", "/add-user"); - }); + masthead.checkNotificationMessage("The user has been created"); + }); - it("Create user test", () => { - itemId += "_" + (Math.random() + 1).toString(36).substring(7); + it("Create user with credentials test", () => { + itemIdWithCred += "_" + (Math.random() + 1).toString(36).substring(7); - // Create - createUserPage.goToCreateUser(); + createUserPage.goToCreateUser(); - createUserPage.createUser(itemId); + createUserPage.createUser(itemIdWithCred); - createUserPage.toggleAddGroupModal(); + userDetailsPage.fillUserData(); + createUserPage.save(); + masthead.checkNotificationMessage("The user has been created"); + sidebarPage.waitForPageLoad(); - const groupsListCopy = groupsList.slice(0, 1); + credentialsPage + .goToCredentialsTab() + .clickEmptyStatePasswordBtn() + .fillPasswordForm() + .clickConfirmationBtn() + .clickSetPasswordBtn(); + }); - groupsListCopy.forEach((element) => { - cy.findByTestId(`${element}-check`).click(); + it("User details test", () => { + sidebarPage.waitForPageLoad(); + listingPage.searchItem(itemId).itemExist(itemId); + + listingPage.goToItemDetails(itemId); + + userDetailsPage.fillUserData().save(); + + masthead.checkNotificationMessage("The user has been saved"); + + sidebarPage.waitForPageLoad(); + sidebarPage.goToUsers(); + listingPage.searchItem(itemId).itemExist(itemId); + }); + + it("User attributes test", () => { + listingPage.goToItemDetails(itemId); + + attributesTab + .goToAttributesTab() + .fillLastRow("key", "value") + .saveAttribute(); + + masthead.checkNotificationMessage("The user has been saved"); + }); + + it("User attributes with multiple values test", () => { + listingPage.searchItem(itemId).itemExist(itemId); + listingPage.goToItemDetails(itemId); + + cy.intercept("PUT", `/auth/admin/realms/master/users/*`).as("save-user"); + + const attributeKey = "key-multiple"; + attributesTab + .goToAttributesTab() + .fillLastRow(attributeKey, "other value") + .saveAttribute(); + + cy.wait("@save-user").should(({ request, response }) => { + expect(response?.statusCode).to.equal(204); + + expect(request?.body.attributes, "response body").deep.equal({ + key: ["value"], + "key-multiple": ["other value"], }); - - createUserPage.joinGroups(); - - createUserPage.save(); - - masthead.checkNotificationMessage("The user has been created"); - - sidebarPage.goToUsers(); }); - it("Create user with credentials test", () => { - itemIdWithCred += "_" + (Math.random() + 1).toString(36).substring(7); + masthead.checkNotificationMessage("The user has been saved"); + }); - createUserPage.goToCreateUser(); + it("Add user to groups test", () => { + // Go to user groups + listingPage.searchItem(itemId).itemExist(itemId); + listingPage.goToItemDetails(itemId); - createUserPage.createUser(itemIdWithCred); + userGroupsPage.goToGroupsTab(); + userGroupsPage.toggleAddGroupModal(); - createUserPage.save(); + const groupsListCopy = groupsList.slice(1, 2); - masthead.checkNotificationMessage("The user has been created"); - - sidebarPage.goToUsers(); - - listingPage.goToItemDetails(itemIdWithCred); - - userDetailsPage.fillUserData().save(); - masthead.checkNotificationMessage("The user has been saved"); - - credentialsPage - .goToCredentialsTab() - .clickEmptyStatePasswordBtn() - .fillPasswordForm() - .clickConfirmationBtn() - .clickSetPasswordBtn(); - - sidebarPage.goToUsers(); + groupsListCopy.forEach((element) => { + cy.findByTestId(`${element}-check`).click(); }); - it("User details test", () => { - cy.wait("@brute-force"); - listingPage.searchItem(itemId).itemExist(itemId); + userGroupsPage.joinGroups(); + }); - listingPage.goToItemDetails(itemId); + it("Leave group test", () => { + listingPage.searchItem(itemId).itemExist(itemId); + listingPage.goToItemDetails(itemId); + // Go to user groups + userGroupsPage.goToGroupsTab(); + cy.findByTestId(`leave-${groupsList[0]}`).click(); + cy.findByTestId("confirm").click(); + }); - userDetailsPage.fillUserData().save(); + it("Go to user consents test", () => { + listingPage.searchItem(itemId).itemExist(itemId); - masthead.checkNotificationMessage("The user has been saved"); + sidebarPage.waitForPageLoad(); + listingPage.goToItemDetails(itemId); - sidebarPage.goToUsers(); - cy.wait("@brute-force"); - listingPage.searchItem(itemId).itemExist(itemId); - }); + cy.findByTestId("user-consents-tab").click(); + cy.findByTestId("empty-state").contains("No consents"); + }); - it("User attributes test", () => { - cy.wait("@brute-force"); - listingPage.searchItem(itemId).itemExist(itemId); + it("Reset credential of User with empty state", () => { + listingPage.goToItemDetails(itemId); + credentialsPage + .goToCredentialsTab() + .clickEmptyStateResetBtn() + .fillResetCredentialForm(); + masthead.checkNotificationMessage("Failed to send email to user."); + modalUtils.cancelModal(); + }); - listingPage.goToItemDetails(itemId); + it("Reset credential of User with existing credentials", () => { + listingPage.goToItemDetails(itemIdWithCred); + credentialsPage + .goToCredentialsTab() + .clickResetBtn() + .fillResetCredentialForm(); - attributesTab - .goToAttributesTab() - .fillLastRow("key", "value") - .saveAttribute(); + masthead.checkNotificationMessage("Failed to send email to user."); + modalUtils.cancelModal(); + }); - masthead.checkNotificationMessage("The user has been saved"); - }); + it("Delete user test", () => { + // Delete + listingPage.deleteItem(itemId); - it("User attributes with multiple values test", () => { - cy.wait("@brute-force"); - listingPage.searchItem(itemId).itemExist(itemId); + modalUtils.checkModalTitle("Delete user?").confirmModal(); - listingPage.goToItemDetails(itemId); + masthead.checkNotificationMessage("The user has been deleted"); + sidebarPage.waitForPageLoad(); - cy.intercept("PUT", `/auth/admin/realms/master/users/*`).as("save-user"); + listingPage.itemExist(itemId, false); + }); - const attributeKey = "key-multiple"; - attributesTab - .goToAttributesTab() - .fillLastRow(attributeKey, "other value") - .saveAttribute(); + it("Delete user with credential test", () => { + // Delete + listingPage.deleteItem(itemIdWithCred); - cy.wait("@save-user").should(({ request, response }) => { - expect(response?.statusCode).to.equal(204); + modalUtils.checkModalTitle("Delete user?").confirmModal(); - expect(request?.body.attributes, "response body").deep.equal({ - key: ["value"], - "key-multiple": ["other value"], - }); - }); + masthead.checkNotificationMessage("The user has been deleted"); + sidebarPage.waitForPageLoad(); - masthead.checkNotificationMessage("The user has been saved"); - }); - - it("Add user to groups test", () => { - cy.wait("@brute-force"); - // Go to user groups - listingPage.searchItem(itemId).itemExist(itemId); - listingPage.goToItemDetails(itemId); - - userGroupsPage.goToGroupsTab(); - userGroupsPage.toggleAddGroupModal(); - - const groupsListCopy = groupsList.slice(1, 2); - - groupsListCopy.forEach((element) => { - cy.findByTestId(`${element}-check`).click(); - }); - - userGroupsPage.joinGroups(); - }); - - it("Leave group test", () => { - cy.wait("@brute-force"); - listingPage.searchItem(itemId).itemExist(itemId); - listingPage.goToItemDetails(itemId); - // Go to user groups - userGroupsPage.goToGroupsTab(); - cy.findByTestId(`leave-${groupsList[0]}`).click(); - cy.findByTestId("modalConfirm").click(); - }); - - it("Go to user consents test", () => { - cy.wait("@brute-force"); - listingPage.searchItem(itemId).itemExist(itemId); - - listingPage.goToItemDetails(itemId); - - cy.findByTestId("user-consents-tab").click(); - cy.findByTestId("empty-state").contains("No consents"); - }); - - it("Reset credential of User with empty state", () => { - cy.wait("@brute-force"); - listingPage.goToItemDetails(itemId); - credentialsPage - .goToCredentialsTab() - .clickEmptyStateResetBtn() - .fillResetCredentialForm(); - masthead.checkNotificationMessage("Failed to send email to user."); - }); - - it("Reset credential of User with existing credentials", () => { - cy.wait("@brute-force"); - listingPage.goToItemDetails(itemIdWithCred); - credentialsPage - .goToCredentialsTab() - .clickResetBtn() - .fillResetCredentialForm(); - - masthead.checkNotificationMessage("Failed to send email to user."); - }); - - it("Delete user test", () => { - // Delete - listingPage.deleteItem(itemId); - - modalUtils.checkModalTitle("Delete user?").confirmModal(); - - masthead.checkNotificationMessage("The user has been deleted"); - - listingPage.itemExist(itemId, false); - }); - - it("Delete user with credential test", () => { - // Delete - listingPage.deleteItem(itemIdWithCred); - - modalUtils.checkModalTitle("Delete user?").confirmModal(); - - masthead.checkNotificationMessage("The user has been deleted"); - - listingPage.itemExist(itemIdWithCred, false); - }); + listingPage.itemExist(itemIdWithCred, false); }); }); diff --git a/cypress/support/pages/admin_console/SidebarPage.ts b/cypress/support/pages/admin_console/SidebarPage.ts index 02236f6fea..4a5c116948 100644 --- a/cypress/support/pages/admin_console/SidebarPage.ts +++ b/cypress/support/pages/admin_console/SidebarPage.ts @@ -24,10 +24,9 @@ export default class SidebarPage { goToRealm(realmName: string) { cy.findByTestId(this.realmsList).scrollIntoView().click(); - cy.findByTestId(this.realmsList) - .get("ul") - .contains(capitalize(realmName)) - .click(); + cy.findByTestId(this.realmsList).within(() => { + cy.get("ul").contains(capitalize(realmName)).click(); + }); return this; } diff --git a/cypress/support/pages/admin_console/manage/RoleMappingTab.ts b/cypress/support/pages/admin_console/manage/RoleMappingTab.ts index 53507d3f6e..ef337b980b 100644 --- a/cypress/support/pages/admin_console/manage/RoleMappingTab.ts +++ b/cypress/support/pages/admin_console/manage/RoleMappingTab.ts @@ -9,7 +9,6 @@ export default class RoleMappingTab { private hideInheritedRolesBtn = "#hideInheritedRoles"; private assignedRolesTable = "assigned-roles"; private namesColumn = 'td[data-label="Name"]:visible'; - private confirmModalBtn = "modalConfirm"; goToServiceAccountTab() { cy.findByTestId(this.tab).click(); diff --git a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts index 7e4cb03789..c29866dde4 100644 --- a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts +++ b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts @@ -85,7 +85,7 @@ export default class RealmSettingsPage { keyInput = "key-input"; valueInput = "value-input"; deleteAction = "delete-action"; - modalConfirm = "modalConfirm"; + modalConfirm = "confirm"; ssoSessionIdleInput = "sso-session-idle-input"; ssoSessionMaxInput = "sso-session-max-input"; ssoSessionIdleRememberMeInput = "sso-session-idle-remember-me-input"; @@ -625,7 +625,7 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "This action will permanently delete the policy Test. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete"); + cy.findByTestId(this.modalConfirm).contains("Delete"); cy.get(this.deleteDialogCancelBtn).contains("Cancel").click(); cy.get("table").should("be.visible").contains("td", "Test"); } @@ -633,7 +633,8 @@ export default class RealmSettingsPage { shouldDeleteClientProfileDialog() { this.listingPage.searchItem("Test", false); this.listingPage.clickRowDetails("Test").clickDetailMenu("Delete"); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.findByTestId(this.modalConfirm).click(); cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.get("table").should("not.have.text", "Test"); } @@ -755,7 +756,7 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "The action will permanently delete secure-ciba-signed-authn-req. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete"); + cy.findByTestId(this.modalConfirm).contains("Delete"); cy.get(this.deleteDialogCancelBtn).contains("Cancel").click(); cy.get('ul[class*="pf-c-data-list"]').should( "have.text", @@ -802,7 +803,8 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "The action will permanently delete secure-ciba-signed-authn-req. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.findByTestId(this.modalConfirm).click(); cy.get('h6[class*="kc-emptyExecutors"]').should( "have.text", "No executors configured" @@ -813,12 +815,12 @@ export default class RealmSettingsPage { cy.get('[data-label="Name"]') .contains("Edit") .parentsUntil("tbody") - .get(this.moreDrpDwn) - .last() - .click() - .get(this.moreDrpDwnItems) - .click(); - cy.findByTestId("modalConfirm").contains("Delete").click(); + .within(() => { + cy.get(this.moreDrpDwn).click(); + }); + cy.get(this.moreDrpDwnItems).click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.findByTestId(this.modalConfirm).click(); cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.get("table").should("not.have.text", "Edit"); } @@ -843,7 +845,8 @@ export default class RealmSettingsPage { ); cy.get(this.createClientDrpDwn).contains("Action").click(); cy.findByTestId("deleteClientProfileDropdown").click(); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.findByTestId(this.modalConfirm).click(); cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.get("table").should("not.have.text", "Test Again Description"); } @@ -956,7 +959,7 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "This action will permanently delete the profile Test. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete"); + cy.findByTestId(this.modalConfirm).contains("Delete"); cy.get(this.deleteDialogCancelBtn).contains("Cancel").click(); cy.get("table").should("be.visible").contains("td", "Test"); } @@ -1008,11 +1011,11 @@ export default class RealmSettingsPage { addClientScopes() { cy.findByTestId(this.selectScopeButton).click(); - cy.get(".pf-c-table__check > label > input[name=checkrow0]").click(); - cy.get(".pf-c-table__check > label > input[name=checkrow1]").click(); - cy.get(".pf-c-table__check > label > input[name=checkrow2]").click(); + cy.get(".pf-c-table__check > input[name=checkrow0]").click(); + cy.get(".pf-c-table__check > input[name=checkrow1]").click(); + cy.get(".pf-c-table__check > input[name=checkrow2]").click(); - cy.findByTestId("modalConfirm").contains("Add").click(); + cy.findByTestId(this.modalConfirm).contains("Add").click(); } shouldAddClientScopesCondition() { @@ -1079,8 +1082,9 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "This action will permanently delete client-roles. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete"); - cy.get(this.deleteDialogCancelBtn).contains("Cancel").click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.get(this.deleteDialogCancelBtn).contains("Cancel"); + cy.get(this.deleteDialogCancelBtn).click(); cy.get('ul[class*="pf-c-data-list"]').contains("client-roles"); } @@ -1091,7 +1095,8 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "This action will permanently delete client-roles. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.findByTestId(this.modalConfirm).click(); cy.get('ul[class*="pf-c-data-list"]').contains("client-scopes"); } @@ -1102,7 +1107,8 @@ export default class RealmSettingsPage { cy.get(this.deleteDialogBodyText).contains( "This action will permanently delete client-scopes. This cannot be undone." ); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete"); + cy.findByTestId(this.modalConfirm).click(); cy.get('h6[class*="kc-emptyConditions"]').should( "have.text", "No conditions configured" @@ -1112,7 +1118,7 @@ export default class RealmSettingsPage { shouldDeleteClientPolicyDialog() { this.listingPage.searchItem("Test", false); this.listingPage.clickRowDetails("Test").clickDetailMenu("Delete"); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete").click(); cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.get("table").should("not.have.text", "Test"); } @@ -1135,7 +1141,7 @@ export default class RealmSettingsPage { cy.findByTestId(this.clientPolicyDrpDwn).contains("Action").click(); cy.findByTestId("deleteClientPolicyDropdown").click(); - cy.findByTestId("modalConfirm").contains("Delete").click(); + cy.findByTestId(this.modalConfirm).contains("Delete").click(); cy.get(this.alertMessage).should("be.visible", "Client profile deleted"); cy.findByTestId(this.createPolicyEmptyStateBtn).should("exist"); } diff --git a/cypress/support/util/AdminClient.ts b/cypress/support/util/AdminClient.ts index c25f08b900..423a26e170 100644 --- a/cypress/support/util/AdminClient.ts +++ b/cypress/support/util/AdminClient.ts @@ -52,6 +52,11 @@ export default class AdminClient { await this.client.clients.del({ id: client.id! }); } + async createGroup(groupName: string) { + await this.login(); + return await this.client.groups.create({ name: groupName }); + } + async createSubGroups(groups: string[]) { await this.login(); let parentGroup = undefined; diff --git a/cypress/support/util/ModalUtils.ts b/cypress/support/util/ModalUtils.ts index 26099fddfb..956dbf4535 100644 --- a/cypress/support/util/ModalUtils.ts +++ b/cypress/support/util/ModalUtils.ts @@ -2,18 +2,18 @@ export default class ModalUtils { private modalTitle = ".pf-c-modal-box .pf-c-modal-box__title-text"; private modalMessage = ".pf-c-modal-box .pf-c-modal-box__body"; - private confirmModalBtn = "#modal-confirm"; - private cancelModalBtn = "#modal-cancel"; + private confirmModalBtn = "confirm"; + private cancelModalBtn = "cancel"; private closeModalBtn = ".pf-c-modal-box .pf-m-plain"; confirmModal(force = false) { - cy.get(this.confirmModalBtn).click({ force }); + cy.findByTestId(this.confirmModalBtn).click({ force }); return this; } cancelModal() { - cy.get(this.cancelModalBtn).click(); + cy.findByTestId(this.cancelModalBtn).click(); return this; } diff --git a/src/client-scopes/add/MapperDialog.test.tsx b/src/client-scopes/add/MapperDialog.test.tsx index 074b793715..af1b99f2b9 100644 --- a/src/client-scopes/add/MapperDialog.test.tsx +++ b/src/client-scopes/add/MapperDialog.test.tsx @@ -43,7 +43,7 @@ describe("MapperDialog", () => { fireEvent.click(screen.getByText("Show")); - expect(screen.getByTestId("modalConfirm")).toHaveClass("pf-m-disabled"); + expect(screen.getByTestId("confirm")).toHaveClass("pf-m-disabled"); }); it("returns array with selected build in protocol mapping", () => { @@ -55,7 +55,7 @@ describe("MapperDialog", () => { fireEvent.click(screen.getByText("Show")); fireEvent.click(screen.getByLabelText("Select row 0")); fireEvent.click(screen.getByLabelText("Select row 1")); - fireEvent.click(screen.getByTestId("modalConfirm")); + fireEvent.click(screen.getByTestId("confirm")); expect(onConfirm).toBeCalledWith([ serverInfo.builtinProtocolMappers[protocol][0], diff --git a/src/client-scopes/add/MapperDialog.tsx b/src/client-scopes/add/MapperDialog.tsx index c7f77f637a..6616e25cba 100644 --- a/src/client-scopes/add/MapperDialog.tsx +++ b/src/client-scopes/add/MapperDialog.tsx @@ -107,7 +107,7 @@ export const AddMapperDialog = (props: AddMapperDialogProps) => { ? [ , , , , , , , , , , , , , ,