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

Add Test Suit for Sidebar Icon and Text Visibility #9588

Conversation

JavidSumra
Copy link
Contributor

@JavidSumra JavidSumra commented Dec 27, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update [product documentation](https://docs.ohc.network).
  • 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

    • Enhanced sidebar navigation with new icons and text visibility features.
    • Added functionality to toggle sidebar visibility and verify icon and text display.
  • Bug Fixes

    • Improved accessibility for testing with new data-testid attributes on sidebar components.
  • Tests

    • Introduced new test cases to verify sidebar functionality and visibility of elements during toggling actions.

@JavidSumra JavidSumra requested a review from a team as a code owner December 27, 2024 08:21
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

This pull request focuses on enhancing the Cypress testing for the facility homepage, specifically by adding sidebar functionality tests. The changes introduce a new constant NavItems and a test case in FacilityHomepage.cy.ts to validate the sidebar behavior during expansion and collapse. Additionally, new methods are added to the FacilityHome page object to verify sidebar interactions, including toggling and visibility checks. data-testid attributes are also added to sidebar components to improve testability.

Changes

File Change Summary
cypress/e2e/facility_spec/FacilityHomepage.cy.ts Added NavItems constant and new test case for sidebar functionality
cypress/pageobject/Facility/FacilityHome.ts Added new methods: verifyIconVisibility(), verifyTextVisibility(), toggleSideBar() and sidebar_toggle property
src/components/Common/Sidebar/Sidebar.tsx Added data-testid to sidebar toggle button
src/components/Common/Sidebar/SidebarItem.tsx Added dynamic data-testid to sidebar text span

Assessment against linked issues

Objective Addressed Explanation
Add sidebar collapse test
Verify sidebar icons and text visibility
Refactor facility export test Export test refactoring not clearly visible in this PR

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • nihal467
  • khavinshankar
  • rithviknishad

Poem

🐰 A sidebar's dance, expand and fold,
Icons and text, a story untold.
Cypress tests with precision and might,
Revealing UI's hidden delight!
Testing magic, rabbit's keen sight. 🕵️‍♀️

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 Dec 27, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 205f1ce
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/676e639885440e0008726a1c
😎 Deploy Preview https://deploy-preview-9588--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

netlify bot commented Dec 27, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 09cfa2c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/676e6dc148b58f0008f5a777
😎 Deploy Preview https://deploy-preview-9588--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: 0

🧹 Nitpick comments (3)
src/components/Common/Sidebar/SidebarItem.tsx (1)

70-70: Consider sanitizing props.text or using a slug if it contains special characters.
While this approach is perfectly valid for simple labels, if props.text includes spaces, punctuation, or special characters, it can lead to awkward data-testid attributes. Either replace spaces with a “-” or sanitize the string to ensure stable test IDs.

cypress/pageobject/Facility/FacilityHome.ts (2)

4-4: Use a more descriptive naming convention for the selector.
Although sidebar_toggle is clear, consider a more descriptive naming if this element is specific to toggling shrink/expansion, such as sidebarToggleShrink or similar. This can help maintain clarity in larger projects.


7-9: Correct the function name spelling.
The method name verifyIconVisiblity appears to contain a spelling error (“Visiblity”). Changing it to verifyIconVisibility would improve readability and consistency.

-  verifyIconVisiblity(iconClassName: string) {
+  verifyIconVisibility(iconClassName: string) {
     cy.get(`.${iconClassName}`).should("be.visible").should("exist");
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 37dce64 and b19bea1.

📒 Files selected for processing (4)
  • cypress/e2e/facility_spec/FacilityHomepage.cy.ts (2 hunks)
  • cypress/pageobject/Facility/FacilityHome.ts (1 hunks)
  • src/components/Common/Sidebar/Sidebar.tsx (1 hunks)
  • src/components/Common/Sidebar/SidebarItem.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/components/Common/Sidebar/Sidebar.tsx
🔇 Additional comments (4)
cypress/pageobject/Facility/FacilityHome.ts (2)

11-23: Validate text matching behavior in verifyTextVisibility.
Currently, the method checks for an exact text match with expectedText. This works well if you want precise matching, but be aware that i18n dynamic text or trailing spaces can cause false negatives. Consider partial matches or a different approach if your text might change slightly (e.g., adding punctuation).


25-29: Good approach for toggling.
This method succinctly ensures the toggle element is visible before clicking, which helps avoid flaky tests. No issues spotted here.

cypress/e2e/facility_spec/FacilityHomepage.cy.ts (2)

35-44: NavItems array structure looks good.
Enumerating the text and icon pair in a central list is a nice pattern, maintaining clarity and facilitating updates.


58-76: Well-structured test scenario for the sidebar toggle.
The test thoroughly ensures icons and labels are correctly shown or hidden when toggling. The usage of verifyIconVisiblity and verifyTextVisibility is clear and consistent. Great coverage!

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

🧹 Nitpick comments (3)
cypress/pageobject/Facility/FacilityHome.ts (3)

4-4: Consider maintaining consistent selector patterns

The sidebar_toggle selector uses a data-testid value directly, while other selectors in the class use CSS/ID selectors (e.g., exportButton = "#export-button"). Consider updating for consistency:

-  sidebar_toggle = "sidebar-toggle";
+  sidebar_toggle = "[data-testid='sidebar-toggle']";

This would also eliminate the need to wrap the selector in data-testid attribute syntax in the toggleSideBar method.


25-29: Consider handling UI transitions

The toggle method should account for potential UI transitions or animations that might affect the sidebar's interactivity.

   toggleSideBar() {
     cy.get(`[data-testid="${this.sidebar_toggle}"]`)
       .should("be.visible")
+      .should("not.be.disabled")
+      .should("have.css", "pointer-events", "auto")
       .click();
+    // Wait for any transitions to complete
+    cy.wait(500); // Adjust based on your transition duration
   }

4-29: Comprehensive test coverage for sidebar functionality

The implementation provides good coverage for testing sidebar behavior, including icon visibility, text visibility, and toggle functionality. The page object pattern is well-maintained, making the tests readable and maintainable.

Consider adding the following test scenarios to ensure complete coverage:

  1. Test for proper aria attributes during sidebar state changes
  2. Verify sidebar state persistence across page reloads
  3. Test keyboard navigation accessibility

Would you like me to provide example test cases for these additional scenarios?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b19bea1 and 09cfa2c.

📒 Files selected for processing (3)
  • cypress/e2e/facility_spec/FacilityHomepage.cy.ts (2 hunks)
  • cypress/pageobject/Facility/FacilityHome.ts (1 hunks)
  • src/components/Common/Sidebar/SidebarItem.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Common/Sidebar/SidebarItem.tsx
  • cypress/e2e/facility_spec/FacilityHomepage.cy.ts

cypress/pageobject/Facility/FacilityHome.ts Show resolved Hide resolved
cypress/pageobject/Facility/FacilityHome.ts Show resolved Hide resolved
@JavidSumra
Copy link
Contributor Author

@nihal467 needs your review

@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Dec 28, 2024

We just migrated to Shadcn's sidebar on form-field-v1 earlier today so this will probably need additional tweaks. Hold for now till that branch is merged.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Dec 31, 2024
Copy link

👋 Hi, @JavidSumra,
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.

@Jacobjeevan
Copy link
Contributor

No longer relevant, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hold merge conflict pull requests with merge conflict
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor the Facility Export existing cypress test and Add New Sidebar collapse test along with it
2 participants