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

Test: Add cypress tests for encounter notes #11154

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

siva222003
Copy link
Contributor

@siva222003 siva222003 commented Mar 8, 2025

Proposed Changes

  • Fixes Create a new cypress test for encounter notes #10388
  • Added test cases to validate thread creation and chat message addition.
  • Added test to verify that messages in one thread are not visible in other threads.
  • Included user interaction tests to ensure multiple users can contribute to the same thread.

Next Steps

  • Confirm that threads and their chats are accessible only within the corresponding patient encounter.
Screencast.from.2025-03-09.04-31-17.webm

@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 in Mobile Devices
  • Completion of QA in Desktop Devices

Summary by CodeRabbit

  • New Features

    • Enhanced the Encounter Notes experience by enabling users to create and manage multiple conversation threads.
  • Enhancements

    • Improved message handling so that contributions remain clearly separated across threads.
    • Refined navigation within patient encounters for a smoother review process.
    • Optimized the sign-out feature for a more consistent and reliable user experience.

@siva222003 siva222003 requested a review from a team as a code owner March 8, 2025 23:03
Copy link
Contributor

coderabbitai bot commented Mar 8, 2025

Walkthrough

This pull request introduces automated Cypress tests for the "Encounter Notes" feature and extends the PatientEncounter page object with new methods for intercepting API calls, managing threads, and sending messages. In addition, several UI components across encounter-related pages and the user dashboard have been updated with data-cy attributes to facilitate reliable, automated testing.

Changes

File(s) Change Summary
cypress/e2e/.../encounter_notes.cy.ts
cypress/pageObject/.../PatientEncounter.ts
Added a new test suite for the Encounter Notes feature and extended the PatientEncounter class with methods for intercepting requests, handling encounter threads, messages, thread switching, and logout.
src/pages/Encounters/.../EncounterList.tsx
src/pages/Encounters/.../EncounterShow.tsx
src/pages/Encounters/.../EncounterNotesTab.tsx
src/pages/UserDashboard.tsx
Introduced data-cy attributes to various UI components for enhanced test selector targeting.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant P as PatientEncounter PageObject
    participant API as Backend API

    T->>P: openEncounterAndSaveId()
    T->>P: openEncounterById(encounterId)
    T->>P: openEncounterNotesTab()
    T->>P: clickNewThreadButton()
    T->>P: typeThreadTitle(title)
    T->>P: clickCreateThreadButton()
    T->>P: typeMessage(message)
    T->>P: sendMessage(message)
    P->>API: POST /api/v1/patient/*/thread/*/note/
    API-->>P: 200 OK
    T->>P: verifyMessagesInChat(messages)
Loading

Possibly related PRs

Suggested labels

tested, reviewed

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a rabbit with a hop and a test,
Coding threads and messages at my best.
New features sprout, like carrots they grow,
In PatientEncounter, the functions now flow.
UI tags shine bright with a data-cy glow,
Celebrating changes with a joyful "let's go!"
🐇💻 Happy coding, with each jump we show!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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 Mar 8, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit d72efcf
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ccccac1fe58700082c46ab
😎 Deploy Preview https://deploy-preview-11154.preview.ohc.network
📱 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 (1)
cypress/pageObject/Patients/PatientEncounter.ts (1)

2-2: Potentially unused property.

private routes = {}; is currently empty. If not intended for future use or extension, consider removing it to avoid confusion.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8932e4 and d72efcf.

📒 Files selected for processing (6)
  • cypress/e2e/patient_spec/encounter_notes.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientEncounter.ts (2 hunks)
  • src/pages/Encounters/EncounterList.tsx (1 hunks)
  • src/pages/Encounters/EncounterShow.tsx (1 hunks)
  • src/pages/Encounters/tabs/EncounterNotesTab.tsx (7 hunks)
  • src/pages/UserDashboard.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (29)
src/pages/UserDashboard.tsx (1)

78-87: Good addition of test selector for sign-out button.

Adding the data-cy attribute to the sign-out button enhances testability and aligns with the PR objectives of improving test coverage for user interactions.

src/pages/Encounters/EncounterList.tsx (1)

694-697: Well implemented test selector for encounter cards.

The dynamic data-cy attribute with the encounter ID provides a reliable way to target specific encounter cards in automated tests, which is essential for the encounter notes test scenarios.

src/pages/Encounters/EncounterShow.tsx (1)

172-177: Good addition of test selectors for encounter tabs.

The dynamic data-cy attribute for tabs makes it straightforward to target specific tabs in automated tests, particularly useful for navigating to the notes tab in the test scenarios.

cypress/e2e/patient_spec/encounter_notes.cy.ts (5)

1-7: Well structured test file with proper imports and page object initialization.

The imports and page object instantiations follow good practices for maintainable test code.


8-28: Comprehensive test data setup with realistic scenarios.

The test data is well-structured with unique thread titles (using timestamps) and a variety of message types, including longer text to test multi-line handling. This provides good coverage for real-world usage patterns.


30-38: Proper test setup with environment configuration.

The beforeEach hook appropriately sets up the environment for each test with viewport configuration, login, and facility selection.


39-68: Well-structured first test case for thread creation and message isolation.

This test case effectively validates the core functionality of creating multiple threads and ensuring messages stay within their respective threads. The fluent API pattern with chained methods improves readability and maintainability.


70-94: Good test for multi-user interaction with threads.

This test case verifies that different user roles can access and contribute to existing threads, which is crucial for collaborative functionality. The verification of the encounter ID ensures test continuity between the two test cases.

src/pages/Encounters/tabs/EncounterNotesTab.tsx (7)

103-103: Consistent Cypress locator for thread selection.

This newly added data-cy="thread-title" attribute follows a clear naming pattern, aligning well with your existing Cypress locators.


255-255: Good addition for targeted testing.

The data-cy="new-thread-title-input" attribute provides a reliable hook for end-to-end testing, ensuring an unambiguous way to locate the field.


268-268: Creates clear separation of responsibilities.

Marking the create thread trigger with data-cy="create-thread-button" helps your tests differentiate it from other buttons in the dialog.


486-486: Clear CTA locator for new thread creation.

The data-cy="new-thread-button" attribute is consistent with your established naming scheme, facilitating script-driven UI actions.


621-624: Useful chat identification.

Adding data-cy="chat-messages" to the container simplifies message verification in Cypress, preventing false positives when searching for text in other areas.


676-677: Explicit locator for the chat input.

The data-cy="encounter-notes-chat-message-input" attribute ensures clarity when referencing this input field in tests, reducing risk of collisions with other textareas.


687-687: Concise button locator for message submission.

The data-cy="send-chat-message-button" locator is clear and aids in reliably triggering the send message flow during automated tests.

cypress/pageObject/Patients/PatientEncounter.ts (14)

92-93: Informative section comment.

Keeping a high-level comment block like /*** ENCOUNTER_NOTES ***/ can help maintain structure, especially in files with multiple functionalities.


94-98: Effective request interception.

Utilizing intercept("POST", "/api/v1/patient/*/thread/*/note/") is a solid approach for validating new chat messages in a targeted manner during tests.


100-114: Smart technique for encounter ID retrieval.

Storing the ID in Cypress.env("encounterId") ensures reusability across tests and fosters more flexible scenarios.


116-126: Direct encounter selection by ID.

Selecting the card via [data-cy="encounter-card-${encounterId}"] is a straightforward approach to handle multiple encounters in test workflows.


128-132: Notes tab navigation aligns with naming.

openEncounterNotesTab() is self-explanatory and leverages data-cy for reliability, which is consistent with the rest of the suite.


134-137: Easily recognizable "New" thread action.

The method name clickNewThreadButton() is intuitive and reused effectively for consistent end-to-end tests.


139-142: Straightforward thread title input.

typeThreadTitle provides a readable abstraction for setting the thread's name, keeping your test steps concise.


144-151: Clear button click with verification.

clickCreateThreadButton ensures both visibility and clickable readiness, reducing flaky tests.


153-164: Message sending flow with response verification.

Validating a 200 status code confirms success, but consider handling non-200 success codes (e.g., 201) if the API can return them.

Do you expect strictly 200 responses, or might other 2xx codes be returned?


165-173: Batch messages for thorough test coverage.

addNewChatMessages elegantly encapsulates multiple message creation in a single flow.


175-178: Verifying expected chat contents.

verifyMessagesInChat uses cy.verifyContentPresence effectively, helping isolate any mismatches or missing messages early.


180-185: Ensures message integrity across threads.

verifyMessagesNotExistInChat helps confirm a message does not appear where it shouldn't, fortifying your concurrency and isolation tests.


187-194: Straightforward thread switching.

changeThread fosters readability in tests that involve multiple discussion threads in the same encounter.


196-201: Covers sign-out scenarios.

Including a logout() method ensures your test suite can gracefully reset the test state without manually repeating sign-out steps.

@siva222003
Copy link
Contributor Author

siva222003 commented Mar 8, 2025

@nihal467
Could you please review this PR and let me know if any changes are needed? As mentioned in the EOD call, I haven’t added the test for Confirm that threads and their chats are accessible only within the corresponding patient encounter and have left it for future work.

@github-actions github-actions bot added needs-triage question Further information is requested labels Mar 8, 2025
@siva222003 siva222003 changed the title Issues/10388/cypress test encounter notes Test: Add cypress tests for encounter notes Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a new cypress test for encounter notes
1 participant