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 16, 2024
1 parent 5fb5947 commit 960bccf
Showing 1 changed file with 51 additions and 52 deletions.
103 changes: 51 additions & 52 deletions cypress/pageobject/Login/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// LoginPage.ts

interface LanguageMapping {
[key: string]: {
Expand Down Expand Up @@ -46,67 +45,67 @@ class LoginPage {
cy.get("#sign-out-button").scrollIntoView();
cy.get("#sign-out-button").contains("Sign Out").should("exist");
}
ensurePageLoaded() {

ensurePageLoaded(): void {
cy.get(this.submitButtonSelector).should("be.visible");
cy.get(this.languageSelector).should("be.visible");
cy.get("input[id='username']").should("be.visible");
cy.get("input[id='password']").should("be.visible");
}

clickContributeOnGitHub() {
cy.get('a[href="https://github.com/ohcnetwork"]').scrollIntoView().click();
clickContributeOnGitHub(): void {
cy.get('a[href="https://github.com/ohcnetwork"]').scrollIntoView().click();
}

clickThirdPartyLicense() {
cy.get('a[href="/licenses"]').scrollIntoView().click();
clickThirdPartyLicense(): void {
cy.get('a[href="/licenses"]').scrollIntoView().click();
}

switchLanguageAndVerifyButtonText(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);
cy.get(this.submitButtonSelector, { timeout: 10000 })
.should("be.visible")
.should("have.text", texts.login)
.should("not.be.disabled");
});
});
}

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

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);
});
});
}

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`);
} try{
this.selectLanguage(languageCode);
this.verifySidebarElement("#care", texts.care);
this.verifySidebarElement("#goal", texts.goal);
this.verifySidebarElement("#footer_body", texts.footer_body);
} catch (error: unknown) {
cy.log(`Failed to verify sidebar elements: ${error.message}`);
throw error;
}
});
});
}
}

export default LoginPage;

0 comments on commit 960bccf

Please sign in to comment.