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

New cypress test for assigning a user to patient #10394

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

nihal467
Copy link
Member

@nihal467 nihal467 commented Feb 4, 2025

Proposed Changes

  • Fixes #issue_number
  • Change 1
  • Change 2
  • 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
    • Enhanced patient management workflows that streamline the process of assigning and removing care providers.
    • Improved verification of patient encounter details for a more seamless user experience.

@nihal467 nihal467 requested a review from a team as a code owner February 4, 2025 15:28
Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

This pull request modifies the Cypress tests for patient management. In the patient creation tests, calls to patientDashboard.verifyEncounterPatientInfo have been replaced with patientEncounter.verifyEncounterPatientInfo. A new test suite for patient management is added, focusing on assigning users to patients. In addition, the PatientDashboard page object is removed, a new PatientDetails class is introduced, and the PatientEncounter page object is updated with the new verification method. Several React component files have been updated with data-cy attributes to improve testability.

Changes

File(s) Change Summary
cypress/e2e/patient_spec/patient_creation.cy.ts and cypress/e2e/patient_spec/patient_details.cy.ts Updated patient creation tests to call patientEncounter.verifyEncounterPatientInfo instead of patientDashboard.verifyEncounterPatientInfo; added a new test suite for user assignment.
cypress/pageObject/Patients/PatientDashboard.ts, cypress/pageObject/Patients/PatientDetails.ts, and cypress/pageObject/Patients/PatientEncounter.ts Removed the PatientDashboard class; introduced the PatientDetails class; and added the verifyEncounterPatientInfo method to the PatientEncounter class for verifying encounter information.
src/components/Patient/PatientDetailsTab/PatientUsers.tsx and src/components/Patient/PatientHome.tsx Added data-cy attributes to key elements to improve component testability, including buttons and link tabs.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Patient Creation Test
    participant PE as PatientEncounter Page Object
    participant cy as Cypress
    
    Test->>PE: verifyEncounterPatientInfo(expectedInfo)
    PE->>cy: cy.verifyContentPresence('#patient-infobadges', expectedInfo)
    cy-->>PE: Return verification result
    PE-->>Test: Return instance for chaining
Loading
sequenceDiagram
    participant Test as Patient Assignment Test
    participant PD as PatientDetails Page Object
    
    Test->>PD: clickUsersTab()
    Test->>PD: clickAssignUserButton()
    Test->>PD: selectUserToAssign("nihal-nurse")
    Test->>PD: selectUserRole("Nurse")
    Test->>PD: confirmUserAssignment()
    Test->>PD: verifyUserAssignmentSuccess()
    Test->>PD: clickRemoveUserButton()
    Test->>PD: confirmUserRemoval()
    Test->>PD: verifyUserRemovalSuccess()
Loading

Possibly related issues

Possibly related PRs

Suggested labels

tested, needs review

Suggested reviewers

  • rithviknishad

Poem

I'm a little rabbit, hopping with code delight,
Testing patient flows from morning till night.
Encounters verified and users assigned with care,
My carrot-fueled energy fills the testing air.
With new features in place, I bounce to debug and cheer!
Happy coding from the burrow, stay sharp and clear!
🥕🐰

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 Feb 4, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 482c64d
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67a232050643d6000866f8fb
😎 Deploy Preview https://deploy-preview-10394--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 (6)
cypress/e2e/patient_spec/patient_details.cy.ts (2)

16-17: Extract user details as test data constants.

Move the hardcoded user details to constants at the top of the file or to a test data file for better maintainability.

+const TEST_USER = {
+  username: "nihal-nurse",
+  role: "Nurse",
+};
+
 describe("Patient Management", () => {
   beforeEach(() => {
     cy.loginByApi("doctor");
     cy.visit("/");
   });

   it("Assign users to a patient", () => {
-    const userName = "nihal-nurse";
-    const userRole = "Nurse";
+    const { username, role } = TEST_USER;

18-18: Extract facility name as a test data constant.

Move the hardcoded facility name to a constant at the top of the file or to a test data file for better maintainability.

+const TEST_FACILITY = "GHC Trikaripur";
+
 describe("Patient Management", () => {
   beforeEach(() => {
     cy.loginByApi("doctor");
     cy.visit("/");
   });

   it("Assign users to a patient", () => {
-    facilityCreation.selectFacility("GHC Trikaripur");
+    facilityCreation.selectFacility(TEST_FACILITY);
cypress/pageObject/Patients/PatientDetails.ts (1)

39-42: Use consistent click operation pattern.

The clickRemoveUserButton method uses a different pattern for clicking compared to other methods. For consistency, use the verifyAndClickElement custom command.

   clickRemoveUserButton() {
-    cy.get('[data-cy="patient-user-remove-button"]').first().click();
+    cy.verifyAndClickElement(
+      '[data-cy="patient-user-remove-button"]',
+      "Remove User",
+    );
     return this;
   }
cypress/pageObject/Patients/PatientEncounter.ts (1)

25-28: Use data-cy attribute for patient info badges selector.

Replace the hardcoded ID selector with a data-cy attribute for consistency with other selectors in the codebase.

   verifyEncounterPatientInfo(contents: string[]) {
-    cy.verifyContentPresence("#patient-infobadges", contents);
+    cy.verifyContentPresence('[data-cy="patient-info-badges"]', contents);
     return this;
   }
cypress/e2e/patient_spec/patient_creation.cy.ts (2)

17-19: Extract encounter constants to a test data file.

Move the hardcoded encounter constants to a separate test data file for better maintainability and reusability across test files.

+// testData/encounterData.ts
+export const ENCOUNTER_DATA = {
+  TYPE: "Observation",
+  STATUS: "In Progress",
+  PRIORITY: "ASAP",
+};
+
-const ENCOUNTER_TYPE = "Observation";
-const ENCOUNTER_STATUS = "In Progress";
-const ENCOUNTER_PRIORITY = "ASAP";
+const { TYPE: ENCOUNTER_TYPE, STATUS: ENCOUNTER_STATUS, PRIORITY: ENCOUNTER_PRIORITY } = ENCOUNTER_DATA;

184-188: Use data-cy attribute for general info selector.

Replace the hardcoded ID selector with a data-cy attribute for consistency with other selectors in the codebase.

-    cy.verifyContentPresence("#general-info", [
+    cy.verifyContentPresence('[data-cy="general-info"]', [
       updatedPatientData.gender,
       updatedPatientData.address,
     ]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 879c583 and 482c64d.

📒 Files selected for processing (7)
  • cypress/e2e/patient_spec/patient_creation.cy.ts (2 hunks)
  • cypress/e2e/patient_spec/patient_details.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientDashboard.ts (0 hunks)
  • cypress/pageObject/Patients/PatientDetails.ts (1 hunks)
  • cypress/pageObject/Patients/PatientEncounter.ts (1 hunks)
  • src/components/Patient/PatientDetailsTab/PatientUsers.tsx (7 hunks)
  • src/components/Patient/PatientHome.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • cypress/pageObject/Patients/PatientDashboard.ts
🧰 Additional context used
📓 Learnings (2)
cypress/e2e/patient_spec/patient_creation.cy.ts (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9145
File: cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts:93-94
Timestamp: 2024-11-18T10:48:08.501Z
Learning: In `cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts`, bed capacity verification assertions after patient admission are already being performed elsewhere, so adding them here is unnecessary.
cypress/e2e/patient_spec/patient_details.cy.ts (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9145
File: cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts:93-94
Timestamp: 2024-11-18T10:48:08.501Z
Learning: In `cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts`, bed capacity verification assertions after patient admission are already being performed elsewhere, so adding them here is unnecessary.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
src/components/Patient/PatientHome.tsx (1)

112-112: LGTM! Well-structured test selector.

The dynamic data-cy attribute tab-${tab.route} provides a clear and unique identifier for each tab, making it easily targetable in Cypress tests.

src/components/Patient/PatientDetailsTab/PatientUsers.tsx (2)

106-106: LGTM! Well-structured test selectors for the user assignment flow.

The data-cy attributes follow a clear naming convention and cover the complete user assignment workflow, making it easy to write and maintain Cypress tests.

Also applies to: 117-117, 170-170, 191-191, 315-315


268-272: LGTM! Comprehensive test selectors for the user removal flow.

The separate data-cy attributes for the remove button and confirm button provide clear distinction between the initial trigger and the confirmation action, which is essential for testing multi-step operations.

Also applies to: 288-288

Copy link

cypress bot commented Feb 4, 2025

CARE    Run #4607

Run Properties:  status check passed Passed #4607  •  git commit 482c64d7b9: New cypress test for assigning a user to patient
Project CARE
Branch Review cypress-patientassign
Run status status check passed Passed #4607
Run duration 06m 31s
Commit git commit 482c64d7b9: New cypress test for assigning a user to patient
Committer Mohammed Nihal
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 11
View all changes introduced in this branch ↗︎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review required
Development

Successfully merging this pull request may close these issues.

1 participant