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/6] 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/6] 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); + }); + }); + }); }); From e85098a421cf4d1c24179d1bed0e470544b111cc Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:55:59 +0530 Subject: [PATCH 3/6] Update LoginPage.ts --- cypress/pageobject/Login/LoginPage.ts | 51 ++++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/cypress/pageobject/Login/LoginPage.ts b/cypress/pageobject/Login/LoginPage.ts index 604184749d3..5b125f6dee4 100644 --- a/cypress/pageobject/Login/LoginPage.ts +++ b/cypress/pageobject/Login/LoginPage.ts @@ -3,6 +3,10 @@ import { users } from "../utils/userConfig"; interface LanguageMapping { [key: string]: { login: string; + }; +} +interface SidebarMapping { + [key: string]: { care: string; goal: string; footer_body: string; @@ -11,7 +15,15 @@ interface LanguageMapping { class LoginPage { languageSelector = "#language-selector"; - submitButtonSelector: string = "#login-button"; + 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) { @@ -99,17 +111,28 @@ class LoginPage { verifyForgotPasswordHeading(text: string[]): void { cy.verifyContentPresence("#forgot-password-heading", text); } - clickContributeOnGitHub(): void { - cy.get('a[href="https://github.com/ohcnetwork"]').scrollIntoView().click(); + + clickContributeOnGitHub(): void { + cy.get(this.contributeOnGitHubLink).scrollIntoView().click(); } clickThirdPartyLicense(): void { - cy.get('a[href="/licenses"]').scrollIntoView().click(); + cy.get(this.thirdPartyLicenseLink).scrollIntoView().click(); } - selectLanguage(languageCode: string): void { + + switchLanguage(languageCode: string): void { cy.get(this.languageSelector).select(languageCode); } - switchLanguageAndVerifyButtonText(languageMappings: LanguageMapping): void { + + 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}"]`) @@ -118,7 +141,7 @@ class LoginPage { if ($option.length === 0) { throw new Error(`Language option ${languageCode} not found`); } - this.selectLanguage(languageCode); + this.switchLanguage(languageCode); cy.get(this.submitButtonSelector, { timeout: 10000 }) .should("be.visible") .should("have.text", texts.login) @@ -126,13 +149,15 @@ class LoginPage { }); }); } - private verifySidebarElement(selector: string, expectedText: string): void { + + 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 { + + switchLanguageAndVerifySidebars(languageMappings: SidebarMapping): void { Object.entries(languageMappings).forEach(([languageCode, texts]) => { cy.get(this.languageSelector) .find(`option[value="${languageCode}"]`) @@ -141,10 +166,10 @@ class LoginPage { 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); + 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); }); }); } From d1156e727ab3009842814abf5d86c454019ad42a Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:56:05 +0530 Subject: [PATCH 4/6] Update redirect.cy.ts --- cypress/e2e/homepage_spec/redirect.cy.ts | 44 ++++++++++-------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/cypress/e2e/homepage_spec/redirect.cy.ts b/cypress/e2e/homepage_spec/redirect.cy.ts index 71d24288bfe..5e2f3733af8 100644 --- a/cypress/e2e/homepage_spec/redirect.cy.ts +++ b/cypress/e2e/homepage_spec/redirect.cy.ts @@ -1,15 +1,17 @@ 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"; +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, locale["login"]]) + const languageMappings = Object.fromEntries( + Object.entries(locales).map(([langCode, locale]) => [langCode, { + login: locale["login"] + }]) ); const languageSidebars = Object.fromEntries( @@ -18,11 +20,12 @@ describe("redirect", () => { { care: locale["care"], goal: locale["goal"], footer_body: locale["footer_body"] }, ]) ); + const loginPage = new LoginPage(); beforeEach(() => { cy.awaitUrl("/", true); - loginPage.ensurePageLoaded(); + loginPage.ensureLoggedIn(); cy.log("Logging in the user devdistrictadmin"); }); @@ -56,7 +59,7 @@ describe("redirect", () => { .and("contain", "Contribute on GitHub"); }); - it("Verify redirection of 'Third Party Software License'", () => { + it("Verify redirection of 'Third Party Software License'", () => { loginPage.clickThirdPartyLicense(); cy.url({ timeout: 10000 }).should("include", "/licenses"); cy.get("body", { timeout: 10000 }) @@ -64,22 +67,11 @@ describe("redirect", () => { .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 login button text", () => { + loginPage.switchLanguageAndVerifyButtonText(languageMappings); + }); - 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); - }); - }); - }); + it("Switch languages and verify sidebar items", () => { + loginPage.switchLanguageAndVerifySidebars(languageSidebars); + }); }); From de3637c02a8b1a213eb496a3120229ac73241f20 Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 24 Dec 2024 01:17:57 +0530 Subject: [PATCH 5/6] Update redirect.cy.ts --- cypress/e2e/homepage_spec/redirect.cy.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/cypress/e2e/homepage_spec/redirect.cy.ts b/cypress/e2e/homepage_spec/redirect.cy.ts index 5e2f3733af8..79996fb4c83 100644 --- a/cypress/e2e/homepage_spec/redirect.cy.ts +++ b/cypress/e2e/homepage_spec/redirect.cy.ts @@ -25,7 +25,6 @@ describe("redirect", () => { beforeEach(() => { cy.awaitUrl("/", true); - loginPage.ensureLoggedIn(); cy.log("Logging in the user devdistrictadmin"); }); From fef707d898c313da5d929b9644168f5d6bec440a Mon Sep 17 00:00:00 2001 From: Kaushikgtm <162317291+Kaushikgtm@users.noreply.github.com> Date: Tue, 24 Dec 2024 01:18:05 +0530 Subject: [PATCH 6/6] Update LoginPage.ts