From 9748397661ec056ff9660e757db242dd66a965bf Mon Sep 17 00:00:00 2001 From: Dominik Kawka <31955648+dominikkawka@users.noreply.github.com> Date: Mon, 17 Oct 2022 11:08:49 +0100 Subject: [PATCH] Tests for realm setting tabs (#3564) --- .../e2e/realm_settings_events_test.spec.ts | 8 +++++ .../e2e/realm_settings_tabs_test.spec.ts | 17 ++++++++++ .../realm_settings/RealmSettingsPage.ts | 33 +++++++++++++++++-- apps/admin-ui/src/realm-settings/EmailTab.tsx | 6 +++- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts index 017f84196f..e4125b0609 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_events_test.spec.ts @@ -233,6 +233,12 @@ describe("Realm settings events tab tests", () => { realmSettingsPage.deleteProvider("test_aes-generated"); }); + it("list keys", () => { + sidebarPage.goToRealmSettings(); + cy.findByTestId("rs-keys-tab").click(); + realmSettingsPage.checkKeyPublic(); + }); + it("add locale", () => { sidebarPage.goToRealmSettings(); @@ -258,6 +264,8 @@ describe("Realm settings events tab tests", () => { masthead.checkNotificationMessage( "Success! The message bundle has been added." ); + realmSettingsPage.setDefaultLocale("dansk"); + cy.findByTestId("localization-tab-save").click(); }); it("Realm header settings", () => { diff --git a/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts b/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts index 1387b74105..ad377c3616 100644 --- a/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts +++ b/apps/admin-ui/cypress/e2e/realm_settings_tabs_test.spec.ts @@ -81,6 +81,21 @@ describe("Realm settings tabs tests", () => { const msg: string = "Error! Failed to send email."; sidebarPage.goToRealmSettings(); cy.findByTestId("rs-email-tab").click(); + //required fields not filled in or not filled properly + realmSettingsPage.addSenderEmail("not a valid email"); + realmSettingsPage.fillFromDisplayName("displayName"); + realmSettingsPage.fillReplyToEmail("replyTo@email.com"); + realmSettingsPage.fillPort("10"); + cy.findByTestId("email-tab-save").click(); + cy.get("#kc-display-name-helper").contains("You must enter a valid email."); + cy.get("#kc-host-helper").contains("Required field"); + //revert + cy.wait(100); + cy.findByTestId("email-tab-revert").click(); + cy.findByTestId("sender-email-address").should("be.empty"); + cy.findByTestId("from-display-name").should("be.empty"); + cy.get("#kc-port").should("be.empty"); + realmSettingsPage.addSenderEmail("example@example.com"); realmSettingsPage.toggleCheck(realmSettingsPage.enableSslCheck); realmSettingsPage.toggleCheck(realmSettingsPage.enableStartTlsCheck); @@ -89,10 +104,12 @@ describe("Realm settings tabs tests", () => { cy.findByTestId(realmSettingsPage.testConnectionButton).click(); cy.wait("@load"); + //ln109-113 cause the tests to fail locally, but is needed for the test to pass on the dashboard. realmSettingsPage.fillEmailField( "example" + (Math.random() + 1).toString(36).substring(7) + "@example.com" ); cy.findByTestId(realmSettingsPage.modalTestConnectionButton).click(); + masthead.checkNotificationMessage(msg, true); }); diff --git a/apps/admin-ui/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts b/apps/admin-ui/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts index 7542dd3b70..17bcbbda22 100644 --- a/apps/admin-ui/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts +++ b/apps/admin-ui/cypress/support/pages/admin_console/manage/realm_settings/RealmSettingsPage.ts @@ -54,8 +54,8 @@ export default class RealmSettingsPage extends CommonPage { loginActionTimeoutSelectMenuList = "#kc-login-action-timeout-select-menu > div > ul"; - selectDefaultLocale = "select-default-locale"; - defaultLocaleList = "select-default-locale > div > ul"; + selectDefaultLocale = "#kc-default-locale"; + defaultLocaleList = "select-default-locale"; supportedLocalesTypeahead = "#kc-l-supported-locales-select-multi-typeahead-typeahead"; supportedLocalesToggle = "#kc-l-supported-locales"; @@ -229,6 +229,13 @@ export default class RealmSettingsPage extends CommonPage { private realmDisplayName = "#kc-display-name"; private frontEndURL = "#kc-frontend-url"; private requireSSL = "#kc-require-ssl"; + private fromDisplayName = "from-display-name"; + private replyToEmail = "#kc-reply-to"; + private port = "#kc-port"; + + private keysList = ".kc-keys-list > tbody > tr > td"; + private publicKeyBtn = + ".kc-keys-list > tbody > tr > td > .button-wrapper > button"; private realmSettingsEventsTab = new RealmSettingsEventsTab(); private realmName?: string; @@ -304,6 +311,18 @@ export default class RealmSettingsPage extends CommonPage { cy.get(this.realmDisplayName).clear().type(displayName); } + fillFromDisplayName(displayName: string) { + cy.findByTestId(this.fromDisplayName).clear().type(displayName); + } + + fillReplyToEmail(email: string) { + cy.get(this.replyToEmail).clear().type(email); + } + + fillPort(port: string) { + cy.get(this.port).clear().type(port); + } + fillFrontendURL(url: string) { cy.get(this.frontEndURL).clear().type(url); } @@ -322,7 +341,7 @@ export default class RealmSettingsPage extends CommonPage { setDefaultLocale(locale: string) { cy.get(this.selectDefaultLocale).click(); - cy.get(this.defaultLocaleList).contains(locale).click(); + cy.findByTestId(this.defaultLocaleList).contains(locale).click(); return this; } @@ -366,6 +385,14 @@ export default class RealmSettingsPage extends CommonPage { return this; } + checkKeyPublic() { + cy.get(this.publicKeyBtn).contains("Public key").click(); + this.modalUtils().checkModalTitle("Public key").confirmModal(); + + cy.get(this.publicKeyBtn).contains("Certificate").click(); + this.modalUtils().checkModalTitle("Certificate").confirmModal(); + } + switchToActiveFilter() { cy.get(this.filterSelectMenu).first().click(); cy.findByTestId(this.activeKeysOption).click(); diff --git a/apps/admin-ui/src/realm-settings/EmailTab.tsx b/apps/admin-ui/src/realm-settings/EmailTab.tsx index 9afbc50859..ba364aaacd 100644 --- a/apps/admin-ui/src/realm-settings/EmailTab.tsx +++ b/apps/admin-ui/src/realm-settings/EmailTab.tsx @@ -405,7 +405,11 @@ export const RealmSettingsEmailTab = ({ > {t("common:testConnection")} -