keycloak-scim/js/apps/admin-ui/cypress/e2e/masthead_test.spec.ts

141 lines
3.9 KiB
TypeScript
Raw Normal View History

import { v4 as uuid } from "uuid";
2021-01-27 12:56:28 +00:00
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import Masthead from "../support/pages/admin-ui/Masthead";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
const loginPage = new LoginPage();
const masthead = new Masthead();
const sidebarPage = new SidebarPage();
const helpLabel = ".pf-v5-c-form__group-label-help";
describe("Masthead tests", () => {
2022-02-15 16:02:17 +00:00
beforeEach(() => {
loginPage.logIn();
2023-02-10 10:10:35 +00:00
keycloakBefore();
});
describe("Desktop view", () => {
it("Go to account console and back to admin console", () => {
sidebarPage.waitForPageLoad();
masthead.accountManagement();
cy.url().should("contain", "/realms/master/account");
});
it("Sign out reachs to log in screen", () => {
sidebarPage.waitForPageLoad();
masthead.signOut();
sidebarPage.waitForPageLoad();
loginPage.isLogInPage();
});
it("Go to realm info", () => {
sidebarPage.goToClients();
masthead.toggleUsernameDropdown().clickRealmInfo();
cy.get(".pf-v5-l-grid").should("contain.text", "Welcome");
});
it("Should go to documentation page", () => {
masthead.clickGlobalHelp();
masthead
.getDocumentationLink()
.invoke("attr", "href")
.then((href) => {
if (!href) return;
masthead.clickDocumentationLink();
cy.origin(href, () => {
cy.get("#header").should(
"contain.text",
"Server Administration Guide",
);
});
});
});
it("Enable/disable help mode in desktop mode", () => {
masthead.assertIsDesktopView();
cy.findByTestId("infoTab").click();
cy.get(helpLabel).should("exist");
masthead.toggleGlobalHelp();
masthead.clickGlobalHelp();
cy.get(helpLabel).should("not.exist");
masthead.toggleGlobalHelp();
cy.get(helpLabel).should("exist");
});
});
describe("Login works for unprivileged users", () => {
const realmName = `test-realm-${uuid()}`;
const username = `test-user-${uuid()}`;
before(async () => {
await adminClient.createRealm(realmName, { enabled: true });
await adminClient.inRealm(realmName, () =>
adminClient.createUser({
username,
enabled: true,
emailVerified: true,
credentials: [{ type: "password", value: "test" }],
firstName: "Test",
lastName: "User",
email: "test@keycloak.org",
}),
);
});
after(() => adminClient.deleteRealm(realmName));
it("Login without privileges to see admin console", () => {
sidebarPage.waitForPageLoad();
masthead.signOut();
cy.visit(`/admin/${realmName}/console`);
cy.get('[role="progressbar"]').should("not.exist");
cy.get("#username").type(username);
cy.get("#password").type("test");
cy.get("#kc-login").click();
sidebarPage.waitForPageLoad();
masthead.signOut();
sidebarPage.waitForPageLoad();
loginPage.isLogInPage();
});
});
describe("Mobile view", () => {
it("Mobile menu is shown when in mobile view", () => {
cy.viewport("samsung-s10");
masthead.assertIsMobileView();
});
it("Enable/disable help mode in mobile view", () => {
cy.viewport("samsung-s10");
masthead
.assertIsMobileView()
.toggleUsernameDropdown()
.toggleMobileViewHelp();
masthead.toggleMobileViewHelp();
cy.findByTestId("helpIcon").should("exist");
});
});
describe("Accessibility tests for masthead", () => {
beforeEach(() => {
loginPage.logIn();
keycloakBefore();
sidebarPage.waitForPageLoad();
masthead.accountManagement();
cy.injectAxe();
});
it("Check a11y violations on load/ masthead", () => {
cy.checkA11y();
});
});
});