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 #9238

Closed
wants to merge 11 commits into from

Conversation

Kaushikgtm
Copy link

@Kaushikgtm Kaushikgtm commented Nov 28, 2024

Proposed Changes

  • Fixes Add New cypress Test for language selection and link redirection #9017
  • Change 1 Added a Cypress test to verify that the login page's "Submit" button updates text dynamically when switching between different languages
  • Change 2 Created a test to log in with a non-English language (e.g., Hindi, Tamil, Kannada).
    Verified that sidebar items display correctly in the chosen language.
  • More?

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Added language selection functionality with a dropdown on the login page.
    • Introduced new test cases for verifying localization and redirection links.
    • Enhanced element selection capabilities for sidebar and contribution links.
    • Added methods for verifying button texts and sidebar items based on language selection.
  • Bug Fixes

    • Improved verification for sidebar items and button texts across multiple languages.
  • Documentation

    • Updated interface for language-specific text mappings to improve clarity and usability.

@Kaushikgtm Kaushikgtm requested a review from a team as a code owner November 28, 2024 19:18
Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Walkthrough

This pull request enhances the Cypress testing framework for the login page by introducing comprehensive language selection and link redirection tests. The changes focus on the LoginPage class in the LoginPage.ts file, adding new methods for language switching, verifying UI elements, and testing link redirections. The accompanying test file redirect.cy.ts implements these new methods, covering scenarios for GitHub link redirection, third-party license link verification, and language-specific UI text validation.

Changes

File Change Summary
cypress/pageobject/Login/LoginPage.ts - Added LanguageMapping and SidebarMapping interfaces
- Introduced methods for GitHub link and license link clicks
- Added language selection and verification methods
cypress/e2e/homepage_spec/redirect.cy.ts - Imported locale JSON for Tamil, Malayalam, Marathi, Kannada, and Hindi
- Added tests for link redirection and language switching
- Implemented UI verification tests for buttons and sidebars

Assessment against linked issues

Objective Addressed Explanation
Verify "Contribute on GitHub" link redirection [#9017]
Verify "Third Party Software License" link redirection [#9017]
Switch languages and verify login button text [#9017]
Verify sidebar items in different languages [#9017]

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • nihal467

Poem

🐰 A Rabbit's Linguistic Dance

In Cypress realm, where tests take flight,
Languages dance with pixel-perfect might.
GitHub links click, licenses unfurl,
Buttons and sidebars in a linguistic swirl.
Testing magic, code's sweet romance! 🌈

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Nov 28, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 091f420
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6769bec40a5a3e00084ab7ab
😎 Deploy Preview https://deploy-preview-9238--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (7)
cypress/e2e/auth_spec/redirect.cy.ts (4)

4-18: Add TypeScript types and documentation for language mappings

Consider adding TypeScript interfaces and JSDoc comments to improve maintainability and documentation.

+/** Mapping of language codes to their respective login button text translations */
+interface LanguageButtonMapping {
+  [key: string]: string;
+}

+/** Mapping of language codes to their respective sidebar content translations */
+interface LanguageSidebarMapping {
+  [key: string]: string;
+}

-const languageMappings = {
+const languageMappings: LanguageButtonMapping = {
   hi: "लॉग इन करें", // Hindi
   // ...
};

-const languageSidebars = {
+const languageSidebars: LanguageSidebarMapping = {
   hi: "देखभालहमारा...", // Hindi
   // ...
};
🧰 Tools
🪛 eslint

[error] 4-4: Delete ·

(prettier/prettier)


[error] 11-12: Delete

(prettier/prettier)


[error] 17-17: Replace ·//kannada· with ,·//kannada

(prettier/prettier)


21-24: Add error handling for page load failures

Consider adding timeout and error handling for the page load check to make tests more robust.

 beforeEach(() => {
   cy.log("Logging in the user devdistrictadmin");
-  loginPage.ensurePageLoaded();
+  loginPage.ensurePageLoaded().catch((error) => {
+    cy.log('Failed to load login page');
+    throw error;
+  });
 });

49-59: Enhance link redirection tests with additional assertions

While the tests verify basic redirection, consider adding:

  1. Negative test cases (e.g., when links are disabled/not present)
  2. More specific assertions about the target page content
 it("Verify redirection of 'Contribute on GitHub' link", () => {
   loginPage.clickContributeOnGitHub();
   cy.url().should("include", "https://github.com/ohcnetwork");
-  cy.get("body").contains("Contribute on GitHub")
+  // Verify link exists before clicking
+  cy.get('[data-testid="github-link"]').should('be.visible');
+  // More specific content verification
+  cy.get('[data-testid="repo-content"]').should('exist');
 });
🧰 Tools
🪛 eslint

[error] 49-49: Delete ··

(prettier/prettier)


[error] 52-52: Insert ;

(prettier/prettier)


[error] 54-54: Delete ··

(prettier/prettier)


61-67: Enhance language switch tests with persistence checks

Consider adding:

  1. Verification that selected language persists after page reload
  2. Specific assertions for each language switch
 it("Switch languages and verify login button text", () => {
   loginPage.switchLanguageAndVerifyButtonText(languageMappings);
+  // Verify language persistence
+  cy.reload();
+  cy.get('[data-testid="login-button"]').should('have.text', languageMappings.hi);
 });

 it("Switch languages and verify sidebar items", () => {
   loginPage.switchLanguageAndVerifySidebars(languageSidebars);
+  // Verify correct language is set in localStorage
+  cy.window().its('localStorage.i18nextLng').should('eq', 'hi');
 });
🧰 Tools
🪛 eslint

[error] 65-65: Insert ·

(prettier/prettier)


[error] 66-66: Insert ·

(prettier/prettier)

cypress/pageobject/Login/LoginPage.ts (3)

40-40: Remove unnecessary whitespace at line 40

There is unnecessary whitespace on line 40. Removing it will help maintain code cleanliness.

Apply this diff:

-  
🧰 Tools
🪛 eslint

[error] 40-40: Delete ··

(prettier/prettier)


71-73: Remove redundant method selectSidebarLanguage()

The selectSidebarLanguage() method is identical to selectLanguage(). To avoid redundancy, consider removing selectSidebarLanguage() and use selectLanguage() instead.

Apply this diff:

-  selectSidebarLanguage(languageCode: string) {
-    cy.get(this.languageSelector).select(languageCode);
-  }

Update references to selectSidebarLanguage():

- this.selectSidebarLanguage(languageCode);
+ this.selectLanguage(languageCode);

79-85: Refactor switchLanguageAndVerifySidebars() to reduce redundancy

Since selectSidebarLanguage() can be replaced with selectLanguage(), and verifySidebarText() has been corrected, consider refactoring switchLanguageAndVerifySidebars() to align with these changes. Additionally, if the logic is similar to switchLanguageAndVerifyButtonText(), you can generalize the method to handle both cases.

Possible refactor:

-  switchLanguageAndVerifySidebars(languageMappings: { [key: string]: string }) {
+  switchLanguageAndVerifyElements(
+    languageMappings: { [key: string]: string },
+    verifyFunction: (expectedText: string) => void
+  ) {
     Object.entries(languageMappings).forEach(([languageCode, expectedText]) => {
-      this.selectSidebarLanguage(languageCode);
+      this.selectLanguage(languageCode);
       cy.wait(500);
-      this.verifySidebarText(expectedText);
+      verifyFunction(expectedText);
     });
   }

You can then use this method for both buttons and sidebars:

// For buttons
this.switchLanguageAndVerifyElements(languageMappings, this.verifySubmitButtonText);

// For sidebars
this.switchLanguageAndVerifyElements(languageMappings, this.verifySidebarText);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fc2ac3b and a3f62d1.

📒 Files selected for processing (2)
  • cypress/e2e/auth_spec/redirect.cy.ts (2 hunks)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/e2e/auth_spec/redirect.cy.ts

[error] 4-4: Delete ·

(prettier/prettier)


[error] 11-12: Delete

(prettier/prettier)


[error] 17-17: Replace ·//kannada· with ,·//kannada

(prettier/prettier)


[error] 49-49: Delete ··

(prettier/prettier)


[error] 52-52: Insert ;

(prettier/prettier)


[error] 54-54: Delete ··

(prettier/prettier)


[error] 65-65: Insert ·

(prettier/prettier)


[error] 66-66: Insert ·

(prettier/prettier)


[error] 67-68: Delete

(prettier/prettier)

cypress/pageobject/Login/LoginPage.ts

[error] 40-40: Delete ··

(prettier/prettier)

🔇 Additional comments (4)
cypress/e2e/auth_spec/redirect.cy.ts (2)

Line range hint 27-47: LGTM! Existing tests are well-structured

The existing tests effectively cover URL redirection scenarios including basic login, redirect parameters, and same-origin policy enforcement.

🧰 Tools
🪛 eslint

[error] 49-49: Delete ··

(prettier/prettier)


[error] 52-52: Insert ;

(prettier/prettier)


[error] 54-54: Delete ··

(prettier/prettier)


[error] 65-65: Insert ·

(prettier/prettier)


[error] 66-66: Insert ·

(prettier/prettier)


[error] 67-68: Delete

(prettier/prettier)


Line range hint 1-68: Implementation successfully meets PR objectives

The tests effectively cover all required scenarios:

  1. Language selection and verification of button text ✓
  2. Sidebar content verification in different languages ✓
  3. Link redirection functionality ✓

Great job implementing comprehensive tests that align with the PR objectives!

🧰 Tools
🪛 eslint

[error] 4-4: Delete ·

(prettier/prettier)


[error] 11-12: Delete

(prettier/prettier)


[error] 17-17: Replace ·//kannada· with ,·//kannada

(prettier/prettier)

cypress/pageobject/Login/LoginPage.ts (2)

41-43: Method ensurePageLoaded() is properly implemented

The ensurePageLoaded() method correctly verifies that the page contains the text "Login", ensuring the page has loaded successfully.


53-55: Method selectLanguage() is correctly implemented

The selectLanguage() method properly selects a language using the languageSelector.

cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
@Jacobjeevan Jacobjeevan changed the title Add Cypress Test to Verify Bed Capacity Badge Behavior on Facility Card #9107 Cypress Test for language selection and link redirection Nov 28, 2024
@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Nov 29, 2024

Check and implement the Coderabbit suggestions that are worth doing @Kaushikgtm

Copy link

👋 Hi, @Kaushikgtm,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Nov 29, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
cypress/pageobject/Login/LoginPage.ts (1)

41-43: Consider enhancing page load verification.

The current implementation only checks for "Login" text. Consider making this more robust by verifying critical page elements.

  ensurePageLoaded() {
-    cy.get("body").should("contain", "Login");
+    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");
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a3f62d1 and 22ab14b.

📒 Files selected for processing (1)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/pageobject/Login/LoginPage.ts

[error] 40-40: Delete ··

(prettier/prettier)


[error] 46-46: Delete ·

(prettier/prettier)


[error] 50-50: Delete ·

(prettier/prettier)


[error] 76-76: Replace +···· with ····+

(prettier/prettier)

🔇 Additional comments (1)
cypress/pageobject/Login/LoginPage.ts (1)

4-6: LGTM! Selectors are properly defined with ID prefixes.

The selectors are correctly implemented following the previous review suggestions.

cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
cypress/pageobject/Login/LoginPage.ts (1)

45-51: Enhance link click verification

The methods should verify the resulting URLs and handle external links appropriately.

  clickContributeOnGitHub() {
-    cy.get('a[href="https://github.com/ohcnetwork"]').scrollIntoView().click();
+    cy.get('a[href="https://github.com/ohcnetwork"]')
+      .should('have.attr', 'target', '_blank')
+      .invoke('removeAttr', 'target')
+      .click();
+    cy.url().should('include', 'github.com/ohcnetwork');
  }

  clickThirdPartyLicense() {
-    cy.get('a[href="/licenses"]').scrollIntoView().click();
+    cy.get('a[href="/licenses"]').scrollIntoView().click();
+    cy.url().should('include', '/licenses');
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 22ab14b and 1a3b7b9.

📒 Files selected for processing (1)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
cypress/pageobject/Login/LoginPage.ts

[error] 67-67: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


[error] 84-84: Expected an expression but instead found '.'.

Expected an expression here.

(parse)

cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
@nihal467
Copy link
Member

@Kaushikgtm check the code rabbit suggestion and merge conflict issues

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
cypress/pageobject/Login/LoginPage.ts (1)

41-46: Add timeout configuration for page load checks

The implementation looks good but could be more resilient by adding consistent timeout configurations.

   ensurePageLoaded() {
-    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");
+    const timeout = { timeout: 10000 };
+    cy.get(this.submitButtonSelector, timeout).should("be.visible");
+    cy.get(this.languageSelector, timeout).should("be.visible");
+    cy.get("input[id='username']", timeout).should("be.visible");
+    cy.get("input[id='password']", timeout).should("be.visible");
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1a3b7b9 and 896a92e.

📒 Files selected for processing (1)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
cypress/pageobject/Login/LoginPage.ts

[error] 70-70: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


[error] 74-74: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


[error] 76-76: Expected a statement but instead found ')'.

Expected a statement here.

(parse)


[error] 92-92: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


[error] 72-76: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

🔇 Additional comments (4)
cypress/pageobject/Login/LoginPage.ts (4)

80-82: ⚠️ Potential issue

Remove duplicate language selection method

The selectSidebarLanguage method is identical to selectLanguage and should be removed.

Remove this duplicate method and update all references to use selectLanguage instead.


56-62: 🛠️ Refactor suggestion

Add error handling for language selection

The language selection should handle cases where the language code doesn't exist.

   selectLanguage(languageCode: string) {
+    cy.get(this.languageSelector)
+      .find(`option[value="${languageCode}"]`)
+      .should('exist')
+      .then(() => {
         cy.get(this.languageSelector).select(languageCode);
+      });
   }

Likely invalid or redundant comment.


88-95: ⚠️ Potential issue

Fix syntax errors and maintain consistency with button verification method

The implementation should follow the same pattern as switchLanguageAndVerifyButtonText.

   switchLanguageAndVerifySidebars(languageMappings: { [key: string]: string }) {
     Object.entries(languageMappings).forEach(([languageCode, expectedText]) => {
-      this.selectLanguage(languageCode);
-      cy.get(this.sidebarSelector, { timeout: 10000 })
-        .should("be.visible")
-        .and("have.text", expectedText);
+      cy.get(this.languageSelector)
+        .find(`option[value="${languageCode}"]`)
+        .should('exist')
+        .then(() => {
+          this.selectLanguage(languageCode);
+          cy.get(this.sidebarSelector, { timeout: 10000 })
+            .should("be.visible")
+            .should("have.text", expectedText);
+        });
     });
   }

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 92-92: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


64-78: ⚠️ Potential issue

Fix syntax errors in chain calls and improve error handling

The implementation has syntax errors in the chain calls and could use better error handling.

   switchLanguageAndVerifyButtonText(languageMappings: {
     [key: string]: string;
   }) {
     Object.entries(languageMappings).forEach(([languageCode, expectedText]) => {
-      this.selectLanguage(languageCode);
-      cy.get(this.languageSelector)
-        .find(`option[value="${languageCode}"]`)
-        .should('exist')
-        .then(() => {
-        cy.get(this.submitButtonSelector, { timeout: 10000 })
-          .should("be.visible")
-          .should("have.text", expectedText);
-      });
+      cy.get(this.languageSelector)
+        .find(`option[value="${languageCode}"]`)
+        .should('exist')
+        .then(() => {
+          this.selectLanguage(languageCode);
+          cy.get(this.submitButtonSelector, { timeout: 10000 })
+            .should("be.visible")
+            .should("have.text", expectedText);
+        });
     });
   }

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 70-70: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


[error] 74-74: Expected an expression but instead found '.'.

Expected an expression here.

(parse)


[error] 76-76: Expected a statement but instead found ')'.

Expected a statement here.

(parse)


[error] 72-76: This block statement doesn't serve any purpose and can be safely removed.

Standalone block statements without any block-level declarations are redundant in JavaScript and can be removed to simplify the code.
Safe fix: Remove redundant block.

(lint/complexity/noUselessLoneBlockStatements)

cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
@Jacobjeevan
Copy link
Contributor

Noticed that #9258 was a duplicate PR (closed). Please refer to the comments there and make changes accordingly 👍

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 896a92e and 29e045f.

📒 Files selected for processing (1)
  • cypress/e2e/auth_spec/redirect.cy.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/e2e/auth_spec/redirect.cy.ts

[error] 5-5: Insert ··

(prettier/prettier)


[error] 6-6: Replace ·· with ····

(prettier/prettier)


[error] 7-7: Replace ·· with ····

(prettier/prettier)


[error] 8-8: Insert ··

(prettier/prettier)


[error] 9-9: Insert ··

(prettier/prettier)


[error] 37-37: Insert ;

(prettier/prettier)


[error] 42-42: Insert ·

(prettier/prettier)


[error] 68-68: Delete ··

(prettier/prettier)


[error] 71-71: Insert ;

(prettier/prettier)


[error] 73-73: Delete ··

(prettier/prettier)


[error] 84-84: Insert ·

(prettier/prettier)


[error] 85-85: Insert ·

(prettier/prettier)


[error] 86-87: Delete

(prettier/prettier)

🔇 Additional comments (1)
cypress/e2e/auth_spec/redirect.cy.ts (1)

80-86: 🛠️ Refactor suggestion

Add test cases for invalid language scenarios

The language switching tests should include error cases and validation:

it("Should handle invalid language selection gracefully", () => {
  // Test with invalid language code
  loginPage.switchLanguageAndVerifyButtonText({ 
    invalidLang: "Invalid Text" 
  } as any).should(() => {
    // Verify it falls back to default language
  });
});
🧰 Tools
🪛 eslint

[error] 84-84: Insert ·

(prettier/prettier)


[error] 85-85: Insert ·

(prettier/prettier)

cypress/e2e/auth_spec/redirect.cy.ts Outdated Show resolved Hide resolved
cypress/e2e/auth_spec/redirect.cy.ts Outdated Show resolved Hide resolved
cypress/e2e/auth_spec/redirect.cy.ts Outdated Show resolved Hide resolved
@Kaushikgtm
Copy link
Author

@Jacobjeevan I have made some changes please see

Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to test your changes before requesting for a review. Run cypress locally and ensure the tests are passing.

cypress/e2e/auth_spec/redirect.cy.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/e2e/auth_spec/redirect.cy.ts Outdated Show resolved Hide resolved
@nihal467
Copy link
Member

nihal467 commented Dec 9, 2024

@Kaushikgtm Can you please share the current status of the PR? Otherwise, the PR will be closed in the next 48 hours, and you will be unassigned from the issue due to inactivity.

@nihal467 nihal467 added the stale label Dec 9, 2024
@Kaushikgtm
Copy link
Author

@nihal467 I have update the PR, due to my semester exam i am inactive on this issue

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 29e045f and d6d4c4d.

📒 Files selected for processing (2)
  • cypress/e2e/auth_spec/redirect.cy.ts (2 hunks)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/pageobject/Login/LoginPage.ts

[error] 40-40: Delete ··

(prettier/prettier)


[error] 42-42: Replace +···· with ····+

(prettier/prettier)


[error] 43-43: Replace +···· with ····+

(prettier/prettier)


[error] 44-44: Replace +···· with ····+

(prettier/prettier)


[error] 45-45: Replace +···· with ····+

(prettier/prettier)


[error] 49-49: Delete ·

(prettier/prettier)


[error] 53-53: Delete ·

(prettier/prettier)


[error] 55-56: Replace ··⏎switchLanguageAndVerifyButtonText(languageMappings:·{·[key:·string]:·string with ⏎··switchLanguageAndVerifyButtonText(languageMappings:·{⏎····[key:·string]:·string;⏎·

(prettier/prettier)


[error] 57-57: Insert ··

(prettier/prettier)


[error] 58-58: Replace ···· with ······

(prettier/prettier)


[error] 59-59: Insert ··

(prettier/prettier)


[error] 60-60: Replace ······ with ········

(prettier/prettier)


[error] 62-62: Insert ··

(prettier/prettier)


[error] 64-64: Insert ··

(prettier/prettier)


[error] 65-65: Insert ··

(prettier/prettier)


[error] 66-66: Insert ··

(prettier/prettier)


[error] 67-67: Insert ··

(prettier/prettier)


[error] 68-68: Insert ··

(prettier/prettier)


[error] 70-70: Insert ··

(prettier/prettier)


[error] 71-71: Insert ··

(prettier/prettier)


[error] 72-72: Insert ··

(prettier/prettier)


[error] 73-73: Replace ··Object.entries(languageMappings).forEach( with ····Object.entries(languageMappings).forEach(⏎······

(prettier/prettier)


[error] 74-74: Insert ····

(prettier/prettier)


[error] 75-75: Replace ······ with ··········

(prettier/prettier)


[error] 76-76: Insert ····

(prettier/prettier)


[error] 77-77: Replace ······ with ··········

(prettier/prettier)


[error] 79-79: Insert ····

(prettier/prettier)


[error] 80-80: Insert ····

(prettier/prettier)


[error] 81-81: Insert ····

(prettier/prettier)


[error] 83-83: Insert ····

(prettier/prettier)


[error] 84-84: Replace ······ with ··········

(prettier/prettier)


[error] 85-85: Insert ····

(prettier/prettier)


[error] 87-87: Replace ···· with ········

(prettier/prettier)


[error] 88-88: Insert ····

(prettier/prettier)


[error] 89-89: Replace ······ with ··········

(prettier/prettier)


[error] 90-90: Replace } with ····},⏎····

(prettier/prettier)


[error] 91-92: Replace }⏎ with ··}

(prettier/prettier)

cypress/e2e/auth_spec/redirect.cy.ts

[error] 12-12: Replace langCode,·locale["login"]]) with ⏎······langCode,⏎······locale["login"],⏎····]),

(prettier/prettier)


[error] 14-14: Delete ·

(prettier/prettier)


[error] 17-17: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 18-18: Insert ,

(prettier/prettier)


[error] 20-20: Delete ··

(prettier/prettier)


[error] 24-24: Insert ·

(prettier/prettier)


[error] 50-50: Delete ··

(prettier/prettier)


[error] 51-51: Delete ··

(prettier/prettier)


[error] 52-52: Replace ··cy.url({·timeout:·10000·}).should("include",·"https://github.com/ohcnetwork"); with cy.url({·timeout:·10000·}).should(⏎······"include",⏎······"https://github.com/ohcnetwork",

(prettier/prettier)


[error] 53-53: Insert );⏎··

(prettier/prettier)


[error] 54-54: Replace ···· with ······

(prettier/prettier)


[error] 55-55: Insert ··

(prettier/prettier)


[error] 57-57: Delete ··

(prettier/prettier)


[error] 62-62: Replace ···· with ······

(prettier/prettier)


[error] 63-63: Insert ··

(prettier/prettier)


[error] 70-70: Insert ·

(prettier/prettier)


[error] 71-71: Insert ·

(prettier/prettier)


[error] 72-73: Delete

(prettier/prettier)

🔇 Additional comments (5)
cypress/pageobject/Login/LoginPage.ts (1)

41-46: LGTM! Comprehensive page load verification.

The implementation correctly verifies all critical elements before proceeding with tests.

🧰 Tools
🪛 eslint

[error] 42-42: Replace +···· with ····+

(prettier/prettier)


[error] 43-43: Replace +···· with ····+

(prettier/prettier)


[error] 44-44: Replace +···· with ····+

(prettier/prettier)


[error] 45-45: Replace +···· with ····+

(prettier/prettier)

cypress/e2e/auth_spec/redirect.cy.ts (4)

2-7: Add missing imports and organize them better

The language JSON imports should be organized better. Consider grouping related imports together.

 import LoginPage from "../../pageobject/Login/LoginPage";
+import { expect } from "cypress";
+
+// Language imports
 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";

24-25: Document the awaitUrl parameter usage

Add a comment explaining that true disables the login status verification since we're on the login page.

 beforeEach(() => {
+  // Pass true to disable login verification since we're on the login page
   cy.awaitUrl("/",true);
   loginPage.ensurePageLoaded();
 });
🧰 Tools
🪛 eslint

[error] 24-24: Insert ·

(prettier/prettier)


50-64: Enhance error handling in link redirection tests

The tests should handle navigation failures more gracefully.

 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");
+  cy.url({ timeout: 10000 })
+    .should("include", "https://github.com/ohcnetwork")
+    .then((url) => {
+      expect(url).to.include("ohcnetwork", "URL should contain organization name");
+    });
+  
+  // Retry until content is visible or timeout
+  cy.get("body", { timeout: 10000 })
+    .should("be.visible")
+    .and("contain", "Contribute on GitHub")
+    .then(($body) => {
+      expect($body).to.contain("Contribute on GitHub", "Page should display GitHub content");
+    });
 });
🧰 Tools
🪛 eslint

[error] 50-50: Delete ··

(prettier/prettier)


[error] 51-51: Delete ··

(prettier/prettier)


[error] 52-52: Replace ··cy.url({·timeout:·10000·}).should("include",·"https://github.com/ohcnetwork"); with cy.url({·timeout:·10000·}).should(⏎······"include",⏎······"https://github.com/ohcnetwork",

(prettier/prettier)


[error] 53-53: Insert );⏎··

(prettier/prettier)


[error] 54-54: Replace ···· with ······

(prettier/prettier)


[error] 55-55: Insert ··

(prettier/prettier)


[error] 57-57: Delete ··

(prettier/prettier)


[error] 62-62: Replace ···· with ······

(prettier/prettier)


[error] 63-63: Insert ··

(prettier/prettier)


11-19: 🛠️ Refactor suggestion

Improve type safety and reduce repetition in language mappings

The language mappings could benefit from TypeScript types and a more DRY approach.

type SupportedLanguage = 'hi' | 'ta' | 'ml' | 'mr' | 'kn';
type LocaleContent = typeof hi;  // Use one of the imports as the base type

interface SidebarContent {
  care: string;
  goal: string;
  footer_body: string;
}

const createSidebarContent = (locale: LocaleContent): SidebarContent => ({
  care: locale.care,
  goal: locale.goal,
  footer_body: locale.footer_body,
});

const languageMappings = Object.fromEntries(
  Object.entries(locales).map(([langCode, locale]) => [langCode, locale.login])
) as Record<SupportedLanguage, string>;

const languageSidebars = Object.fromEntries(
  Object.entries(locales).map(([langCode, locale]) => [
    langCode,
    createSidebarContent(locale),
  ])
) as Record<SupportedLanguage, SidebarContent>;
🧰 Tools
🪛 eslint

[error] 12-12: Replace langCode,·locale["login"]]) with ⏎······langCode,⏎······locale["login"],⏎····]),

(prettier/prettier)


[error] 14-14: Delete ·

(prettier/prettier)


[error] 17-17: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 18-18: Insert ,

(prettier/prettier)

cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/pageobject/Login/LoginPage.ts Outdated Show resolved Hide resolved
cypress/e2e/auth_spec/redirect.cy.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the stale label Dec 10, 2024
@Kaushikgtm
Copy link
Author

@Jacobjeevan, I have made some changes based on your suggestions

@Jacobjeevan
Copy link
Contributor

@Jacobjeevan, I have made some changes based on your suggestions

Some of the coderabbit suggestions are worth doing 👍 Implement those and resolve the merge conflicts.

@Kaushikgtm Kaushikgtm reopened this Dec 19, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (4)
cypress/pageobject/Login/LoginPage.ts (2)

112-128: Add wait for language change to complete.

Add verification that the language change has completed before checking the button text.

   this.selectLanguage(languageCode);
+  // Wait for language change to complete
+  cy.get("html")
+    .should("have.attr", "lang", languageCode);
   cy.get(this.submitButtonSelector, { timeout: 10000 })
🧰 Tools
🪛 eslint

[error] 112-112: Delete ··

(prettier/prettier)


135-150: Enhance error handling for sidebar verification.

Add try-catch block to better handle and report sidebar verification failures.

   this.selectLanguage(languageCode);
+  try {
     this.verifySidebarElement("#care", texts.care);
     this.verifySidebarElement("#goal", texts.goal);
     this.verifySidebarElement("#footer_body", texts.footer_body);
+  } catch (error: unknown) {
+    const errorMessage = error instanceof Error ? error.message : 'Unknown error';
+    cy.log(`Failed to verify sidebar elements: ${errorMessage}`);
+    throw error;
+  }
🧰 Tools
🪛 eslint

[error] 135-135: Delete ·

(prettier/prettier)

cypress/e2e/homepage_spec/redirect.cy.ts (2)

2-8: Consider adding TypeScript interfaces for locale files

While the imports are well-organized, adding TypeScript interfaces would improve type safety and maintainability.

interface LocaleStrings {
  login: string;
  care: string;
  goal: string;
  footer_body: string;
  // Add other required strings
}

const locales: Record<string, LocaleStrings> = { hi, ta, ml, mr, kn };

24-25: Document the purpose of awaitUrl parameter

The true parameter passed to cy.awaitUrl() needs documentation to explain its purpose and impact.

// Add a comment explaining the purpose:
// Wait for the URL to be exactly "/" before proceeding
// The `true` parameter ensures exact URL match
cy.awaitUrl("/", true);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 960bccf and 6e9aa07.

📒 Files selected for processing (2)
  • cypress/e2e/homepage_spec/redirect.cy.ts (2 hunks)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/pageobject/Login/LoginPage.ts

[error] 14-14: Delete ·

(prettier/prettier)


[error] 102-102: Delete ··

(prettier/prettier)


[error] 109-109: Delete ··

(prettier/prettier)


[error] 112-112: Delete ··

(prettier/prettier)


[error] 129-129: Delete ·

(prettier/prettier)


[error] 135-135: Delete ·

(prettier/prettier)

🔇 Additional comments (5)
cypress/pageobject/Login/LoginPage.ts (4)

3-10: LGTM! Well-structured interface definition.

The LanguageMapping interface correctly defines the structure for language-specific text mappings and is properly placed at the module level.


13-14: LGTM! Well-defined selectors.

The selectors are properly defined with correct ID format and explicit typing.

🧰 Tools
🪛 eslint

[error] 14-14: Delete ·

(prettier/prettier)


102-104: 🛠️ Refactor suggestion

Add URL verification after clicking the GitHub link.

While the implementation is good, add URL verification to ensure successful navigation.

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

Likely invalid or redundant comment.

🧰 Tools
🪛 eslint

[error] 102-102: Delete ··

(prettier/prettier)


106-108: 🛠️ Refactor suggestion

Add URL verification after clicking the license link.

Add URL verification to ensure successful navigation.

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

Likely invalid or redundant comment.

cypress/e2e/homepage_spec/redirect.cy.ts (1)

Line range hint 1-84: Verify test coverage against requirements

The tests implement the required functionality, but let's verify the coverage.

✅ Verification successful

Test implementation is comprehensive and well-structured

The verification shows that:

  • The LoginPage class has robust language switching implementation with proper type safety (LanguageMapping interface)
  • Test coverage includes:
    • Language switching for login button text
    • Sidebar content verification in multiple languages
    • Error handling for missing language options
    • Proper timeout and visibility checks
  • The implementation follows page object pattern best practices with clear separation of concerns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if all required test scenarios are covered

# Look for language-related test files
echo "Checking for language-related test files..."
fd -e ts -e js "language|locale|i18n" cypress/

# Check for existing similar tests to avoid duplication
echo "Checking for similar existing tests..."
rg -l "switchLanguage|languageMapping" cypress/

# Verify all locale files are imported
echo "Verifying locale file imports..."
fd -e json . src/Locale/

Length of output: 463


Script:

#!/bin/bash
# Let's examine the content of LoginPage.ts to verify the implementation of language switching
echo "Checking LoginPage implementation..."
cat cypress/pageobject/Login/LoginPage.ts

# Let's verify all available locale files
echo "Checking locale files in src/Locale..."
ls -la src/Locale/

# Let's check if there are any other language-related tests
echo "Checking for other language tests..."
rg -l "language|locale|i18n" cypress/e2e/

Length of output: 5283

🧰 Tools
🪛 Biome (1.9.4)

[error] 85-85: expected } but instead the file ends

the file ends here

(parse)

Comment on lines 11 to 20
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"] },
])
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for missing translations

The current implementation assumes all required translations exist. Consider adding validation and error handling.

const languageMappings = Object.fromEntries(
  Object.entries(locales).map(([langCode, locale]) => {
    if (!locale["login"]) {
      throw new Error(`Missing 'login' translation for language: ${langCode}`);
    }
    return [langCode, locale["login"]];
  })
);

Comment on lines +51 to +57
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");
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve GitHub link redirection test robustness

The test could be more specific in its assertions and should use consistent timeout values.

const NETWORK_TIMEOUT = 10000;

it("Verify redirection of 'Contribute on GitHub' link", () => {
  const expectedUrl = "https://github.com/ohcnetwork";
  loginPage.clickContributeOnGitHub();
  cy.url({ timeout: NETWORK_TIMEOUT }).should("eq", expectedUrl);
  cy.get("body", { timeout: NETWORK_TIMEOUT })
    .should("be.visible")
    .find("h1")  // Be more specific about where to find the text
    .should("contain", "Contribute on GitHub");
});

Comment on lines 67 to 84
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);
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance language switching test robustness

The language switching tests could be more robust with better error handling and validation.

it("Switch languages and verify login button text", () => {
  const testedLanguages = new Set();
  
  cy.wrap(Object.entries(languageMappings)).each(([lang, expected]) => {
    testedLanguages.add(lang);
    cy.log(`Testing login button in language: ${lang}`);
    loginPage.switchLanguage(lang);
    loginPage.getSubmitButton()
      .should("be.visible")
      .and("have.text", expected)
      .then(() => {
        cy.log(`✓ Verified ${lang} translation: ${expected}`);
      });
  }).then(() => {
    // Verify all languages were tested
    expect(testedLanguages.size).to.equal(Object.keys(languageMappings).length);
  });
});

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Dec 19, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
cypress/pageobject/Login/LoginPage.ts (2)

3-14: Consider making interface properties optional for better reusability.

The interfaces are well-structured, but making properties optional would improve reusability across different scenarios where not all translations might be required.

 interface LanguageMapping {
   [key: string]: {
-    login: string;
+    login?: string;
   };
 }
 interface SidebarMapping {
   [key: string]: {
-    care: string;
-    goal: string;
-    footer_body: string;
+    care?: string;
+    goal?: string;
+    footer_body?: string;
   };
 }

131-133: Improve readability of getSidebarItems method.

Consider using an array and join for better readability of the selector string.

 getSidebarItems() {
-  return cy.get(`${this.sidebarSelectors.care}, ${this.sidebarSelectors.goal}, ${this.sidebarSelectors.footer_body}`);
+  const selectors = [
+    this.sidebarSelectors.care,
+    this.sidebarSelectors.goal,
+    this.sidebarSelectors.footer_body
+  ];
+  return cy.get(selectors.join(', '));
 }
🧰 Tools
🪛 eslint

[error] 132-132: Replace ${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body} with ⏎······${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body},⏎····

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e9aa07 and d1156e7.

📒 Files selected for processing (2)
  • cypress/e2e/homepage_spec/redirect.cy.ts (2 hunks)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/pageobject/Login/LoginPage.ts

[error] 132-132: Replace ${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body} with ⏎······${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body},⏎····

(prettier/prettier)


[error] 172-172: Replace this.sidebarSelectors.footer_body,·texts.footer_body with ⏎············this.sidebarSelectors.footer_body,⏎············texts.footer_body,⏎··········

(prettier/prettier)

cypress/e2e/homepage_spec/redirect.cy.ts

[error] 2-2: Replace ta·from·"../../../public/locale/ta with kn·from·"../../../public/locale/kn

(prettier/prettier)


[error] 5-5: Replace kn·from·"../../../public/locale/kn with ta·from·"../../../public/locale/ta

(prettier/prettier)


[error] 6-6: Replace *·as·hi·from·"../../../public/locale/hi.json with LoginPage·from·"../../pageobject/Login/LoginPage

(prettier/prettier)


[error] 12-12: Replace langCode, with ⏎······langCode,⏎·····

(prettier/prettier)


[error] 13-13: Replace ······login:·locale["login"] with ········login:·locale["login"],

(prettier/prettier)


[error] 14-14: Replace ····}]) with ······},⏎····]),

(prettier/prettier)


[error] 20-20: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 21-21: Insert ,

(prettier/prettier)


[error] 56-56: Replace "include",·"https://github.com/ohcnetwork" with ⏎······"include",⏎······"https://github.com/ohcnetwork",⏎····

(prettier/prettier)

🔇 Additional comments (7)
cypress/e2e/homepage_spec/redirect.cy.ts (3)

2-22: LGTM! Well-structured locale mappings.

The implementation of language mappings is clean, type-safe, and follows TypeScript best practices.

🧰 Tools
🪛 eslint

[error] 2-2: Replace ta·from·"../../../public/locale/ta with kn·from·"../../../public/locale/kn

(prettier/prettier)


[error] 5-5: Replace kn·from·"../../../public/locale/kn with ta·from·"../../../public/locale/ta

(prettier/prettier)


[error] 6-6: Replace *·as·hi·from·"../../../public/locale/hi.json with LoginPage·from·"../../pageobject/Login/LoginPage

(prettier/prettier)


[error] 12-12: Replace langCode, with ⏎······langCode,⏎·····

(prettier/prettier)


[error] 13-13: Replace ······login:·locale["login"] with ········login:·locale["login"],

(prettier/prettier)


[error] 14-14: Replace ····}]) with ······},⏎····]),

(prettier/prettier)


[error] 20-20: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 21-21: Insert ,

(prettier/prettier)


54-60: Consider implementing the previously suggested improvements.

The test implementation could be more robust with specific URL assertions and consistent timeout values.

🧰 Tools
🪛 eslint

[error] 56-56: Replace "include",·"https://github.com/ohcnetwork" with ⏎······"include",⏎······"https://github.com/ohcnetwork",⏎····

(prettier/prettier)


70-72: Consider implementing the previously suggested error handling improvements.

The language switching test could be more robust with better error handling and validation.

cypress/pageobject/Login/LoginPage.ts (4)

17-25: LGTM! Well-organized selectors.

The selectors are well-structured and follow Cypress best practices for element selection.


135-151: Consider implementing the previously suggested improvements for language verification.

The implementation could benefit from the previously suggested improvements regarding error handling and retry options.


153-175: Consider implementing the previously suggested improvements for sidebar verification.

The implementation could benefit from the previously suggested improvements regarding error handling and retry options.

🧰 Tools
🪛 eslint

[error] 172-172: Replace this.sidebarSelectors.footer_body,·texts.footer_body with ⏎············this.sidebarSelectors.footer_body,⏎············texts.footer_body,⏎··········

(prettier/prettier)


115-121: 🛠️ Refactor suggestion

Add URL verification after link clicks.

Consider adding URL verification to ensure successful navigation after clicking the links.

 clickContributeOnGitHub(): void {
   cy.get(this.contributeOnGitHubLink).scrollIntoView().click();
+  cy.url().should('include', 'github.com/ohcnetwork');
 }

 clickThirdPartyLicense(): void {
   cy.get(this.thirdPartyLicenseLink).scrollIntoView().click();
+  cy.url().should('include', '/licenses');
 }

Likely invalid or redundant comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
cypress/e2e/homepage_spec/redirect.cy.ts (2)

11-22: 🛠️ Refactor suggestion

Add error handling and type safety for translations

The current implementation assumes all required translations exist and lacks type safety.

Additionally, consider adding TypeScript interfaces for better type safety:

interface LocaleKeys {
  login: string;
  care: string;
  goal: string;
  footer_body: string;
}

type LocaleMap = Record<string, LocaleKeys>;

// Add type assertions
const locales = { hi, ta, ml, mr, kn } as LocaleMap;
🧰 Tools
🪛 eslint

[error] 12-12: Replace langCode, with ⏎······langCode,⏎·····

(prettier/prettier)


[error] 13-13: Replace ······login:·locale["login"] with ········login:·locale["login"],

(prettier/prettier)


[error] 14-14: Replace ····}]) with ······},⏎····]),

(prettier/prettier)


[error] 20-20: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 21-21: Insert ,

(prettier/prettier)


54-68: 🛠️ Refactor suggestion

Improve link redirection tests

The tests could be more robust with consistent timeout values and specific assertions.

Additionally, consider extracting the timeout value and URLs as constants:

const NETWORK_TIMEOUT = 10000;
const GITHUB_URL = 'https://github.com/ohcnetwork';
const LICENSE_URL = '/licenses';

it("Verify redirection of 'Third Party Software License'", () => {
  loginPage.clickThirdPartyLicense();
  cy.url({ timeout: NETWORK_TIMEOUT }).should("include", LICENSE_URL);
  cy.get("body", { timeout: NETWORK_TIMEOUT })
    .should("be.visible")
    .and("contain", "Third Party Software License");
});
🧰 Tools
🪛 eslint

[error] 56-56: Replace "include",·"https://github.com/ohcnetwork" with ⏎······"include",⏎······"https://github.com/ohcnetwork",⏎····

(prettier/prettier)

🧹 Nitpick comments (5)
cypress/e2e/homepage_spec/redirect.cy.ts (2)

2-8: Consider centralizing locale imports

The current approach of importing individual locale files could become harder to maintain as more languages are added. Consider creating a central locale registry or using dynamic imports.

// locales/index.ts
export const SUPPORTED_LOCALES = ['hi', 'ta', 'ml', 'mr', 'kn'] as const;

export const loadLocale = async (code: typeof SUPPORTED_LOCALES[number]) => 
  import(`../../../public/locale/${code}.json`);

// In test file
const locales = await Promise.all(
  SUPPORTED_LOCALES.map(async code => [code, await loadLocale(code)])
);
🧰 Tools
🪛 eslint

[error] 2-2: Replace ta·from·"../../../public/locale/ta with kn·from·"../../../public/locale/kn

(prettier/prettier)


[error] 5-5: Replace kn·from·"../../../public/locale/kn with ta·from·"../../../public/locale/ta

(prettier/prettier)


[error] 6-6: Replace *·as·hi·from·"../../../public/locale/hi.json with LoginPage·from·"../../pageobject/Login/LoginPage

(prettier/prettier)


27-28: Document the purpose of the boolean parameter in awaitUrl

The true parameter in cy.awaitUrl("/", true) is not self-documenting. Consider adding a comment explaining its purpose or use a named parameter.

cypress/pageobject/Login/LoginPage.ts (3)

3-14: Consider expanding LanguageMapping interface.

The LanguageMapping interface only includes the login button text. Consider expanding it to include other UI elements that might need translations (e.g., form labels, error messages, etc.).

Would you like me to help identify other UI elements that might need translations and propose an expanded interface?


131-133: Improve getSidebarItems selector composition.

The current selector concatenation could be more maintainable:

 getSidebarItems() {
-  return cy.get(`${this.sidebarSelectors.care}, ${this.sidebarSelectors.goal}, ${this.sidebarSelectors.footer_body}`);
+  const selectors = Object.values(this.sidebarSelectors);
+  return cy.get(selectors.join(', '));
 }
🧰 Tools
🪛 eslint

[error] 132-132: Replace ${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body} with ⏎······${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body},⏎····

(prettier/prettier)


153-158: Enhance error handling in verifySidebarElement.

The method should provide more descriptive error messages:

 private verifySidebarElement(selector: string, expectedText: string): void {
   cy.get(selector, { timeout: 10000 })
     .should("be.visible")
     .should("have.text", expectedText)
-    .should("not.be.disabled");
+    .should("not.be.disabled")
+    .then($el => {
+      if ($el.length === 0) {
+        throw new Error(`Sidebar element "${selector}" not found`);
+      }
+      if ($el.text() !== expectedText) {
+        throw new Error(`Expected "${expectedText}" but found "${$el.text()}" in "${selector}"`);
+      }
+    });
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e9aa07 and d1156e7.

📒 Files selected for processing (2)
  • cypress/e2e/homepage_spec/redirect.cy.ts (2 hunks)
  • cypress/pageobject/Login/LoginPage.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/e2e/homepage_spec/redirect.cy.ts

[error] 2-2: Replace ta·from·"../../../public/locale/ta with kn·from·"../../../public/locale/kn

(prettier/prettier)


[error] 5-5: Replace kn·from·"../../../public/locale/kn with ta·from·"../../../public/locale/ta

(prettier/prettier)


[error] 6-6: Replace *·as·hi·from·"../../../public/locale/hi.json with LoginPage·from·"../../pageobject/Login/LoginPage

(prettier/prettier)


[error] 12-12: Replace langCode, with ⏎······langCode,⏎·····

(prettier/prettier)


[error] 13-13: Replace ······login:·locale["login"] with ········login:·locale["login"],

(prettier/prettier)


[error] 14-14: Replace ····}]) with ······},⏎····]),

(prettier/prettier)


[error] 20-20: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 21-21: Insert ,

(prettier/prettier)


[error] 56-56: Replace "include",·"https://github.com/ohcnetwork" with ⏎······"include",⏎······"https://github.com/ohcnetwork",⏎····

(prettier/prettier)

cypress/pageobject/Login/LoginPage.ts

[error] 132-132: Replace ${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body} with ⏎······${this.sidebarSelectors.care},·${this.sidebarSelectors.goal},·${this.sidebarSelectors.footer_body},⏎····

(prettier/prettier)


[error] 172-172: Replace this.sidebarSelectors.footer_body,·texts.footer_body with ⏎············this.sidebarSelectors.footer_body,⏎············texts.footer_body,⏎··········

(prettier/prettier)

🔇 Additional comments (4)
cypress/e2e/homepage_spec/redirect.cy.ts (1)

70-76: Enhance language switching test coverage

The language switching tests could be more comprehensive.

Additionally, verify that the language switch actually occurred:

#!/bin/bash
# Description: Check if LoginPage methods properly verify language switch success

# Search for language switch verification in LoginPage
ast-grep --pattern 'switchLanguage($_) {
  $$$
  cy.get($_).should($$$)
  $$$
}'

# Search for URL parameter verification
rg -A 2 'cy\.url\(\)\.should\(.*lang='
cypress/pageobject/Login/LoginPage.ts (3)

17-25: LGTM! Well-structured selectors.

The selectors are well-organized and follow Cypress best practices:

  • Good use of ID selectors for internal elements
  • Appropriate use of attribute selectors for external links
  • Clear and meaningful property names

115-121: 🛠️ Refactor suggestion

Add URL verification after link clicks.

While the click implementations are good, they should verify successful navigation:

 clickContributeOnGitHub(): void {
   cy.get(this.contributeOnGitHubLink).scrollIntoView().click();
+  cy.url().should('include', 'github.com/ohcnetwork');
 }

 clickThirdPartyLicense(): void {
   cy.get(this.thirdPartyLicenseLink).scrollIntoView().click();
+  cy.url().should('include', '/licenses');
 }

Likely invalid or redundant comment.


135-151: 🛠️ Refactor suggestion

Add wait for language change to complete.

The language verification should wait for the language change to complete:

 this.switchLanguage(languageCode);
+// Wait for language change to complete
+cy.get('html').should('have.attr', 'lang', languageCode);
 cy.get(this.submitButtonSelector, { timeout: 10000 })

Likely invalid or redundant comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
cypress/e2e/homepage_spec/redirect.cy.ts (1)

11-15: 🛠️ Refactor suggestion

Add type safety and error handling for language mappings.

The current implementation lacks type safety and error handling for missing translations.

interface LocaleType {
  login: string;
  [key: string]: any;
}

const languageMappings = Object.fromEntries(
  Object.entries(locales).map(([langCode, locale]) => {
    if (!locale["login"]) {
      throw new Error(`Missing 'login' translation for language: ${langCode}`);
    }
    return [langCode, {
      login: locale["login"]
    }];
  })
);
🧰 Tools
🪛 eslint

[error] 12-12: Replace langCode, with ⏎······langCode,⏎·····

(prettier/prettier)


[error] 13-13: Replace ······login:·locale["login"] with ········login:·locale["login"],

(prettier/prettier)


[error] 14-14: Replace ····}]) with ······},⏎····]),

(prettier/prettier)

🧹 Nitpick comments (3)
cypress/e2e/homepage_spec/redirect.cy.ts (3)

2-8: Consider using dynamic imports for locale files.

Instead of importing all locale files statically, consider using dynamic imports to load them on demand. This can improve initial load time and reduce memory usage.

const loadLocale = async (lang: string) => {
  return import(`../../../public/locale/${lang}.json`);
};
🧰 Tools
🪛 eslint

[error] 2-2: Replace ta·from·"../../../public/locale/ta with kn·from·"../../../public/locale/kn

(prettier/prettier)


[error] 5-5: Replace kn·from·"../../../public/locale/kn with ta·from·"../../../public/locale/ta

(prettier/prettier)


[error] 6-6: Replace *·as·hi·from·"../../../public/locale/hi.json with LoginPage·from·"../../pageobject/Login/LoginPage

(prettier/prettier)


27-29: Extract base URL to a constant.

Consider extracting the base URL to a constant for better maintainability.

const BASE_URL = "/";

beforeEach(() => {
  cy.awaitUrl(BASE_URL, true);
  cy.log("Logging in the user devdistrictadmin");
});

69-71: Add detailed logging for language switching test.

The language switching test could benefit from more detailed logging to help with debugging.

it("Switch languages and verify login button text", () => {
  cy.log('Starting language switch test');
  Object.entries(languageMappings).forEach(([lang, _]) => {
    cy.log(`Testing language: ${lang}`);
  });
  loginPage.switchLanguageAndVerifyButtonText(languageMappings);
  cy.log('Completed language switch test');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1156e7 and 091f420.

📒 Files selected for processing (1)
  • cypress/e2e/homepage_spec/redirect.cy.ts (2 hunks)
🧰 Additional context used
🪛 eslint
cypress/e2e/homepage_spec/redirect.cy.ts

[error] 2-2: Replace ta·from·"../../../public/locale/ta with kn·from·"../../../public/locale/kn

(prettier/prettier)


[error] 5-5: Replace kn·from·"../../../public/locale/kn with ta·from·"../../../public/locale/ta

(prettier/prettier)


[error] 6-6: Replace *·as·hi·from·"../../../public/locale/hi.json with LoginPage·from·"../../pageobject/Login/LoginPage

(prettier/prettier)


[error] 12-12: Replace langCode, with ⏎······langCode,⏎·····

(prettier/prettier)


[error] 13-13: Replace ······login:·locale["login"] with ········login:·locale["login"],

(prettier/prettier)


[error] 14-14: Replace ····}]) with ······},⏎····]),

(prettier/prettier)


[error] 20-20: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 21-21: Insert ,

(prettier/prettier)


[error] 55-55: Replace "include",·"https://github.com/ohcnetwork" with ⏎······"include",⏎······"https://github.com/ohcnetwork",⏎····

(prettier/prettier)

🔇 Additional comments (1)
cypress/e2e/homepage_spec/redirect.cy.ts (1)

53-59: Improve GitHub link redirection test robustness.

The test could be more specific in its assertions and should use consistent timeout values.

const NETWORK_TIMEOUT = 10000;

it("Verify redirection of 'Contribute on GitHub' link", () => {
  const expectedUrl = "https://github.com/ohcnetwork";
  loginPage.clickContributeOnGitHub();
  cy.url({ timeout: NETWORK_TIMEOUT }).should("eq", expectedUrl);
  cy.get("body", { timeout: NETWORK_TIMEOUT })
    .should("be.visible")
    .find("h1")  // Be more specific about where to find the text
    .should("contain", "Contribute on GitHub");
});
🧰 Tools
🪛 eslint

[error] 55-55: Replace "include",·"https://github.com/ohcnetwork" with ⏎······"include",⏎······"https://github.com/ohcnetwork",⏎····

(prettier/prettier)

Comment on lines +17 to +22
const languageSidebars = Object.fromEntries(
Object.entries(locales).map(([langCode, locale]) => [
langCode,
{ care: locale["care"], goal: locale["goal"], footer_body: locale["footer_body"] },
])
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for required sidebar items.

Similar to the login text, the sidebar items should be validated to ensure all required translations exist.

interface SidebarType {
  care: string;
  goal: string;
  footer_body: string;
}

const languageSidebars = Object.fromEntries(
  Object.entries(locales).map(([langCode, locale]) => {
    const required = ['care', 'goal', 'footer_body'];
    const missing = required.filter(key => !locale[key]);
    if (missing.length > 0) {
      throw new Error(`Missing translations for language ${langCode}: ${missing.join(', ')}`);
    }
    return [
      langCode,
      {
        care: locale["care"],
        goal: locale["goal"],
        footer_body: locale["footer_body"]
      }
    ];
  })
);
🧰 Tools
🪛 eslint

[error] 20-20: Replace ·care:·locale["care"],·goal:·locale["goal"],·footer_body:·locale["footer_body"] with ⏎········care:·locale["care"],⏎········goal:·locale["goal"],⏎········footer_body:·locale["footer_body"],⏎·····

(prettier/prettier)


[error] 21-21: Insert ,

(prettier/prettier)

Comment on lines +73 to +75
it("Switch languages and verify sidebar items", () => {
loginPage.switchLanguageAndVerifySidebars(languageSidebars);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for sidebar verification.

The sidebar verification test should handle cases where elements might not be immediately visible.

it("Switch languages and verify sidebar items", () => {
  cy.log('Starting sidebar verification');
  loginPage.switchLanguageAndVerifySidebars(languageSidebars)
    .catch((error) => {
      cy.log(`Error during sidebar verification: ${error.message}`);
      throw error;
    });
});

@@ -28,4 +49,28 @@ describe("redirect", () => {
loginPage.ensureLoggedIn();
cy.url().should("include", "/facility");
});

it("Verify redirection of 'Contribute on GitHub' link", () => {
loginPage.clickContributeOnGitHub();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work unless we disable chromeWebSecurity which is only applicable to Chrome anyways, so just verify the link.

cy.get(loginPage.contributeOnGitHubLink)
      .should("have.attr", "href", "https://github.com/ohcnetwork")
      .and("have.attr", "target", "_blank")
      .and("have.attr", "rel", "noopener noreferrer");


switchLanguageAndVerifySidebars(languageMappings: SidebarMapping): void {
Object.entries(languageMappings).forEach(([languageCode, texts]) => {
cy.get(this.languageSelector)
Copy link
Contributor

@Jacobjeevan Jacobjeevan Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So language selector doesn't exist, from this code I assume you are referring to language selector from the profile page, but this test is not being called for a logged in user.

Additionally profile page was just replaced anyways. So you would need add logic for logging in and add the selector Id to the selection dropdown on profile page or rewrite the logic to use the language selection options on the login page.


switchLanguageAndVerifyButtonText(languageMappings: LanguageMapping): void {
Object.entries(languageMappings).forEach(([languageCode, texts]) => {
cy.get(this.languageSelector)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic below suggests you are trying to use language selector on profile page, but here it seems like you are referring to login page 😅

@Jacobjeevan
Copy link
Contributor

Closing as per user's request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add New cypress Test for language selection and link redirection
3 participants