Adds Realm Settings tests for general tab (#2336)

This commit is contained in:
Jenny 2022-04-05 15:34:21 -04:00 committed by GitHub
parent ef9d0ca822
commit bb226b52ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 224 additions and 25 deletions

View file

@ -0,0 +1,169 @@
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
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 adminClient from "../support/util/AdminClient";
const loginPage = new LoginPage();
const sidebarPage = new SidebarPage();
const masthead = new Masthead();
const realmSettingsPage = new RealmSettingsPage();
describe("Realm settings general tab tests", () => {
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
beforeEach(() => {
keycloakBefore();
loginPage.logIn();
sidebarPage.goToRealm(realmName);
});
before(async () => {
await adminClient.createRealm(realmName);
});
after(async () => {
await adminClient.deleteRealm(realmName);
});
it("Test all general tab switches", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch);
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch);
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
// Enable realm
realmSettingsPage.toggleSwitch(`${realmName}-switch`);
masthead.checkNotificationMessage("Realm successfully updated", true);
// Disable realm
realmSettingsPage.toggleSwitch(`${realmName}-switch`);
realmSettingsPage.disableRealm();
masthead.checkNotificationMessage("Realm successfully updated", true);
// Re-enable realm
realmSettingsPage.toggleSwitch(`${realmName}-switch`);
masthead.checkNotificationMessage("Realm successfully updated");
});
it("Modify Display name", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.fillDisplayName("display_name");
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
});
it("Check Display name value", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.getDisplayName("display_name");
});
it("Modify front end URL", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.fillFrontendURL("www.example.com");
// TODO: Fix internal server error 500 when front-end URL is saved
// realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
// masthead.checkNotificationMessage("Realm successfully updated", true);
realmSettingsPage.getFrontendURL("www.example.com");
realmSettingsPage.clearFrontendURL();
});
it("Select SSL all requests", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.fillRequireSSL("All requests");
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
});
it("Verify SSL all requests displays", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.getRequireSSL("All requests");
});
it("Select SSL external requests", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.fillRequireSSL("External requests");
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
});
it("Verify SSL external requests displays", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.getRequireSSL("External requests");
});
it("Select SSL None", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.fillRequireSSL("None");
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
});
it("Verify SSL None displays", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.getRequireSSL("None");
});
it("Check Access Endpoints OpenID Endpoint Configuration link", () => {
sidebarPage.goToRealmSettings();
// Check link exists
cy.get("a")
.contains("OpenID Endpoint Configuration")
.should(
"have.attr",
"href",
`http://localhost:8080/realms/${realmName}/.well-known/openid-configuration`
)
.should("have.attr", "target", "_blank")
.should("have.attr", "rel", "noreferrer noopener");
});
it("Access Endpoints OpenID Endpoint Configuration link", () => {
sidebarPage.goToRealmSettings();
// Check the link is live
cy.get("a")
.contains("OpenID Endpoint Configuration")
.then((link) => {
cy.request(link.prop("href")).its("status").should("eq", 200);
});
});
it("Check if Access Endpoints SAML 2.0 Identity Provider Metadata link exists", () => {
sidebarPage.goToRealmSettings();
cy.get("a")
.contains("SAML 2.0 Identity Provider Metadata")
.should(
"have.attr",
"href",
`http://localhost:8080/realms/${realmName}/protocol/saml/descriptor`
)
.should("have.attr", "target", "_blank")
.should("have.attr", "rel", "noreferrer noopener");
});
it("Access Endpoints SAML 2.0 Identity Provider Metadata link", () => {
sidebarPage.goToRealmSettings();
// Check the link is live
cy.get("a")
.contains("SAML 2.0 Identity Provider Metadata ")
.then((link) => {
cy.request(link.prop("href")).its("status").should("eq", 200);
});
});
it("Verify 'Revert' button works", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.fillDisplayName("should_be_reverted");
realmSettingsPage.revert(realmSettingsPage.generalRevertBtn);
realmSettingsPage.getDisplayName("display_name");
});
});

View file

@ -27,29 +27,6 @@ describe("Realm settings tabs tests", () => {
await adminClient.deleteRealm(realmName);
});
it("Go to general tab", () => {
sidebarPage.goToRealmSettings();
realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch);
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
realmSettingsPage.toggleSwitch(realmSettingsPage.managedAccessSwitch);
realmSettingsPage.save(realmSettingsPage.generalSaveBtn);
masthead.checkNotificationMessage("Realm successfully updated", true);
// Enable realm
realmSettingsPage.toggleSwitch(`${realmName}-switch`);
masthead.checkNotificationMessage("Realm successfully updated", true);
// Disable realm
realmSettingsPage.toggleSwitch(`${realmName}-switch`);
realmSettingsPage.disableRealm();
masthead.checkNotificationMessage("Realm successfully updated", true);
// Re-enable realm
realmSettingsPage.toggleSwitch(`${realmName}-switch`);
masthead.checkNotificationMessage("Realm successfully updated");
});
it("shows the 'user profile' tab if enabled", () => {
sidebarPage.goToRealmSettings();
cy.findByTestId(realmSettingsPage.userProfileTab).should("not.exist");

View file

@ -3,6 +3,7 @@ import ListingPage from "../../ListingPage";
const expect = chai.expect;
export default class RealmSettingsPage {
generalSaveBtn = "general-tab-save";
generalRevertBtn = "general-tab-revert";
themesSaveBtn = "themes-tab-save";
loginTab = "rs-login-tab";
userProfileTab = "rs-user-profile-tab";
@ -220,6 +221,10 @@ export default class RealmSettingsPage {
private selectScopeButton = "addValue";
private deleteClientRolesConditionBtn = "delete-client-roles-condition";
private deleteClientScopesConditionBtn = "delete-client-scopes-condition";
private realmDisplayName = "#kc-display-name";
private displayNameHTML = "#kc-html-display-name";
private frontEndURL = "#kc-frontend-url";
private requireSSL = "#kc-require-ssl";
private realmName?: string;
constructor(realmName?: string) {
@ -268,6 +273,42 @@ export default class RealmSettingsPage {
return this;
}
getDisplayName(name: string) {
cy.get(this.realmDisplayName).should("have.value", name);
return this;
}
getFrontendURL(url: string) {
cy.get(this.frontEndURL).should("have.value", url);
return this;
}
getRequireSSL(option: string) {
cy.get(this.requireSSL).contains(option);
return this;
}
fillDisplayName(displayName: string) {
cy.get(this.realmDisplayName).clear().type(displayName);
}
fillFrontendURL(url: string) {
cy.get(this.frontEndURL).clear().type(url);
}
clearFrontendURL() {
cy.get(this.frontEndURL).clear();
}
fillRequireSSL(option: string) {
cy.get(this.requireSSL)
.click()
.get(".pf-c-select__menu-item")
.contains(option)
.click();
}
setDefaultLocale(locale: string) {
cy.get(this.selectDefaultLocale).click();
cy.get(this.defaultLocaleList).contains(locale).click();
@ -350,6 +391,12 @@ export default class RealmSettingsPage {
return this;
}
revert(revertBtn: string) {
cy.findByTestId(revertBtn).click();
return this;
}
clearEvents(type: "admin" | "user") {
cy.findByTestId(`clear-${type}-events`).click();

View file

@ -64,7 +64,9 @@ export const RealmSettingsGeneralTab = ({
control={control}
defaultValue=""
render={({ onChange, value }) => (
<ClipboardCopy onChange={onChange}>{value}</ClipboardCopy>
<ClipboardCopy data-testid="realmName" onChange={onChange}>
{value}
</ClipboardCopy>
)}
/>
</FormGroup>
@ -232,7 +234,11 @@ export const RealmSettingsGeneralTab = ({
>
{t("common:save")}
</Button>
<Button variant="link" onClick={reset}>
<Button
data-testid="general-tab-revert"
variant="link"
onClick={reset}
>
{t("common:revert")}
</Button>
</ActionGroup>