From 8b08a43af12a93b80a38f0ead4068e2322a93178 Mon Sep 17 00:00:00 2001 From: ikhomyn <89014675+ikhomyn@users.noreply.github.com> Date: Thu, 19 May 2022 15:43:48 +0200 Subject: [PATCH] Refactor & new events tests (#2666) --- cypress/integration/events_test.spec.ts | 373 ++++++++++++++++-- cypress/support/pages/CommonElements.ts | 5 + .../pages/admin_console/ListingPage.ts | 33 ++ .../admin_console/components/PageObject.ts | 320 +++++++++++++++ .../manage/events/AdminEventsTab.ts | 90 ----- .../admin_console/manage/events/EventsPage.ts | 23 ++ .../manage/events/UserEventsTab.ts | 73 ---- .../manage/events/tabs/AdminEventsTab.ts | 307 ++++++++++++++ .../manage/events/tabs/UserEventsTab.ts | 204 ++++++++++ .../realm_settings/RealmSettingsPage.ts | 19 +- .../tabs/RealmSettingsEventsTab.ts | 31 ++ .../AdminEventsSettingsTab.ts | 41 ++ .../EventListenersTab.ts | 3 + .../UserEventsSettingsTab.ts | 40 ++ cypress/support/util/AdminClient.ts | 9 + cypress/support/util/ModalUtils.ts | 12 + 16 files changed, 1380 insertions(+), 203 deletions(-) create mode 100644 cypress/support/pages/admin_console/components/PageObject.ts delete mode 100644 cypress/support/pages/admin_console/manage/events/AdminEventsTab.ts create mode 100644 cypress/support/pages/admin_console/manage/events/EventsPage.ts delete mode 100644 cypress/support/pages/admin_console/manage/events/UserEventsTab.ts create mode 100644 cypress/support/pages/admin_console/manage/events/tabs/AdminEventsTab.ts create mode 100644 cypress/support/pages/admin_console/manage/events/tabs/UserEventsTab.ts create mode 100644 cypress/support/pages/admin_console/manage/realm_settings/tabs/RealmSettingsEventsTab.ts create mode 100644 cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/AdminEventsSettingsTab.ts create mode 100644 cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/EventListenersTab.ts create mode 100644 cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/UserEventsSettingsTab.ts diff --git a/cypress/integration/events_test.spec.ts b/cypress/integration/events_test.spec.ts index 4d472f46fc..bc0fcce06b 100644 --- a/cypress/integration/events_test.spec.ts +++ b/cypress/integration/events_test.spec.ts @@ -1,20 +1,90 @@ import LoginPage from "../support/pages/LoginPage"; import SidebarPage from "../support/pages/admin_console/SidebarPage"; -import UserEventsTab from "../support/pages/admin_console/manage/events/UserEventsTab"; -import AdminEventsTab from "../support/pages/admin_console/manage/events/AdminEventsTab"; +import UserEventsTab, { + UserEventSearchData, +} from "../support/pages/admin_console/manage/events/tabs/UserEventsTab"; +import AdminEventsTab from "../support/pages/admin_console/manage/events/tabs/AdminEventsTab"; import RealmSettingsPage from "../support/pages/admin_console/manage/realm_settings/RealmSettingsPage"; import Masthead from "../support/pages/admin_console/Masthead"; import { keycloakBefore } from "../support/util/keycloak_hooks"; +import EventsPage, { + EventsTab, +} from "../support/pages/admin_console/manage/events/EventsPage"; +import ListingPage from "../support/pages/admin_console/ListingPage"; +import adminClient from "../support/util/AdminClient"; const loginPage = new LoginPage(); const sidebarPage = new SidebarPage(); const userEventsTab = new UserEventsTab(); +const eventsPage = new EventsPage(); const adminEventsTab = new AdminEventsTab(); const realmSettingsPage = new RealmSettingsPage(); const masthead = new Masthead(); +const listingPage = new ListingPage(); + +const dateFrom = new Date(); +dateFrom.setDate(dateFrom.getDate() - 100); +const dateFromFormatted = `${dateFrom.getFullYear()}-${dateFrom.getMonth()}-${dateFrom.getDay()}`; +const dateTo = new Date(); +dateTo.setDate(dateTo.getDate() + 100); +const dateToFormatted = `${dateTo.getFullYear()}-${dateTo.getMonth()}-${dateTo.getDay()}`; describe("Events tests", () => { - describe.skip("Search user events", () => { + const eventsTestUser = { + eventsTestUserId: "", + userRepresentation: { + username: "events-test", + enabled: true, + credentials: [{ value: "events-test" }], + }, + }; + const eventsTestUserClientId = "admin-cli"; + + before(async () => { + const result = await adminClient.createUser( + eventsTestUser.userRepresentation + ); + eventsTestUser.eventsTestUserId = result.id; + }); + + after(() => + adminClient.deleteUser(eventsTestUser.userRepresentation.username) + ); + + describe("User events list", () => { + beforeEach(() => { + keycloakBefore(); + loginPage.logIn(); + sidebarPage.goToEvents(); + }); + + it("Show empty when no save events", () => { + sidebarPage.goToRealmSettings(); + realmSettingsPage + .goToEventsTab() + .goToUserEventsSettingsSubTab() + .enableSaveEventsSwitch() + .save() + .clearUserEvents(); + sidebarPage.goToEvents(); + eventsPage.goToUserEventsTab(); + userEventsTab.assertNoSearchResultsExist(true); + }); + + it("Expand item to see more information", () => { + listingPage.expandRow(0).assertExpandedRowContainText(0, "code_id"); + }); + }); + + describe("Search user events list", () => { + const eventTypes = [ + "LOGOUT", + "CODE_TO_TOKEN", + "CODE_TO_TOKEN_ERROR", + "LOGIN_ERROR", + "LOGIN", + ]; + beforeEach(() => { keycloakBefore(); loginPage.logIn(); @@ -23,43 +93,263 @@ describe("Events tests", () => { it("Check search dropdown display", () => { sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-realm-events-tab").click(); - cy.findByTestId("rs-events-tab").click(); - realmSettingsPage - .toggleSwitch(realmSettingsPage.enableEvents) - .save(realmSettingsPage.eventsUserSave); + .goToEventsTab() + .goToUserEventsSettingsSubTab() + .disableSaveEventsSwitch() + .save(); masthead.signOut(); loginPage.logIn(); sidebarPage.goToEvents(); - - userEventsTab.shouldDisplay(); + eventsPage.tabUtils().checkIsCurrentTab(EventsTab.UserEvents); + userEventsTab.assertSearchUserEventDropdownMenuExist(true); }); it("Check user events search form fields display", () => { - userEventsTab.shouldHaveFormFields(); + userEventsTab + .openSearchUserEventDropdownMenu() + .assertUserSearchDropdownMenuHasLabels(); }); it("Check event type dropdown options exist", () => { - userEventsTab.shouldHaveEventTypeOptions(); + userEventsTab + .openSearchUserEventDropdownMenu() + .openEventTypeSelectMenu() + .clickEventTypeSelectItem(eventTypes[0]) + .clickEventTypeSelectItem(eventTypes[1]) + .clickEventTypeSelectItem(eventTypes[2]) + .clickEventTypeSelectItem(eventTypes[3]) + .closeEventTypeSelectMenu(); }); it("Check `search events` button disabled by default", () => { - userEventsTab.shouldHaveSearchBtnDisabled(); + userEventsTab + .openSearchUserEventDropdownMenu() + .assertSearchEventBtnIsEnabled(false); }); - it.skip("Check user events search and removal work", () => { - userEventsTab.shouldDoSearchAndRemoveChips(); + it("Check user events search and removal work", () => { + userEventsTab + .searchUserEventByEventType([eventTypes[0]]) + .assertEventTypeChipGroupItemExist(eventTypes[0], true) + .assertEventTypeChipGroupItemExist(eventTypes[1], false) + .assertEventTypeChipGroupItemExist(eventTypes[2], false) + .assertEventTypeChipGroupItemExist(eventTypes[3], false) + .assertNoSearchResultsExist(true) + .removeEventTypeChipGroupItem(eventTypes[0]) + .assertEventTypeChipGroupExist(false); }); it("Check for no events logged", () => { - userEventsTab.shouldDoNoResultsSearch(); + userEventsTab + .searchUserEventByUserId("test") + .assertNoSearchResultsExist(true); }); it("Check `search events` button enabled", () => { - userEventsTab.shouldHaveSearchBtnEnabled(); + userEventsTab + .openSearchUserEventDropdownMenu() + .assertSearchEventBtnIsEnabled(false) + .typeUserId("11111") + .assertSearchEventBtnIsEnabled(true); + }); + + it("Search by user ID", () => { + sidebarPage.goToRealmSettings(); + realmSettingsPage + .goToEventsTab() + .goToUserEventsSettingsSubTab() + .enableSaveEventsSwitch() + .save(); + sidebarPage.goToEvents(); + cy.wrap(null).then(() => + adminClient.loginUser( + eventsTestUser.userRepresentation.username, + eventsTestUser.userRepresentation.credentials[0].value, + eventsTestUserClientId + ) + ); + userEventsTab + .searchUserEventByUserId(eventsTestUser.eventsTestUserId) + .assertUserIdChipGroupExist(true) + .assertEventTypeChipGroupExist(false) + .assertClientChipGroupExist(false) + .assertDateFromChipGroupExist(false) + .assertDateToChipGroupExist(false); + listingPage.itemsGreaterThan(0); + }); + + it("Search by event type", () => { + userEventsTab + .searchUserEventByEventType([eventTypes[4]]) + .assertUserIdChipGroupExist(false) + .assertEventTypeChipGroupExist(true) + .assertClientChipGroupExist(false) + .assertDateFromChipGroupExist(false) + .assertDateToChipGroupExist(false); + listingPage.itemsGreaterThan(0); + }); + + it("Search by client", () => { + userEventsTab + .searchUserEventByClient(eventsTestUserClientId) + .assertUserIdChipGroupExist(false) + .assertEventTypeChipGroupExist(false) + .assertClientChipGroupExist(true) + .assertDateFromChipGroupExist(false) + .assertDateToChipGroupExist(false); + listingPage.itemsGreaterThan(0); + }); + + it("Search by date from", () => { + userEventsTab + .searchUserEventByDateFrom(dateFromFormatted) + .assertUserIdChipGroupExist(false) + .assertEventTypeChipGroupExist(false) + .assertClientChipGroupExist(false) + .assertDateFromChipGroupExist(true) + .assertDateToChipGroupExist(false); + listingPage.itemsGreaterThan(0); + }); + + it("Search by dato to", () => { + userEventsTab + .searchUserEventByDateTo(dateToFormatted) + .assertUserIdChipGroupExist(false) + .assertEventTypeChipGroupExist(false) + .assertClientChipGroupExist(false) + .assertDateFromChipGroupExist(false) + .assertDateToChipGroupExist(true); + listingPage.itemsGreaterThan(0); + }); + + it("Search by all elements", () => { + const searchData = new UserEventSearchData(); + searchData.client = eventsTestUserClientId; + searchData.userId = eventsTestUser.eventsTestUserId; + searchData.eventType = [eventTypes[4]]; + searchData.dateFrom = dateFromFormatted; + searchData.dateTo = dateToFormatted; + userEventsTab + .searchUserEvent(searchData) + .assertUserIdChipGroupExist(true) + .assertEventTypeChipGroupExist(true) + .assertClientChipGroupExist(true) + .assertDateFromChipGroupExist(true) + .assertDateToChipGroupExist(true); + listingPage.itemsGreaterThan(0); + }); + }); + + describe("Admin events list", () => { + beforeEach(() => { + keycloakBefore(); + loginPage.logIn(); + sidebarPage.goToEvents(); + eventsPage.goToAdminEventsTab(); + }); + + it("Show events", () => { + sidebarPage.goToRealmSettings(); + realmSettingsPage + .goToEventsTab() + .goToAdminEventsSettingsSubTab() + .enableSaveEvents() + .save(); + sidebarPage.goToEvents(); + eventsPage.goToAdminEventsTab(); + listingPage.itemsGreaterThan(0); + }); + + it("Show empty when no save events", () => { + sidebarPage.goToRealmSettings(); + realmSettingsPage + .goToEventsTab() + .goToAdminEventsSettingsSubTab() + .disableSaveEvents() + .save() + .clearAdminEvents(); + sidebarPage.goToEvents(); + eventsPage.goToAdminEventsTab(); + adminEventsTab.assertNoSearchResultsExist(true); + }); + }); + + describe("Search admin events list", () => { + const resourceTypes = ["REALM"]; + const operationTypes = ["UPDATE"]; + + beforeEach(() => { + keycloakBefore(); + loginPage.logIn(); + sidebarPage.goToEvents(); + eventsPage.goToAdminEventsTab(); + }); + + it("Search by resource types", () => { + sidebarPage.goToRealmSettings(); + realmSettingsPage + .goToEventsTab() + .goToAdminEventsSettingsSubTab() + .enableSaveEvents() + .save(); + sidebarPage.goToEvents(); + eventsPage.goToAdminEventsTab(); + adminEventsTab + .searchAdminEventByResourceTypes([resourceTypes[0]]) + .assertResourceTypesChipGroupExist(true); + listingPage.itemsGreaterThan(0); + }); + + it("Search by operation types", () => { + adminEventsTab + .searchAdminEventByOperationTypes([operationTypes[0]]) + .assertOperationTypesChipGroupExist(true); + listingPage.itemsGreaterThan(0); + }); + + it("Search by resource path", () => { + adminEventsTab + .searchAdminEventByResourcePath("test") + .assertResourcePathChipGroupExist(true); + }); + + it("Search by realm", () => { + adminEventsTab + .searchAdminEventByRealm("master") + .assertRealmChipGroupExist(true); + }); + + it("Search by client", () => { + adminEventsTab + .searchAdminEventByClient("admin-cli") + .assertClientChipGroupExist(true); + }); + + it("Search by user ID", () => { + adminEventsTab + .searchAdminEventByUser("test") + .assertUserChipGroupExist(true); + }); + + it("Search by IP address", () => { + adminEventsTab + .searchAdminEventByIpAddress("test") + .assertIpAddressChipGroupExist(true); + }); + + it("Search by date from", () => { + adminEventsTab + .searchAdminEventByDateTo(dateToFormatted) + .assertDateToChipGroupExist(true); + }); + + it("Search by date to", () => { + adminEventsTab + .searchAdminEventByDateFrom(dateFromFormatted) + .assertDateFromChipGroupExist(true); }); }); @@ -68,40 +358,50 @@ describe("Events tests", () => { keycloakBefore(); loginPage.logIn(); sidebarPage.goToEvents(); - cy.findByTestId("admin-events-tab").click(); + eventsPage.goToAdminEventsTab(); }); it("Check admin events search form fields display", () => { sidebarPage.goToRealmSettings(); - cy.findByTestId("rs-realm-events-tab").click(); - cy.findByTestId("rs-admin-events-tab").click(); - realmSettingsPage - .toggleSwitch(realmSettingsPage.enableAdminEvents) - .save(realmSettingsPage.eventsAdminSave); - + .goToEventsTab() + .goToAdminEventsSettingsSubTab() + .disableSaveEvents() + .save(); sidebarPage.goToEvents(); - cy.findByTestId("admin-events-tab").click(); - sidebarPage.waitForPageLoad(); - adminEventsTab.shouldHaveFormFields(); + eventsPage.goToAdminEventsTab(); + adminEventsTab + .openSearchAdminEventDropdownMenu() + .assertAdminSearchDropdownMenuHasLabels(); }); it("Check `search admin events` button disabled by default", () => { - adminEventsTab.shouldHaveSearchBtnDisabled(); + adminEventsTab + .openSearchAdminEventDropdownMenu() + .assertSearchAdminBtnEnabled(false); }); it("Check admin events search and removal work", () => { sidebarPage.goToEvents(); - cy.findByTestId("admin-events-tab").click(); - adminEventsTab.shouldDoAdminEventsSearchAndRemoveChips(); + eventsPage + .goToAdminEventsTab() + .searchAdminEventByResourcePath("events/config") + .assertResourcePathChipGroupItemExist("events/config", true) + .removeResourcePathChipGroup(); + listingPage.itemContainValue("UPDATE", 3, "UPDATE"); }); it("Check for no events logged", () => { - adminEventsTab.shouldDoNoResultsSearch(); + adminEventsTab + .searchAdminEventByResourcePath("events/test") + .assertNoSearchResultsExist(true); }); it("Check `search admin events` button enabled", () => { - adminEventsTab.shouldHaveSearchBtnEnabled(); + adminEventsTab + .openSearchAdminEventDropdownMenu() + .typeIpAddress("11111") + .assertSearchAdminBtnEnabled(true); }); }); @@ -110,16 +410,17 @@ describe("Events tests", () => { keycloakBefore(); loginPage.logIn(); sidebarPage.goToEvents(); - cy.findByTestId("admin-events-tab").click(); + eventsPage.goToAdminEventsTab(); }); it("Check auth dialog opens and is not empty", () => { - adminEventsTab.shouldCheckAuthDialogOpensAndIsNotEmpty(); + listingPage.clickRowDetails("UPDATE").clickDetailMenu("Auth"); + adminEventsTab.assertAuthDialogIsNotEmpty(); }); it("Check representation dialog opens and is not empty", () => { - sidebarPage.waitForPageLoad(); - adminEventsTab.shouldCheckRepDialogOpensAndIsNotEmpty(); + listingPage.clickRowDetails("UPDATE").clickDetailMenu("Representation"); + adminEventsTab.assertRepresentationDialogIsNotEmpty(); }); }); }); diff --git a/cypress/support/pages/CommonElements.ts b/cypress/support/pages/CommonElements.ts index 1e60610019..7ec5f12fa9 100644 --- a/cypress/support/pages/CommonElements.ts +++ b/cypress/support/pages/CommonElements.ts @@ -26,6 +26,11 @@ export default class CommonElements { this.parentSelector + ".pf-c-select__menu > li"; } + clickPrimaryBtn() { + cy.get(this.primaryBtn).click(); + return this; + } + clickSecondaryBtn(buttonName: string) { cy.get(this.secondaryBtn).contains(buttonName).click(); return this; diff --git a/cypress/support/pages/admin_console/ListingPage.ts b/cypress/support/pages/admin_console/ListingPage.ts index 6e463b79df..d62c41f5fb 100644 --- a/cypress/support/pages/admin_console/ListingPage.ts +++ b/cypress/support/pages/admin_console/ListingPage.ts @@ -60,6 +60,7 @@ export default class ListingPage extends CommonElements { private changeTypeToButton = ".pf-c-select__toggle"; private toolbarChangeType = "#change-type-dropdown"; private tableNameColumnPrefix = "name-column-"; + private rowGroup = "table:visible tbody[role='rowgroup']"; showPreviousPageTableItems() { cy.get(this.previousPageBtn).first().click(); @@ -371,4 +372,36 @@ export default class ListingPage extends CommonElements { this.getResourceLink(name).should("exist"); return this; } + + private getRowGroup(index = 0) { + return cy.get(this.rowGroup).eq(index); + } + + expandRow(index = 0) { + this.getRowGroup(index) + .find("[class='pf-c-button pf-m-plain'][id*='expandable']") + .click(); + return this; + } + + collapseRow(index = 0) { + this.getRowGroup(index) + .find("[class='pf-c-button pf-m-plain pf-m-expanded'][id*='expandable']") + .click(); + return this; + } + + assertExpandedRowContainText(index = 0, text: string) { + this.getRowGroup(index) + .find("tr[class='pf-c-table__expandable-row pf-m-expanded']") + .should("contain.text", text); + return this; + } + + assertRowIsExpanded(index = 0, isExpanded: boolean) { + this.getRowGroup(index) + .find("[class='pf-c-button pf-m-plain pf-m-expanded'][id*='expandable']") + .should((!isExpanded ? "not." : "") + "exist"); + return this; + } } diff --git a/cypress/support/pages/admin_console/components/PageObject.ts b/cypress/support/pages/admin_console/components/PageObject.ts new file mode 100644 index 0000000000..852480bf06 --- /dev/null +++ b/cypress/support/pages/admin_console/components/PageObject.ts @@ -0,0 +1,320 @@ +export default class PageObject { + private selectItemSelectedIcon = ".pf-c-select__menu-item-icon"; + private drpDwnMenuList = ".pf-c-dropdown__menu"; + private drpDwnMenuItem = ".pf-c-dropdown__menu-item"; + private drpDwnMenuToggleBtn = ".pf-c-dropdown__toggle"; + private selectMenuList = ".pf-c-select__menu"; + private selectMenuItem = ".pf-c-select__menu-item"; + private selectMenuToggleBtn = ".pf-c-select__toggle"; + private switchInput = ".pf-c-switch__input"; + private formLabel = ".pf-c-form__label"; + private chipGroup = ".pf-c-chip-group"; + private chipGroupCloseBtn = ".pf-c-chip-group__close"; + private chipItem = ".pf-c-chip-group__list-item"; + + protected assertExist(element: Cypress.Chainable, exist: boolean) { + element.should((!exist ? "not." : "") + "exist"); + return this; + } + + protected assertIsVisible( + element: Cypress.Chainable, + isVisible: boolean + ) { + element.should((!isVisible ? "not." : "") + "be.visible"); + return this; + } + + protected assertIsEnabled( + element: Cypress.Chainable, + isEnabled = true + ) { + element.then(($btn) => { + if ($btn.hasClass("pf-m-disabled")) { + element.should( + (isEnabled ? "not." : "") + "have.class", + "pf-m-disabled" + ); + } else { + element.should((isEnabled ? "not." : "") + "have.attr", "disabled"); + } + }); + return this; + } + + protected assertIsDisabled(element: Cypress.Chainable) { + return this.assertIsEnabled(element, false); + } + + protected assertHaveText(element: Cypress.Chainable, text: string) { + element.should("have.text", text); + return this; + } + + protected assertHaveValue(element: Cypress.Chainable, value: string) { + element.should("have.value", value); + return this; + } + + protected assertSwitchStateOn( + element?: Cypress.Chainable, + isOn = true + ) { + (element ?? cy.get(this.switchInput)) + .parent() + .contains(isOn ? "On" : "Off") + .should("be.visible"); + return this; + } + + protected assertSwitchStateOff(element?: Cypress.Chainable) { + return this.assertSwitchStateOn(element, false); + } + + protected assertDropdownMenuIsOpen( + isOpen = true, + element?: Cypress.Chainable + ) { + this.assertExist(element ?? cy.get(this.drpDwnMenuList), isOpen); + return this; + } + + protected assertDropdownMenuIsClosed(element?: Cypress.Chainable) { + return this.assertDropdownMenuIsOpen( + false, + element ?? cy.get(this.drpDwnMenuList) + ); + } + + protected clickDropdownMenuItem( + itemName: string, + element?: Cypress.Chainable + ) { + (element ?? cy.get(this.drpDwnMenuItem)).contains(itemName).click(); + return this; + } + + protected clickDropdownMenuToggleButton( + itemName: string, + element?: Cypress.Chainable + ) { + element = + element ?? + cy.get(this.drpDwnMenuToggleBtn).contains(itemName).parent().parent(); + element.click(); + return this; + } + + protected openDropdownMenu( + itemName: string, + element?: Cypress.Chainable + ) { + element = + element ?? + cy.get(this.drpDwnMenuToggleBtn).contains(itemName).parent().parent(); + this.clickDropdownMenuToggleButton(itemName, element); + this.assertDropdownMenuIsOpen(true); + return this; + } + + protected closeDropdownMenu( + itemName: string, + element?: Cypress.Chainable + ) { + element = + element ?? + cy.get(this.drpDwnMenuToggleBtn).contains(itemName).parent().parent(); + this.clickDropdownMenuToggleButton(itemName, element); + this.assertDropdownMenuIsOpen(false); + return this; + } + + protected assertDropdownMenuItemIsSelected( + itemName: string, + isSelected: boolean, + element?: Cypress.Chainable + ) { + element = element ?? cy.get(this.drpDwnMenuItem); + this.assertExist( + element.contains(itemName).find(this.selectItemSelectedIcon), + isSelected + ); + return this; + } + + protected assertDropdownMenuHasItems( + items: string[], + element?: Cypress.Chainable + ) { + const initialElement = element; + for (const item of items) { + element = initialElement ?? cy.get(this.drpDwnMenuList); + this.assertExist(element.find(this.drpDwnMenuItem).contains(item), true); + } + return this; + } + + protected assertDropdownMenuHasLabels( + items: string[], + element?: Cypress.Chainable + ) { + const initialElement = element; + for (const item of items) { + element = initialElement ?? cy.get(this.drpDwnMenuList); + this.assertExist(element.find(this.formLabel).contains(item), true); + } + return this; + } + + protected assertDropdownMenuItemsEqualTo( + number: number, + element?: Cypress.Chainable + ) { + element = element ?? cy.get(this.drpDwnMenuList); + element.find(this.drpDwnMenuItem).should(($item) => { + expect($item).to.have.length(number); + }); + return this; + } + + protected assertSelectMenuIsOpen( + isOpen = true, + element?: Cypress.Chainable + ) { + element = element ?? cy.get(this.selectMenuList); + return this.assertDropdownMenuIsOpen(isOpen, element); + } + + protected assertSelectMenuIsClosed(element?: Cypress.Chainable) { + element = element ?? cy.get(this.selectMenuList); + return this.assertDropdownMenuIsClosed(element); + } + + protected clickSelectMenuItem( + itemName: string, + element?: Cypress.Chainable + ) { + element = element ?? cy.get(this.selectMenuItem); + return this.clickDropdownMenuItem(itemName, element); + } + + protected clickSelectMenuToggleButton( + itemName: string, + element?: Cypress.Chainable + ) { + element = + element ?? + cy.get(this.selectMenuToggleBtn).contains(itemName).parent().parent(); + return this.clickDropdownMenuToggleButton(itemName, element); + } + + protected openSelectMenu(itemName: string, element?: Cypress.Chainable) { + element = + element ?? + cy.get(this.selectMenuToggleBtn).contains(itemName).parent().parent(); + this.clickDropdownMenuToggleButton(itemName, element); + this.assertSelectMenuIsOpen(true); + return this; + } + + protected closeSelectMenu( + itemName: string, + element?: Cypress.Chainable + ) { + element = + element ?? + cy.get(this.selectMenuToggleBtn).contains(itemName).parent().parent(); + this.clickDropdownMenuToggleButton(itemName, element); + this.assertSelectMenuIsOpen(false); + return this; + } + + protected assertSelectMenuItemIsSelected( + itemName: string, + isSelected: boolean, + element?: Cypress.Chainable + ) { + element = element ?? cy.get(this.selectMenuItem); + return this.assertDropdownMenuItemIsSelected(itemName, isSelected, element); + } + + protected assertSelectMenuHasItems( + items: string[], + element?: Cypress.Chainable + ) { + const initialElement = element; + for (const item of items) { + element = initialElement ?? cy.get(this.selectMenuList); + this.assertExist(element.find(this.selectMenuItem).contains(item), true); + } + return this; + } + + protected assertSelectMenuItemsEqualTo( + number: number, + element?: Cypress.Chainable + ) { + element = element ?? cy.get(this.selectMenuList); + element.find(this.selectMenuItem).should(($item) => { + expect($item).to.have.length(number); + }); + return this; + } + + private getChipGroup(groupName: string) { + return cy.get(this.chipGroup).contains(groupName).parent().parent(); + } + + private getChipItem(itemName: string) { + return cy.get(this.chipItem).contains(itemName).parent(); + } + + private getChipGroupItem(groupName: string, itemName: string) { + return this.getChipGroup(groupName) + .find(this.chipItem) + .contains(itemName) + .parent(); + } + + protected removeChipGroup(groupName: string) { + this.getChipGroup(groupName) + .find(this.chipGroupCloseBtn) + .find("button") + .click(); + return this; + } + + protected removeChipItem(itemName: string) { + this.getChipItem(itemName).find("button").click(); + return this; + } + + protected removeChipGroupItem(groupName: string, itemName: string) { + this.getChipGroupItem(groupName, itemName).find("button").click(); + return this; + } + + protected assertChipGroupExist(groupName: string, exist: boolean) { + this.assertExist(cy.contains(this.chipGroup, groupName), exist); + return this; + } + + protected assertChipItemExist(itemName: string, exist: boolean) { + cy.get(this.chipItem).within(() => { + cy.contains(itemName).should((exist ? "" : "not.") + "exist"); + }); + return this; + } + + protected assertChipGroupItemExist( + groupName: string, + itemName: string, + exist: boolean + ) { + this.assertExist( + this.getChipGroup(groupName).contains(this.chipItem, itemName), + exist + ); + return this; + } +} diff --git a/cypress/support/pages/admin_console/manage/events/AdminEventsTab.ts b/cypress/support/pages/admin_console/manage/events/AdminEventsTab.ts deleted file mode 100644 index 0416ae8286..0000000000 --- a/cypress/support/pages/admin_console/manage/events/AdminEventsTab.ts +++ /dev/null @@ -1,90 +0,0 @@ -export default class AdminEventsTab { - searchAdminEventDrpDwn = ".pf-c-dropdown__toggle"; - searchAdminEventDrpDwnBtn = "adminEventsSearchSelectorToggle"; - searchForm = ".pf-c-dropdown__menu"; - resourceTypesDrpDwnFld = "resource-types-searchField"; - operationTypesDrpDwnFld = "operation-types-searchField"; - resourcePathInputFld = "resourcePath-searchField"; - userInputFld = "user-searchField"; - realmInputFld = "realm-searchField"; - ipAddressInputFld = "ipAddress-searchField"; - dateFromInputFld = "dateFrom-searchField"; - dateToInputFld = "dateTo-searchField"; - searchEventsBtn = "search-events-btn"; - operationTypesList = ".pf-c-form-control"; - operationTypesOption = ".pf-c-select__menu-item"; - operationTypesInputFld = ".pf-c-form-control.pf-c-select__toggle-typeahead"; - operationTypesBtn = ".pf-c-button.pf-c-select__toggle-button.pf-m-plain"; - adminEventsTabTitle = ".pf-c-title"; - moreBtn = ".pf-c-dropdown__toggle.pf-m-plain"; - moreDrpDwnItems = ".pf-c-dropdown__menu"; - dialogTitle = ".pf-c-modal-box__title-text"; - dialogClose = `[aria-label="Close"]`; - authAttrDataRow = 'tbody > tr > [data-label="Attribute"]'; - authValDataRow = 'tbody > tr > [data-label="Value"]'; - - shouldHaveFormFields() { - cy.findByTestId(this.searchAdminEventDrpDwnBtn).click(); - cy.get(this.searchForm).contains("Resource types"); - cy.get(this.searchForm).contains("Operation types"); - cy.get(this.searchForm).contains("Resource path"); - cy.get(this.searchForm).contains("User"); - cy.get(this.searchForm).contains("Realm"); - cy.get(this.searchForm).contains("IP address"); - cy.get(this.searchForm).contains("Date(from)"); - cy.get(this.searchForm).contains("Date(to)"); - cy.get(this.searchForm).contains("Search admin events"); - } - - shouldHaveSearchBtnDisabled() { - cy.findByTestId(this.searchAdminEventDrpDwnBtn).click(); - cy.findByTestId(this.searchEventsBtn).should("have.attr", "disabled"); - } - - shouldDoAdminEventsSearchAndRemoveChips() { - cy.findByTestId(this.searchAdminEventDrpDwnBtn).click(); - cy.findByTestId(this.resourcePathInputFld).type("events/config"); - - cy.intercept("/admin/realms/master/admin-events*").as("eventsFetch"); - cy.findByTestId(this.searchEventsBtn).click(); - cy.wait("@eventsFetch"); - - cy.get("table").contains("td", "events/config").should("be.visible"); - - cy.get("[id^=remove_group]").click(); - cy.wait("@eventsFetch"); - cy.get("table").should("be.visible").contains("td", "UPDATE"); - } - - shouldHaveSearchBtnEnabled() { - cy.findByTestId(this.searchAdminEventDrpDwnBtn).click(); - cy.findByTestId(this.ipAddressInputFld).type("11111"); - cy.findByTestId(this.searchEventsBtn).should("not.have.attr", "disabled"); - } - - shouldDoNoResultsSearch() { - cy.findByTestId(this.searchAdminEventDrpDwnBtn).click(); - cy.findByTestId(this.resourcePathInputFld).type("events/test"); - cy.findByTestId(this.searchEventsBtn).click(); - cy.get(this.adminEventsTabTitle).contains("No search results"); - } - - shouldCheckAuthDialogOpensAndIsNotEmpty() { - cy.get(this.moreBtn).last().click(); - cy.get(this.moreDrpDwnItems).contains("Auth").click(); - cy.get(this.dialogTitle).contains("Auth"); - cy.get(this.authAttrDataRow).contains("Realm"); - cy.get(this.authAttrDataRow).contains("Client"); - cy.get(this.authAttrDataRow).contains("User"); - cy.get(this.authAttrDataRow).contains("IP address"); - cy.get(this.authValDataRow).should("exist"); - cy.get(this.dialogClose).click(); - } - - shouldCheckRepDialogOpensAndIsNotEmpty() { - cy.get(this.moreBtn).last().click(); - cy.get(this.moreDrpDwnItems).contains("Representation").click(); - cy.get(this.dialogTitle).contains("Representation"); - cy.get(this.dialogClose).click(); - } -} diff --git a/cypress/support/pages/admin_console/manage/events/EventsPage.ts b/cypress/support/pages/admin_console/manage/events/EventsPage.ts new file mode 100644 index 0000000000..bb3c933443 --- /dev/null +++ b/cypress/support/pages/admin_console/manage/events/EventsPage.ts @@ -0,0 +1,23 @@ +import CommonPage from "../../../CommonPage"; +import UserEventsTab from "./tabs/UserEventsTab"; +import AdminEventsTab from "./tabs/AdminEventsTab"; + +export enum EventsTab { + UserEvents = "User events", + AdminEvents = "Admin events", +} + +export default class EventsPage extends CommonPage { + private userEventsTab = new UserEventsTab(); + private adminEventsTab = new AdminEventsTab(); + + goToUserEventsTab() { + this.tabUtils().clickTab(EventsTab.UserEvents); + return this.userEventsTab; + } + + goToAdminEventsTab() { + this.tabUtils().clickTab(EventsTab.AdminEvents); + return this.adminEventsTab; + } +} diff --git a/cypress/support/pages/admin_console/manage/events/UserEventsTab.ts b/cypress/support/pages/admin_console/manage/events/UserEventsTab.ts deleted file mode 100644 index 31810cb328..0000000000 --- a/cypress/support/pages/admin_console/manage/events/UserEventsTab.ts +++ /dev/null @@ -1,73 +0,0 @@ -export default class UserEventsTab { - searchEventDrpDwn = ".pf-c-dropdown__toggle"; - searchEventDrpDwnBtn = "userEventsSearchSelectorToggle"; - searchForm = ".pf-c-dropdown__menu"; - userIdInputFld = "userId-searchField"; - eventTypeDrpDwnFld = "event-type-searchField"; - clientInputFld = "client-searchField"; - dateFromInputFld = "dateFrom-searchField"; - dateToInputFld = "dateTo-searchField"; - searchEventsBtn = "search-events-btn"; - eventTypeList = ".pf-c-form-control"; - eventTypeOption = ".pf-c-select__menu-item"; - eventTypeInputFld = ".pf-c-form-control.pf-c-select__toggle-typeahead"; - eventTypeBtn = ".pf-c-button.pf-c-select__toggle-button.pf-m-plain"; - userEventsTabTitle = ".pf-c-title"; - - shouldDisplay() { - cy.get(this.searchEventDrpDwn).should("exist"); - } - - shouldHaveFormFields() { - cy.findByTestId(this.searchEventDrpDwnBtn).click(); - cy.get(this.searchForm).contains("User ID"); - cy.get(this.searchForm).contains("Event type"); - cy.get(this.searchForm).contains("Client"); - cy.get(this.searchForm).contains("Date(from)"); - cy.get(this.searchForm).contains("Date(to)"); - cy.get(this.searchForm).contains("Search events"); - } - - shouldHaveEventTypeOptions() { - cy.findByTestId(this.searchEventDrpDwnBtn).click(); - cy.get(this.eventTypeList).should("exist"); - } - - shouldHaveSearchBtnDisabled() { - cy.findByTestId(this.searchEventDrpDwnBtn).click(); - cy.findByTestId(this.searchEventsBtn).should("have.attr", "disabled"); - } - - shouldDoSearchAndRemoveChips() { - cy.findByTestId(this.searchEventDrpDwnBtn).click(); - cy.get(this.eventTypeInputFld).type("LOGOUT"); - cy.get(this.eventTypeOption).contains("LOGOUT").click(); - - cy.intercept("/admin/realms/master/events*").as("eventsFetch"); - cy.findByTestId(this.searchEventsBtn).click(); - cy.wait("@eventsFetch"); - - cy.get("table").contains("td", "LOGOUT"); - cy.get("table").should("not.have.text", "CODE_TO_TOKEN"); - cy.get("table").should("not.have.text", "CODE_TO_TOKEN_ERROR"); - cy.get("table").should("not.have.text", "LOGIN_ERROR"); - cy.get("table").should("not.have.text", "LOGOUT"); - - cy.get("[id^=remove_group]").click(); - cy.wait("@eventsFetch"); - cy.get("table").should("not.contain", "LOGOUT"); - } - - shouldHaveSearchBtnEnabled() { - cy.findByTestId(this.searchEventDrpDwnBtn).click(); - cy.findByTestId(this.userIdInputFld).type("11111"); - cy.findByTestId(this.searchEventsBtn).should("not.have.attr", "disabled"); - } - - shouldDoNoResultsSearch() { - cy.findByTestId(this.searchEventDrpDwnBtn).click(); - cy.findByTestId(this.userIdInputFld).type("test"); - cy.findByTestId(this.searchEventsBtn).click(); - cy.get(this.userEventsTabTitle).contains("No search results"); - } -} diff --git a/cypress/support/pages/admin_console/manage/events/tabs/AdminEventsTab.ts b/cypress/support/pages/admin_console/manage/events/tabs/AdminEventsTab.ts new file mode 100644 index 0000000000..d7398114c5 --- /dev/null +++ b/cypress/support/pages/admin_console/manage/events/tabs/AdminEventsTab.ts @@ -0,0 +1,307 @@ +import ModalUtils from "../../../../../util/ModalUtils"; +import EmptyStatePage from "../../../components/EmptyStatePage"; +import PageObject from "../../../components/PageObject"; + +enum AdminEventsTabSearchFormFieldsLabel { + ResourceTypes = "Resource types", + OperationTypes = "Operation types", + ResourcePath = "Resource path", + Realm = "Realm", + Client = "Client", + User = "User", + IpAddress = "IP address", + DateFrom = "Date(from)", + DateTo = "Date(to)", +} + +export class AdminEventSearchData { + resourceTypes?: string[]; + operationTypes?: string[]; + resourcePath?: string; + realm?: string; + client?: string; + user?: string; + ipAddress?: string; + dateFrom?: string; + dateTo?: string; +} + +const emptyStatePage = new EmptyStatePage(); +const modalUtils = new ModalUtils(); + +export default class AdminEventsTab extends PageObject { + private searchAdminEventDrpDwnBtn = "adminEventsSearchSelectorToggle"; + private searchEventsBtn = "search-events-btn"; + private operationTypesInputFld = + ".pf-c-form-control.pf-c-select__toggle-typeahead"; + private authAttrDataRow = 'tbody > tr > [data-label="Attribute"]'; + private authValDataRow = 'tbody > tr > [data-label="Value"]'; + private refreshBtn = "refresh-btn"; + private resourcePathInput = "#kc-resourcePath"; + private realmInput = "#kc-realm"; + private clienInput = "#kc-client"; + private userInput = "#kc-user"; + private ipAddressInput = "#kc-ipAddress"; + private dateFromInput = "#kc-dateFrom"; + private dateToInput = "#kc-dateTo"; + + public refresh() { + cy.findByTestId(this.refreshBtn).click(); + return this; + } + + public openSearchAdminEventDropdownMenu() { + super.openDropdownMenu("", cy.findByTestId(this.searchAdminEventDrpDwnBtn)); + return this; + } + + public assertAdminSearchDropdownMenuHasLabels() { + super.assertDropdownMenuHasLabels( + Object.values(AdminEventsTabSearchFormFieldsLabel) + ); + return this; + } + + public openResourceTypesSelectMenu() { + cy.get(this.operationTypesInputFld).first().click(); + return this; + } + + public closeResourceTypesSelectMenu() { + cy.get(this.operationTypesInputFld).first().click(); + return this; + } + + public openOperationTypesSelectMenu() { + cy.get(this.operationTypesInputFld).last().click(); + return this; + } + + public closeOperationTypesSelectMenu() { + cy.get(this.operationTypesInputFld).last().click(); + return this; + } + + public typeIpAddress(ipAddress: string) { + cy.get(this.ipAddressInput).type(ipAddress); + return this; + } + + searchAdminEvent(searchData: AdminEventSearchData) { + this.openSearchAdminEventDropdownMenu(); + if (searchData.resourceTypes) { + this.openResourceTypesSelectMenu(); + searchData.resourceTypes.forEach((value) => { + super.clickSelectMenuItem(value); + }); + this.closeResourceTypesSelectMenu(); + } + if (searchData.operationTypes) { + this.openOperationTypesSelectMenu(); + searchData.operationTypes.forEach((value) => { + super.clickSelectMenuItem(value); + }); + this.closeOperationTypesSelectMenu(); + } + if (searchData.resourcePath) { + cy.get(this.resourcePathInput).type(searchData.resourcePath); + } + if (searchData.realm) { + cy.get(this.realmInput).type(searchData.realm); + } + if (searchData.client) { + cy.get(this.clienInput).type(searchData.client); + } + if (searchData.user) { + cy.get(this.userInput).type(searchData.user); + } + if (searchData.ipAddress) { + cy.get(this.ipAddressInput).type(searchData.ipAddress); + } + if (searchData.dateFrom) { + cy.get(this.dateFromInput).type(searchData.dateFrom); + } + if (searchData.dateTo) { + cy.get(this.dateToInput).type(searchData.dateTo); + } + cy.findByTestId(this.searchEventsBtn).click(); + return this; + } + + public assertSearchAdminBtnEnabled(disabled: boolean) { + super.assertIsEnabled(cy.findByTestId(this.searchEventsBtn), disabled); + return this; + } + + public searchAdminEventByResourceTypes(resourceTypes: string[]) { + const searchData = new AdminEventSearchData(); + searchData.resourceTypes = resourceTypes; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByOperationTypes(operationTypes: string[]) { + const searchData = new AdminEventSearchData(); + searchData.operationTypes = operationTypes; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByResourcePath(resourcePath: string) { + const searchData = new AdminEventSearchData(); + searchData.resourcePath = resourcePath; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByRealm(realm: string) { + const searchData = new AdminEventSearchData(); + searchData.realm = realm; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByClient(client: string) { + const searchData = new AdminEventSearchData(); + searchData.client = client; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByUser(user: string) { + const searchData = new AdminEventSearchData(); + searchData.user = user; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByIpAddress(ipAddress: string) { + const searchData = new AdminEventSearchData(); + searchData.ipAddress = ipAddress; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByDateFrom(dateFrom: string) { + const searchData = new AdminEventSearchData(); + searchData.dateFrom = dateFrom; + this.searchAdminEvent(searchData); + return this; + } + + public searchAdminEventByDateTo(dateTo: string) { + const searchData = new AdminEventSearchData(); + searchData.dateTo = dateTo; + this.searchAdminEvent(searchData); + return this; + } + + public removeResourcePathChipGroup() { + super.removeChipGroup(AdminEventsTabSearchFormFieldsLabel.ResourcePath); + return this; + } + + public assertResourceTypesChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.ResourceTypes, + exist + ); + return this; + } + + public assertOperationTypesChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.OperationTypes, + exist + ); + return this; + } + + public assertResourcePathChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.ResourcePath, + exist + ); + return this; + } + + public assertResourcePathChipGroupItemExist( + itemName: string, + exist: boolean + ) { + super.assertChipGroupItemExist( + AdminEventsTabSearchFormFieldsLabel.ResourcePath, + itemName, + exist + ); + return this; + } + + public assertRealmChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.Realm, + exist + ); + return this; + } + + public assertClientChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.Client, + exist + ); + return this; + } + + public assertUserChipGroupExist(exist: boolean) { + super.assertChipGroupExist(AdminEventsTabSearchFormFieldsLabel.User, exist); + return this; + } + + public assertIpAddressChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.IpAddress, + exist + ); + return this; + } + + public assertDateFromChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.DateFrom, + exist + ); + return this; + } + + public assertDateToChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + AdminEventsTabSearchFormFieldsLabel.DateTo, + exist + ); + return this; + } + + public assertAuthDialogIsNotEmpty() { + modalUtils + .checkModalTitle("Auth") + .assertModalMessageContainText("Realm") + .assertModalMessageContainText("Client") + .assertModalMessageContainText("User") + .assertModalMessageContainText("IP address") + .assertModalHasElement(this.authAttrDataRow, true) + .assertModalHasElement(this.authValDataRow, true) + .closeModal(); + return this; + } + + public assertRepresentationDialogIsNotEmpty() { + modalUtils.checkModalTitle("Representation").closeModal(); + return this; + } + + public assertNoSearchResultsExist(exist: boolean) { + emptyStatePage.checkIfExists(exist); + return this; + } +} diff --git a/cypress/support/pages/admin_console/manage/events/tabs/UserEventsTab.ts b/cypress/support/pages/admin_console/manage/events/tabs/UserEventsTab.ts new file mode 100644 index 0000000000..935913955b --- /dev/null +++ b/cypress/support/pages/admin_console/manage/events/tabs/UserEventsTab.ts @@ -0,0 +1,204 @@ +import EmptyStatePage from "../../../components/EmptyStatePage"; +import PageObject from "../../../components/PageObject"; + +enum UserEventsTabSearchFormFieldsLabel { + UserId = "User ID", + EventType = "Event type", + Client = "Client", + DateFrom = "Date(from)", + DateTo = "Date(to)", +} + +export class UserEventSearchData { + userId?: string; + eventType?: string[]; + client?: string; + dateFrom?: string; + dateTo?: string; +} + +const emptyStatePage = new EmptyStatePage(); + +export default class UserEventsTab extends PageObject { + private searchUserEventDrpDwnToggle = "userEventsSearchSelectorToggle"; + private searchUserIdInput = "#kc-userId"; + private searchEventTypeSelectToggle = + ".pf-c-select.keycloak__events_search__type_select"; + private searchClientInput = "#kc-client"; + private searchDateFromInput = "#kc-dateFrom"; + private searchDateToInput = "#kc-dateTo"; + private searchEventsBtn = "search-events-btn"; + private refreshBtn = "refresh-btn"; + + public openSearchUserEventDropdownMenu() { + super.openDropdownMenu( + "", + cy.findByTestId(this.searchUserEventDrpDwnToggle) + ); + return this; + } + + public openEventTypeSelectMenu() { + super.openSelectMenu("", cy.get(this.searchEventTypeSelectToggle)); + return this; + } + + public closeEventTypeSelectMenu() { + super.closeSelectMenu("", cy.get(this.searchEventTypeSelectToggle)); + return this; + } + + public clickEventTypeSelectItem(itemName: string) { + super.clickSelectMenuItem(itemName); + return this; + } + + public assertSearchEventBtnIsEnabled(enabled: boolean) { + super.assertIsEnabled(cy.findByTestId(this.searchEventsBtn), enabled); + return this; + } + + public assertUserSearchDropdownMenuHasLabels() { + super.assertDropdownMenuHasLabels( + Object.values(UserEventsTabSearchFormFieldsLabel) + ); + return this; + } + + public assertSearchUserEventDropdownMenuExist(exist: boolean) { + super.assertExist(cy.findByTestId(this.searchUserEventDrpDwnToggle), exist); + return this; + } + + public refresh() { + cy.findByTestId(this.refreshBtn).click(); + return this; + } + + public typeUserId(userId: string) { + cy.get(this.searchUserIdInput).type(userId); + return this; + } + + public searchUserEvent(searchData: UserEventSearchData) { + this.openSearchUserEventDropdownMenu(); + if (searchData.userId) { + this.typeUserId(searchData.userId); + } + if (searchData.eventType) { + this.openEventTypeSelectMenu(); + searchData.eventType.forEach((value) => { + super.clickSelectMenuItem(value); + }); + this.closeEventTypeSelectMenu(); + } + if (searchData.client) { + cy.get(this.searchClientInput).type(searchData.client); + } + if (searchData.dateFrom) { + cy.get(this.searchDateFromInput).type(searchData.dateFrom); + } + if (searchData.dateTo) { + cy.get(this.searchDateToInput).type(searchData.dateTo); + } + cy.findByTestId(this.searchEventsBtn).click(); + return this; + } + + public searchUserEventByUserId(userId: string) { + const searchData = new UserEventSearchData(); + searchData.userId = userId; + this.searchUserEvent(searchData); + return this; + } + + public searchUserEventByEventType(eventType: string[]) { + const searchData = new UserEventSearchData(); + searchData.eventType = eventType; + this.searchUserEvent(searchData); + return this; + } + + public searchUserEventByClient(client: string) { + const searchData = new UserEventSearchData(); + searchData.client = client; + this.searchUserEvent(searchData); + return this; + } + + public searchUserEventByDateFrom(dateFrom: string) { + const searchData = new UserEventSearchData(); + searchData.dateFrom = dateFrom; + this.searchUserEvent(searchData); + return this; + } + + public searchUserEventByDateTo(dateTo: string) { + const searchData = new UserEventSearchData(); + searchData.dateTo = dateTo; + this.searchUserEvent(searchData); + return this; + } + + public removeEventTypeChipGroupItem(itemName: string) { + super.removeChipGroupItem( + UserEventsTabSearchFormFieldsLabel.EventType, + itemName + ); + return this; + } + + public assertEventTypeChipGroupItemExist(itemName: string, exist: boolean) { + super.assertChipGroupItemExist( + UserEventsTabSearchFormFieldsLabel.EventType, + itemName, + exist + ); + return this; + } + + public assertUserIdChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + UserEventsTabSearchFormFieldsLabel.UserId, + exist + ); + return this; + } + + public assertEventTypeChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + UserEventsTabSearchFormFieldsLabel.EventType, + exist + ); + return this; + } + + public assertClientChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + UserEventsTabSearchFormFieldsLabel.Client, + exist + ); + return this; + } + + public assertDateFromChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + UserEventsTabSearchFormFieldsLabel.DateFrom, + exist + ); + return this; + } + + public assertDateToChipGroupExist(exist: boolean) { + super.assertChipGroupExist( + UserEventsTabSearchFormFieldsLabel.DateTo, + exist + ); + return this; + } + + public assertNoSearchResultsExist(exist: boolean) { + emptyStatePage.checkIfExists(exist); + return this; + } +} 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 123502e7b4..e74e05ed9d 100644 --- a/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts +++ b/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts @@ -1,8 +1,13 @@ -import ModalUtils from "../../../../util/ModalUtils"; +import CommonPage from "../../../CommonPage"; import ListingPage from "../../ListingPage"; +import RealmSettingsEventsTab from "./tabs/RealmSettingsEventsTab"; + +enum RealmSettingsTab { + Events = "Events", +} const expect = chai.expect; -export default class RealmSettingsPage { +export default class RealmSettingsPage extends CommonPage { generalSaveBtn = "general-tab-save"; generalRevertBtn = "general-tab-revert"; themesSaveBtn = "themes-tab-save"; @@ -200,7 +205,6 @@ export default class RealmSettingsPage { private executorAvailablePeriodInput = "#available-period"; private listingPage = new ListingPage(); - private modalUtils = new ModalUtils(); private addCondition = "addCondition"; private addConditionDrpDwn = ".pf-c-select__toggle"; private addConditionDrpDwnOption = "conditionType-select"; @@ -225,12 +229,19 @@ export default class RealmSettingsPage { private realmDisplayName = "#kc-display-name"; private frontEndURL = "#kc-frontend-url"; private requireSSL = "#kc-require-ssl"; + private realmSettingsEventsTab = new RealmSettingsEventsTab(); private realmName?: string; constructor(realmName?: string) { + super(); this.realmName = realmName; } + goToEventsTab() { + this.tabUtils().clickTab(RealmSettingsTab.Events); + return this.realmSettingsEventsTab; + } + disableRealm() { cy.get(this.modalDialogTitle).contains("Disable realm?"); cy.get(this.modalDialogBodyText).contains( @@ -346,7 +357,7 @@ export default class RealmSettingsPage { deleteProvider(name: string) { this.listingPage.deleteItem(name); - this.modalUtils.checkModalTitle("Delete key provider?").confirmModal(); + this.modalUtils().checkModalTitle("Delete key provider?").confirmModal(); cy.get(this.alertMessage).should( "be.visible", diff --git a/cypress/support/pages/admin_console/manage/realm_settings/tabs/RealmSettingsEventsTab.ts b/cypress/support/pages/admin_console/manage/realm_settings/tabs/RealmSettingsEventsTab.ts new file mode 100644 index 0000000000..ffba87ed2a --- /dev/null +++ b/cypress/support/pages/admin_console/manage/realm_settings/tabs/RealmSettingsEventsTab.ts @@ -0,0 +1,31 @@ +import CommonPage from "../../../../CommonPage"; +import AdminEventsSettingsTab from "./realmsettings_events_subtabs/AdminEventsSettingsTab"; +import EventListenersTab from "./realmsettings_events_subtabs/EventListenersTab"; +import UserEventsSettingsTab from "./realmsettings_events_subtabs/UserEventsSettingsTab"; + +enum RealmSettingsEventsSubTab { + EventListeners = "Event listeners", + UserEventsSettings = "User events settings", + AdminEventsSettings = "Admin events settings", +} + +export default class RealmSettingsEventsTab extends CommonPage { + private eventListenersTab = new EventListenersTab(); + private userEventsSettingsTab = new UserEventsSettingsTab(); + private adminEventsSettingsTab = new AdminEventsSettingsTab(); + + goToEventListenersSubTab() { + this.tabUtils().clickTab(RealmSettingsEventsSubTab.EventListeners, 1); + return this.eventListenersTab; + } + + goToUserEventsSettingsSubTab() { + this.tabUtils().clickTab(RealmSettingsEventsSubTab.UserEventsSettings, 1); + return this.userEventsSettingsTab; + } + + goToAdminEventsSettingsSubTab() { + this.tabUtils().clickTab(RealmSettingsEventsSubTab.AdminEventsSettings, 1); + return this.adminEventsSettingsTab; + } +} diff --git a/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/AdminEventsSettingsTab.ts b/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/AdminEventsSettingsTab.ts new file mode 100644 index 0000000000..e1173b2b3d --- /dev/null +++ b/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/AdminEventsSettingsTab.ts @@ -0,0 +1,41 @@ +import ModalUtils from "../../../../../../util/ModalUtils"; +import PageObject from "../../../../components/PageObject"; +import Masthead from "../../../../Masthead"; + +const masthead = new Masthead(); +const modal = new ModalUtils(); + +export default class AdminEventsSettingsTab extends PageObject { + private saveEventsSwitch = "#adminEventsEnabled-switch"; + private clearAdminEventsBtn = "#clear-admin-events"; + private saveBtn = "#save-admin"; + + clearAdminEvents() { + cy.get(this.clearAdminEventsBtn).click(); + modal.checkModalTitle("Clear events"); + modal.confirmModal(); + masthead.checkNotificationMessage("The admin events have been cleared"); + return this; + } + + disableSaveEvents() { + super.assertSwitchStateOn(cy.get(this.saveEventsSwitch)); + cy.get(this.saveEventsSwitch).parent().click(); + modal.checkModalTitle("Unsave events?"); + modal.confirmModal(); + super.assertSwitchStateOff(cy.get(this.saveEventsSwitch)); + return this; + } + + enableSaveEvents() { + super.assertSwitchStateOff(cy.get(this.saveEventsSwitch)); + cy.get(this.saveEventsSwitch).parent().click(); + super.assertSwitchStateOn(cy.get(this.saveEventsSwitch)); + return this; + } + + save() { + cy.get(this.saveBtn).click(); + return this; + } +} diff --git a/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/EventListenersTab.ts b/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/EventListenersTab.ts new file mode 100644 index 0000000000..7ab854fb0a --- /dev/null +++ b/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/EventListenersTab.ts @@ -0,0 +1,3 @@ +import PageObject from "../../../../components/PageObject"; + +export default class EventListenersTab extends PageObject {} diff --git a/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/UserEventsSettingsTab.ts b/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/UserEventsSettingsTab.ts new file mode 100644 index 0000000000..96fb788521 --- /dev/null +++ b/cypress/support/pages/admin_console/manage/realm_settings/tabs/realmsettings_events_subtabs/UserEventsSettingsTab.ts @@ -0,0 +1,40 @@ +import ModalUtils from "../../../../../../util/ModalUtils"; +import PageObject from "../../../../components/PageObject"; +import Masthead from "../../../../Masthead"; + +const masthead = new Masthead(); +const modal = new ModalUtils(); + +export default class UserEventsSettingsTab extends PageObject { + private saveEventsSwitch = "#eventsEnabled-switch"; + private clearUserEventsBtn = "#clear-user-events"; + private saveBtn = "#save-user"; + + clearUserEvents() { + cy.get(this.clearUserEventsBtn).click(); + modal.checkModalTitle("Clear events"); + modal.confirmModal(); + masthead.checkNotificationMessage("The user events have been cleared"); + return this; + } + + disableSaveEventsSwitch() { + cy.get(this.saveEventsSwitch).parent().click(); + super.assertSwitchStateOn(cy.get(this.saveEventsSwitch)); + modal.checkModalTitle("Unsave events?"); + modal.confirmModal(); + super.assertSwitchStateOff(cy.get(this.saveEventsSwitch)); + return this; + } + + enableSaveEventsSwitch() { + cy.get(this.saveEventsSwitch).parent().click(); + super.assertSwitchStateOn(cy.get(this.saveEventsSwitch)); + return this; + } + + save() { + cy.get(this.saveBtn).click(); + return this; + } +} diff --git a/cypress/support/util/AdminClient.ts b/cypress/support/util/AdminClient.ts index 7d3c8eb8e4..b56cb49794 100644 --- a/cypress/support/util/AdminClient.ts +++ b/cypress/support/util/AdminClient.ts @@ -22,6 +22,15 @@ class AdminClient { }); } + async loginUser(username: string, password: string, clientId: string) { + return this.client.auth({ + username: username, + password: password, + grantType: "password", + clientId: clientId, + }); + } + async createRealm(realm: string, payload?: RealmRepresentation) { await this.login(); await this.client.realms.create({ realm, ...payload }); diff --git a/cypress/support/util/ModalUtils.ts b/cypress/support/util/ModalUtils.ts index f24ac85bf2..c52a4abff5 100644 --- a/cypress/support/util/ModalUtils.ts +++ b/cypress/support/util/ModalUtils.ts @@ -79,4 +79,16 @@ export default class ModalUtils extends CommonElements { return this; } + + assertModalMessageContainText(text: string) { + cy.get(this.modalMessage).should("contain.text", text); + return this; + } + + assertModalHasElement(elementSelector: string, exist: boolean) { + cy.get(this.parentSelector) + .find(elementSelector) + .should((exist ? "" : ".not") + "exist"); + return this; + } }