Masthead new tests & refactoring (#4439)

This commit is contained in:
ikhomyn 2023-02-21 14:41:33 +01:00 committed by GitHub
parent ce7e3ec9ea
commit fed9f2716d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 49 deletions

View file

@ -1,4 +1,3 @@
import ListingPage from "../support/pages/admin-ui/ListingPage";
import LoginPage from "../support/pages/LoginPage"; import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin-ui/SidebarPage"; import SidebarPage from "../support/pages/admin-ui/SidebarPage";
import Masthead from "../support/pages/admin-ui/Masthead"; import Masthead from "../support/pages/admin-ui/Masthead";
@ -6,61 +5,69 @@ import { keycloakBefore } from "../support/util/keycloak_hooks";
const loginPage = new LoginPage(); const loginPage = new LoginPage();
const masthead = new Masthead(); const masthead = new Masthead();
const listingPage = new ListingPage();
const sidebarPage = new SidebarPage(); const sidebarPage = new SidebarPage();
const helpLabel = ".pf-c-form__group-label-help";
const logOutTest = () => { describe("Masthead tests", () => {
beforeEach(() => {
loginPage.logIn();
keycloakBefore();
});
describe("Desktop view", () => {
it("Go to account console and back to admin console", () => {
sidebarPage.waitForPageLoad();
masthead.accountManagement();
cy.get("h1").contains("Welcome to Keycloak account management");
masthead.goToAdminConsole();
masthead.checkIsAdminUI();
});
it("Sign out reachs to log in screen", () => {
sidebarPage.waitForPageLoad(); sidebarPage.waitForPageLoad();
masthead.signOut(); masthead.signOut();
sidebarPage.waitForPageLoad(); sidebarPage.waitForPageLoad();
loginPage.isLogInPage(); loginPage.isLogInPage();
};
const goToAcctMgtTest = () => {
sidebarPage.waitForPageLoad();
masthead.accountManagement();
cy.get("h1").contains("Welcome to Keycloak account management");
cy.get("#landingReferrerLink").click({ force: true });
masthead.checkIsAdminUI();
};
describe("Masthead tests in desktop mode", () => {
beforeEach(() => {
loginPage.logIn();
keycloakBefore();
}); });
it("Test dropdown in desktop mode", () => { it("Go to realm info", () => {
goToAcctMgtTest(); sidebarPage.goToClients();
masthead.toggleUsernameDropdown().clickRealmInfo();
cy.get(".pf-c-card__title").should("contain.text", "Server info");
});
sidebarPage.goToClientScopes(); it("Should go to documentation page", () => {
listingPage.goToItemDetails("address"); masthead.clickGlobalHelp();
masthead.clickDocumentationLink();
cy.get("#view-header-subkey").should("exist"); cy.get("#header").should("contain.text", "Server Administration Guide");
cy.findByTestId("help-label-name").should("exist"); });
it("Enable/disable help mode in desktop mode", () => {
masthead.assertIsDesktopView();
cy.get(helpLabel).should("exist");
masthead.toggleGlobalHelp(); masthead.toggleGlobalHelp();
masthead.clickGlobalHelp();
cy.get("#view-header-subkey").should("not.exist"); cy.get(helpLabel).should("not.exist");
cy.findByTestId("help-label-name").should("not.exist"); masthead.toggleGlobalHelp();
cy.get(helpLabel).should("exist");
logOutTest();
}); });
}); });
describe("Masthead tests with kebab menu", () => { describe("Mobile view", () => {
beforeEach(() => { it("Mobile menu is shown when in mobile view", () => {
loginPage.logIn(); cy.viewport("samsung-s10");
keycloakBefore(); masthead.assertIsMobileView();
masthead.setMobileMode(true);
}); });
it("Test dropdown in mobile mode", () => { it("Enable/disable help mode in mobile view", () => {
masthead.checkKebabShown(); cy.viewport("samsung-s10");
goToAcctMgtTest(); masthead
logOutTest(); .assertIsMobileView()
.toggleUsernameDropdown()
.toggleMobileViewHelp();
cy.get(helpLabel).should("not.exist");
masthead.toggleMobileViewHelp();
cy.get(helpLabel).should("exist");
});
}); });
// TODO: Add test for help when using kebab menu.
// Feature not yet implemented for kebab.
}); });

View file

@ -10,6 +10,9 @@ export default class Masthead extends CommonElements {
private userDrpDwn = "#user-dropdown"; private userDrpDwn = "#user-dropdown";
private userDrpDwnKebab = "#user-dropdown-kebab"; private userDrpDwnKebab = "#user-dropdown-kebab";
private globalAlerts = "global-alerts"; private globalAlerts = "global-alerts";
private documentationLink = "#link";
private backToAdminConsoleLink = "#landingReferrerLink";
private userDrpdwnItem = ".pf-c-dropdown__menu-item";
private getAlertsContainer() { private getAlertsContainer() {
return cy.findByTestId(this.globalAlerts); return cy.findByTestId(this.globalAlerts);
@ -35,6 +38,39 @@ export default class Masthead extends CommonElements {
cy.get("#enableHelp").click({ force: true }); cy.get("#enableHelp").click({ force: true });
} }
toggleUsernameDropdown() {
this.userDropdown().click();
return this;
}
toggleMobileViewHelp() {
cy.get(this.userDrpdwnItem).contains("Help").click();
return this;
}
clickRealmInfo() {
cy.get(this.userDrpdwnItem).contains("Realm info").click();
return this;
}
clickGlobalHelp() {
cy.get(this.helpBtn).click();
return this;
}
clickDocumentationLink() {
cy.get(this.documentationLink)
.find("a")
.invoke("removeAttr", "target")
.click();
return this;
}
goToAdminConsole() {
cy.get(this.backToAdminConsoleLink).click({ force: true });
return this;
}
userDropdown() { userDropdown() {
return cy return cy
.document() .document()
@ -45,13 +81,13 @@ export default class Masthead extends CommonElements {
} }
signOut() { signOut() {
this.userDropdown().click(); this.toggleUsernameDropdown();
cy.get("#sign-out").click(); cy.get("#sign-out").click();
Cypress.session.clearAllSavedSessions(); Cypress.session.clearAllSavedSessions();
} }
accountManagement() { accountManagement() {
this.userDropdown().click(); this.toggleUsernameDropdown();
cy.get("#manage-account").click(); cy.get("#manage-account").click();
} }
@ -83,9 +119,16 @@ export default class Masthead extends CommonElements {
return this; return this;
} }
checkKebabShown() { assertIsDesktopView() {
cy.get(this.userDrpDwn).should("be.visible");
cy.get(this.userDrpDwnKebab).should("not.be.visible");
return this;
}
assertIsMobileView() {
cy.get(this.userDrpDwn).should("not.be.visible"); cy.get(this.userDrpDwn).should("not.be.visible");
cy.get(this.userDrpDwnKebab).should("exist"); cy.get(this.userDrpDwnKebab).should("be.visible");
return this; return this;
} }