Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress Test for language selection and link redirection #9488

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions cypress/e2e/homepage_spec/redirect.cy.ts
Original file line number Diff line number Diff line change
@@ -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");
});

Expand All @@ -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);
});
});
});
});
60 changes: 60 additions & 0 deletions cypress/pageobject/Login/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
Loading