Skip to content

Commit

Permalink
Update LoginPage.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaushikgtm authored Dec 12, 2024
1 parent a1efabe commit 73dacda
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions cypress/pageobject/Login/LoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,42 +51,53 @@ class LoginPage {
clickThirdPartyLicense() {
cy.get('a[href="/licenses"]').scrollIntoView().click();
}

switchLanguageAndVerifyButtonText(languageMappings: { [key: string]: string }) {
Object.entries(languageMappings).forEach(([languageCode, expectedText]) => {
cy.get(this.languageSelector)
.find(`option[value="${languageCode}"]`)
.should("exist");

cy.get(this.languageSelector).select(languageCode);

cy.get("button")
.contains("login", { timeout: 10000 }) // Direct interaction
.should("be.visible")
.and("have.text", expectedText);
});
}

switchLanguageAndVerifySidebars(languageMappings: {
[key: string]: { care: string; goal: string; footer_body: string };
}) {
Object.entries(languageMappings).forEach(([languageCode, expectedSidebarText]) => {
interface LanguageMapping {
[key: string]: {
login: string;
care: string;
goal: string;
footer_body: string;
};
}

switchLanguageAndVerifyButtonText(languageMappings: LanguageMapping) {
Object.entries(languageMappings).forEach(([languageCode, texts]) => {
cy.get(this.languageSelector)
.find(`option[value="${languageCode}"]`)
.should("exist")
.select(languageCode);

cy.get("#care", { timeout: 10000 })
.should("be.visible")
.and("have.text", expectedSidebarText.care);

cy.get("#goal", { timeout: 10000 })
.should("be.visible")
.and("have.text", expectedSidebarText.goal);

cy.get("#footer_body", { timeout: 10000 })
.should("be.visible")
.and("have.text", expectedSidebarText.footer_body);
.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")
.and("have.text", texts.login);
});
});
}

private verifySidebarElement(selector: string, expectedText: string) {
return cy.get(selector, { timeout: 10000 })
.should("be.visible")
.and("have.text", expectedText);
}

switchLanguageAndVerifySidebars(languageMappings: LanguageMapping) {
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);
});
});
}

Expand Down

0 comments on commit 73dacda

Please sign in to comment.