diff --git a/cypress/e2e/homepage_spec/redirect.cy.ts b/cypress/e2e/homepage_spec/redirect.cy.ts index 3822a67b194..79996fb4c83 100644 --- a/cypress/e2e/homepage_spec/redirect.cy.ts +++ b/cypress/e2e/homepage_spec/redirect.cy.ts @@ -1,9 +1,30 @@ import LoginPage from "../../pageobject/Login/LoginPage"; +import * as ta from "../../../public/locale/ta.json"; +import * as ml from "../../../public/locale/ml.json"; +import * as mr from "../../../public/locale/mr.json"; +import * as kn from "../../../public/locale/kn.json"; +import * as hi from "../../../public/locale/hi.json"; + +const locales = { hi, ta, ml, mr, kn }; describe("redirect", () => { + const languageMappings = Object.fromEntries( + Object.entries(locales).map(([langCode, locale]) => [langCode, { + login: locale["login"] + }]) + ); + + const languageSidebars = Object.fromEntries( + Object.entries(locales).map(([langCode, locale]) => [ + langCode, + { care: locale["care"], goal: locale["goal"], footer_body: locale["footer_body"] }, + ]) + ); + const loginPage = new LoginPage(); beforeEach(() => { + cy.awaitUrl("/", true); cy.log("Logging in the user devdistrictadmin"); }); @@ -28,4 +49,28 @@ describe("redirect", () => { loginPage.ensureLoggedIn(); cy.url().should("include", "/facility"); }); + + it("Verify redirection of 'Contribute on GitHub' link", () => { + loginPage.clickContributeOnGitHub(); + cy.url({ timeout: 10000 }).should("include", "https://github.com/ohcnetwork"); + cy.get("body", { timeout: 10000 }) + .should("be.visible") + .and("contain", "Contribute on GitHub"); + }); + + it("Verify redirection of 'Third Party Software License'", () => { + loginPage.clickThirdPartyLicense(); + cy.url({ timeout: 10000 }).should("include", "/licenses"); + cy.get("body", { timeout: 10000 }) + .should("be.visible") + .and("contain", "Third Party Software License"); + }); + + it("Switch languages and verify login button text", () => { + loginPage.switchLanguageAndVerifyButtonText(languageMappings); + }); + + it("Switch languages and verify sidebar items", () => { + loginPage.switchLanguageAndVerifySidebars(languageSidebars); + }); }); diff --git a/cypress/pageobject/Login/LoginPage.ts b/cypress/pageobject/Login/LoginPage.ts index 64e9cd5f25e..5b125f6dee4 100644 --- a/cypress/pageobject/Login/LoginPage.ts +++ b/cypress/pageobject/Login/LoginPage.ts @@ -1,6 +1,29 @@ import { users } from "../utils/userConfig"; +interface LanguageMapping { + [key: string]: { + login: string; + }; +} +interface SidebarMapping { + [key: string]: { + care: string; + goal: string; + footer_body: string; + }; +} + class LoginPage { + languageSelector = "#language-selector"; + submitButtonSelector: string = "#login-button"; + sidebarSelectors = { + care: "#care", + goal: "#goal", + footer_body: "#footer_body", + }; + contributeOnGitHubLink = 'a[href="https://github.com/ohcnetwork"]'; + thirdPartyLicenseLink = 'a[href="/licenses"]'; + loginByRole(role: keyof typeof users): void { const user = users[role]; if (!user) { @@ -88,6 +111,68 @@ class LoginPage { verifyForgotPasswordHeading(text: string[]): void { cy.verifyContentPresence("#forgot-password-heading", text); } + + clickContributeOnGitHub(): void { + cy.get(this.contributeOnGitHubLink).scrollIntoView().click(); + } + + clickThirdPartyLicense(): void { + cy.get(this.thirdPartyLicenseLink).scrollIntoView().click(); + } + + switchLanguage(languageCode: string): void { + cy.get(this.languageSelector).select(languageCode); + } + + getSubmitButton() { + return cy.get(this.submitButtonSelector); + } + + getSidebarItems() { + return cy.get(`${this.sidebarSelectors.care}, ${this.sidebarSelectors.goal}, ${this.sidebarSelectors.footer_body}`); + } + + switchLanguageAndVerifyButtonText(languageMappings: LanguageMapping): void { + Object.entries(languageMappings).forEach(([languageCode, texts]) => { + cy.get(this.languageSelector) + .find(`option[value="${languageCode}"]`) + .should("exist") + .then(($option) => { + if ($option.length === 0) { + throw new Error(`Language option ${languageCode} not found`); + } + this.switchLanguage(languageCode); + cy.get(this.submitButtonSelector, { timeout: 10000 }) + .should("be.visible") + .should("have.text", texts.login) + .should("not.be.disabled"); + }); + }); + } + + private verifySidebarElement(selector: string, expectedText: string): void { + cy.get(selector, { timeout: 10000 }) + .should("be.visible") + .should("have.text", expectedText) + .should("not.be.disabled"); + } + + switchLanguageAndVerifySidebars(languageMappings: SidebarMapping): void { + Object.entries(languageMappings).forEach(([languageCode, texts]) => { + cy.get(this.languageSelector) + .find(`option[value="${languageCode}"]`) + .should("exist") + .then(($option) => { + if ($option.length === 0) { + throw new Error(`Language option ${languageCode} not found`); + } + this.switchLanguage(languageCode); + this.verifySidebarElement(this.sidebarSelectors.care, texts.care); + this.verifySidebarElement(this.sidebarSelectors.goal, texts.goal); + this.verifySidebarElement(this.sidebarSelectors.footer_body, texts.footer_body); + }); + }); + } } export default LoginPage;