From c6aea1cd448769be5f54fa42d04472ae90ecff06 Mon Sep 17 00:00:00 2001 From: Dominik Kawka <31955648+dominikkawka@users.noreply.github.com> Date: Wed, 14 Sep 2022 11:44:30 +0100 Subject: [PATCH] Group role mapping tests (#3314) --- apps/admin-ui/cypress/e2e/group_test.spec.ts | 36 +++++++++++++++++++ .../pages/admin_console/ListingPage.ts | 11 ++++++ .../groups/group_details/GroupDetailPage.ts | 27 ++++++++++++++ .../components/role-mapping/RoleMapping.tsx | 1 + 4 files changed, 75 insertions(+) diff --git a/apps/admin-ui/cypress/e2e/group_test.spec.ts b/apps/admin-ui/cypress/e2e/group_test.spec.ts index 4a92fbb35d..f825e936d6 100644 --- a/apps/admin-ui/cypress/e2e/group_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/group_test.spec.ts @@ -10,6 +10,8 @@ import ChildGroupsTab from "../support/pages/admin_console/manage/groups/group_d import MembersTab from "../support/pages/admin_console/manage/groups/group_details/tabs/MembersTab"; import adminClient from "../support/util/AdminClient"; import { range } from "lodash-es"; +import RoleMappingTab from "../support/pages/admin_console/manage/RoleMappingTab"; +import CommonPage from "../support/pages/CommonPage"; describe("Group test", () => { const loginPage = new LoginPage(); @@ -21,6 +23,7 @@ describe("Group test", () => { const groupDetailPage = new GroupDetailPage(); const childGroupsTab = new ChildGroupsTab(); const membersTab = new MembersTab(); + const commonPage = new CommonPage(); const groupNamePrefix = "group_"; let groupName: string; @@ -474,6 +477,39 @@ describe("Group test", () => { }); }); + describe("Role mappings", () => { + const roleMappingTab = new RoleMappingTab("group"); + beforeEach(() => { + groupPage.goToGroupChildGroupsTab(predefinedGroups[0]); + groupDetailPage.goToRoleMappingTab(); + }); + + it("Check empty state", () => { + commonPage.emptyState().checkIfExists(true); + }); + + it("Assign roles from empty state", () => { + roleMappingTab.assignRole(); + groupDetailPage.createRoleMappingSearch(); + roleMappingTab.assign(); + }); + + it("Show and search roles", () => { + groupDetailPage.checkRoles(); + }); + + it("Check hide inherited roles option", () => { + roleMappingTab.unhideInheritedRoles(); + roleMappingTab.hideInheritedRoles(); + }); + + it("Remove roles", () => { + roleMappingTab.selectRow("offline_access"); + roleMappingTab.unAssign(); + groupDetailPage.deleteRole(); + }); + }); + describe("Permissions", () => { beforeEach(() => { groupPage.goToGroupChildGroupsTab(predefinedGroups[0]); diff --git a/apps/admin-ui/cypress/support/pages/admin_console/ListingPage.ts b/apps/admin-ui/cypress/support/pages/admin_console/ListingPage.ts index 8b2057fd83..b7d2e20c0c 100644 --- a/apps/admin-ui/cypress/support/pages/admin_console/ListingPage.ts +++ b/apps/admin-ui/cypress/support/pages/admin_console/ListingPage.ts @@ -64,6 +64,9 @@ export default class ListingPage extends CommonElements { private tableHeaderCheckboxItemAllRows = "input[aria-label='Select all rows']"; + private searchBtnInModal = + ".pf-c-modal-box .pf-c-toolbar__content-section button.pf-m-control:visible"; + showPreviousPageTableItems() { cy.get(this.previousPageBtn).first().click(); @@ -110,6 +113,14 @@ export default class ListingPage extends CommonElements { return this; } + searchItemInModal(searchValue: string) { + cy.get(this.searchInput).clear(); + if (searchValue) { + cy.get(this.searchInput).type(searchValue); + } + cy.get(this.searchBtnInModal).click({ force: true }); + } + checkTableLength(length: number, identifier: string) { cy.get("table") .should("have.class", identifier) diff --git a/apps/admin-ui/cypress/support/pages/admin_console/manage/groups/group_details/GroupDetailPage.ts b/apps/admin-ui/cypress/support/pages/admin_console/manage/groups/group_details/GroupDetailPage.ts index 02a3a145d3..1b517cd5df 100644 --- a/apps/admin-ui/cypress/support/pages/admin_console/manage/groups/group_details/GroupDetailPage.ts +++ b/apps/admin-ui/cypress/support/pages/admin_console/manage/groups/group_details/GroupDetailPage.ts @@ -1,7 +1,10 @@ import ModalUtils from "../../../../../util/ModalUtils"; +import ListingPage from "../../../ListingPage"; import GroupPage from "../GroupPage"; const modalUtils = new ModalUtils(); +const listingPage = new ListingPage(); +const groupPage = new GroupPage(); export default class GroupDetailPage extends GroupPage { private groupNamesColumn = '[data-label="Group name"] > a'; @@ -146,4 +149,28 @@ export default class GroupDetailPage extends GroupPage { this.assertSwitchStateOff(cy.findByTestId(this.permissionSwitch)); return this; } + + createRoleMapping() { + listingPage.clickItemCheckbox("default-roles-"); + } + + createRoleMappingSearch() { + listingPage.searchItemInModal("offline_access"); + listingPage.clickItemCheckbox("offline_access"); + } + + checkRoles() { + listingPage.itemExist("offline_access"); + listingPage.searchItem("offline_access", false); + listingPage.itemExist("offline_access"); + listingPage.searchItem("non-existant-role", false); + groupPage.assertNoSearchResultsMessageExist(true); + } + + deleteRole() { + modalUtils + .checkModalTitle("Remove mapping?") + .checkConfirmButtonText("Remove") + .confirmModal(); + } } diff --git a/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx b/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx index 378ed6dcf1..f70d577ed6 100644 --- a/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx +++ b/apps/admin-ui/src/components/role-mapping/RoleMapping.tsx @@ -210,6 +210,7 @@ export const RoleMapping = ({ { setHide(check);