From c8a8d80fa8092130d43df7f818bff7149ebda2f8 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:59:20 +0530 Subject: [PATCH 1/2] Update LoginPage.ts --- cypress/pageobject/Login/LoginPage.ts | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/cypress/pageobject/Login/LoginPage.ts b/cypress/pageobject/Login/LoginPage.ts index 64e9cd5f25e..604184749d3 100644 --- a/cypress/pageobject/Login/LoginPage.ts +++ b/cypress/pageobject/Login/LoginPage.ts @@ -1,6 +1,17 @@ import { users } from "../utils/userConfig"; +interface LanguageMapping { + [key: string]: { + login: string; + care: string; + goal: string; + footer_body: string; + }; +} + class LoginPage { + languageSelector = "#language-selector"; + submitButtonSelector: string = "#login-button"; loginByRole(role: keyof typeof users): void { const user = users[role]; if (!user) { @@ -88,6 +99,55 @@ class LoginPage { verifyForgotPasswordHeading(text: string[]): void { cy.verifyContentPresence("#forgot-password-heading", text); } + clickContributeOnGitHub(): void { + cy.get('a[href="https://github.com/ohcnetwork"]').scrollIntoView().click(); + } + + clickThirdPartyLicense(): void { + cy.get('a[href="/licenses"]').scrollIntoView().click(); + } + selectLanguage(languageCode: string): void { + cy.get(this.languageSelector).select(languageCode); + } + 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.selectLanguage(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: 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.selectLanguage(languageCode); + this.verifySidebarElement("#care", texts.care); + this.verifySidebarElement("#goal", texts.goal); + this.verifySidebarElement("#footer_body", texts.footer_body); + }); + }); + } } export default LoginPage; From d954b39a5ad0c3d9874e8608ff3f6e546840bb28 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:59:32 +0530 Subject: [PATCH 2/2] Update redirect.cy.ts --- cypress/e2e/homepage_spec/redirect.cy.ts | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/cypress/e2e/homepage_spec/redirect.cy.ts b/cypress/e2e/homepage_spec/redirect.cy.ts index 3822a67b194..71d24288bfe 100644 --- a/cypress/e2e/homepage_spec/redirect.cy.ts +++ b/cypress/e2e/homepage_spec/redirect.cy.ts @@ -1,9 +1,28 @@ import LoginPage from "../../pageobject/Login/LoginPage"; +import ta from "../../../src/Locale/ta.json"; +import ml from "../../../src/Locale/ml.json"; +import mr from "../../../src/Locale/mr.json"; +import kn from "../../../src/Locale/kn.json"; +import hi from "../../../src/Locale/hi.json"; + +const locales = { hi, ta, ml, mr, kn }; describe("redirect", () => { + const languageMappings = Object.fromEntries( + Object.entries(locales).map(([langCode, locale]) => [langCode, 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); + loginPage.ensurePageLoaded(); cy.log("Logging in the user devdistrictadmin"); }); @@ -28,4 +47,39 @@ 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", () => { + Object.entries(languageMappings).forEach(([lang, expected]) => { + cy.log(`Testing login button in language: ${lang}`); + loginPage.switchLanguage(lang); + loginPage.getSubmitButton().should("have.text", expected); + }); + + it("Switch languages and verify sidebar items", () => { + Object.entries(languageSidebars).forEach(([lang, expected]) => { + cy.log(`Testing sidebar in language: ${lang}`); + loginPage.switchLanguage(lang); + loginPage.getSidebarItems().should(($items) => { + expect($items).to.contain(expected.care); + expect($items).to.contain(expected.goal); + expect($items).to.contain(expected.footer_body); + }); + }); + }); });