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: Patient Prescription Management #10740

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

Conversation

DonXavierdev
Copy link
Contributor

@DonXavierdev DonXavierdev commented Feb 21, 2025

Proposed Changes

@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

    • Introduced a test suite for managing patient prescriptions, including adding and deleting medications.
  • Improvements

    • Enhanced patient prescription management allowing smoother medication addition and removal during patient encounters.
    • Added attributes for improved testability and accessibility in various components related to medication management.
    • Expanded user dataset with the addition of a new user entry for testing purposes.

@DonXavierdev DonXavierdev requested a review from a team as a code owner February 21, 2025 07:56
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

Walkthrough

This update introduces a new Cypress test suite for patient prescription management along with enhancements to supporting page objects and React components. The test file automates the addition and deletion of a medication using the new methods added to the PatientEncounter class. Additionally, several React components now include new data-cy attributes for robust test targeting. No modifications were made to exported or public entities.

Changes

Files Change Summary
cypress/e2e/patient_spec/patient_prescription.cy.ts
cypress/pageObject/Patients/PatientEncounter.ts
Introduces a new test suite for managing patient prescriptions. Adds test cases for adding and removing medications. New methods clickMedicinesTab(), clickEditPrescription(), addMedication(...), and removeMedication() are implemented in the page object.
src/components/Medicine/MedicationRequestTable/index.tsx
src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx
src/components/Questionnaire/QuestionTypes/NotesInput.tsx
src/pages/Encounters/EncounterShow.tsx
Adds new data-cy attributes (e.g., "edit-prescription", "confirm-remove-medication", "remove-medication", "notes", "notes-textarea", and dynamic tab-{tab}) to various components to enable easier identification for automated tests.
cypress/fixtures/users.json Adds a new user entry for "testnurse4" with specified username and password.
src/components/Medicine/MedicationsTable.tsx Adds a data-cy attribute to the <div> wrapping the Table component for improved test targeting.

Possibly related PRs

Suggested labels

tested, reviewed

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I’m a bunny with a hop and a skip,
Celebrating tests that tighten our grip.
Medications add with a joyful click,
And removals confirmed oh-so slick.
Code carrots abound – now let’s take a nibble!
Hop on board and enjoy this delightful ripple.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 Feb 21, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 4434e2d
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67cb37ff7abba4000884f386
😎 Deploy Preview https://deploy-preview-10740.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: 3

🧹 Nitpick comments (4)
cypress/e2e/patient_spec/patient_prescription.cy.ts (1)

13-38: Consider enhancing test coverage and data management.

While the test successfully verifies adding a medication, consider:

  1. Moving test data to fixtures for better maintainability
  2. Adding validation for the added medication
  3. Testing error scenarios (e.g., invalid inputs)
+import testData from '../../fixtures/medication.json';
+
 it("should add a new medicine for the patient", () => {
   facilityCreation.selectFacility("GHC payyanur");
-  const medicineName = "Senna 15 mg oral tablet";
-  const dosage = 6;
-  const frequency = "BID (1-0-1)";
-  const instructions = "Until symptoms improve";
-  const route = "Sublabial route";
-  const site = "Structure of left deltoid muscle";
-  const method = "Bathe";
-  const notes = "testing notes";
+  const { medicineName, dosage, frequency, instructions, route, site, method, notes } = testData.validMedication;
   patientEncounter
     .navigateToEncounters()
     .openFirstEncounterDetails()
     .clickMedicinesTab()
     .clickEditPrescription()
     .addMedication(
       medicineName,
       dosage,
       frequency,
       instructions,
       route,
       site,
       method,
       notes,
-    );
+    )
+    .verifyMedicationAdded(medicineName);
cypress/pageObject/Patients/PatientEncounter.ts (1)

23-58: Consider breaking down the addMedication method for better maintainability.

The method is quite long and handles multiple responsibilities. Consider splitting it into smaller, more focused methods.

+  private fillMedicationDetails(medicineName: string) {
+    cy.get('[data-cy="question-medication-request"]').click();
+    cy.get('[role="listbox"]')
+      .find('[role="option"]')
+      .contains(medicineName)
+      .click();
+    return this;
+  }
+
+  private fillDosageDetails(dosage: number, frequency: string) {
+    cy.get('input[inputmode="numeric"]').should("exist").type(dosage);
+    cy.get('[data-cy="frequency"]').click();
+    cy.get('[role="option"]').contains(frequency).click();
+    return this;
+  }
+
   addMedication(
     medicineName,
     dosage,
     frequency,
     instructions,
     route,
     site,
     method,
     notes,
   ) {
-    cy.get('[data-cy="question-medication-request"]').click();
-    cy.get('[role="listbox"]')
-      .find('[role="option"]')
-      .contains(medicineName)
-      .click();
-    cy.get('input[inputmode="numeric"]').should("exist").type(dosage);
-    cy.get('[data-cy="frequency"]').click();
-    cy.get('[role="option"]').contains(frequency).click();
+    this.fillMedicationDetails(medicineName)
+        .fillDosageDetails(dosage, frequency);
     // ... rest of the method
src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx (2)

84-376: Consider breaking down the MedicationRequestQuestion component.

The component is quite large and handles multiple responsibilities. Consider splitting it into smaller, more focused components for better maintainability.

+const MedicationList = ({ medications, onUpdate, onRemove }) => {
+  // Extract medication list rendering logic
+};
+
+const MedicationForm = ({ onAdd }) => {
+  // Extract medication form logic
+};
+
 export function MedicationRequestQuestion({
   questionnaireResponse,
   updateQuestionnaireResponseCB,
   disabled,
   patientId,
   encounterId,
 }: MedicationRequestQuestionProps) {
   // ... state and handlers
   
   return (
     <div className="space-y-4">
-      {/* Current implementation */}
+      <MedicationList
+        medications={medications}
+        onUpdate={handleUpdateMedication}
+        onRemove={handleRemoveMedication}
+      />
+      <MedicationForm onAdd={handleAddMedication} />
     </div>
   );
 }

624-624: Consider using a more descriptive data-cy value.

The current data-cy value "frequency" could be more specific to better indicate its purpose.

-  <SelectTrigger className="h-9 text-sm" data-cy="frequency">
+  <SelectTrigger className="h-9 text-sm" data-cy="medication-frequency-select">
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d58936d and abf92d1.

📒 Files selected for processing (6)
  • cypress/e2e/patient_spec/patient_prescription.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientEncounter.ts (1 hunks)
  • src/components/Medicine/MedicationRequestTable/index.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx (4 hunks)
  • src/components/Questionnaire/QuestionTypes/NotesInput.tsx (2 hunks)
  • src/pages/Encounters/EncounterShow.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/components/Medicine/MedicationRequestTable/index.tsx
  • src/components/Questionnaire/QuestionTypes/NotesInput.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (4)
cypress/e2e/patient_spec/patient_prescription.cy.ts (1)

7-11: LGTM! Good test setup.

The beforeEach hook properly sets up the test environment by handling login and navigation.

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

15-22: LGTM! Good use of data-cy attributes.

The methods use data-cy attributes for reliable element selection and follow the builder pattern.

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

173-173: LGTM! Good test attribute addition.

The data-cy attribute addition improves test reliability and follows the established pattern.

src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx (1)

205-205: LGTM! Consistent test attribute implementation.

The data-cy attributes are consistently applied across the component for reliable test selection.

Also applies to: 321-321, 884-884

Comment on lines 7 to 49
describe("Patient Prescription Management", () => {
beforeEach(() => {
cy.loginByApi("devnurse");
cy.visit("/");
});

it("should add a new medicine for the patient", () => {
facilityCreation.selectFacility("GHC payyanur");
const medicineName = "Senna 15 mg oral tablet";
const dosage = 6;
const frequency = "BID (1-0-1)";
const instructions = "Until symptoms improve";
const route = "Sublabial route";
const site = "Structure of left deltoid muscle";
const method = "Bathe";
const notes = "testing notes";
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.addMedication(
medicineName,
dosage,
frequency,
instructions,
route,
site,
method,
notes,
);
});
it("should delete prescription", () => {
facilityCreation.selectFacility("GHC payyanur");

patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication();
});
});
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 more test scenarios for comprehensive coverage.

The test suite should include additional scenarios:

  1. Editing an existing medication
  2. Adding multiple medications
  3. Error handling for invalid inputs
  4. Validation of required fields
it("should edit an existing medication", () => {
  // Add test for editing medication
});

it("should validate required fields", () => {
  // Add test for field validation
});

it("should handle invalid inputs gracefully", () => {
  // Add test for error scenarios
});

Comment on lines 39 to 48
it("should delete prescription", () => {
facilityCreation.selectFacility("GHC payyanur");

patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication();
});
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 medication removal.

The deletion test should verify that the medication was actually removed.

 it("should delete prescription", () => {
   facilityCreation.selectFacility("GHC payyanur");
+  const medicineName = "Senna 15 mg oral tablet";
+  
+  // First add a medication to ensure we have something to delete
+  patientEncounter
+    .navigateToEncounters()
+    .openFirstEncounterDetails()
+    .clickMedicinesTab()
+    .clickEditPrescription()
+    .addMedication(medicineName, 6, "BID (1-0-1)", "", "", "", "", "");
 
   patientEncounter
     .navigateToEncounters()
     .openFirstEncounterDetails()
     .clickMedicinesTab()
     .clickEditPrescription()
-    .removeMedication();
+    .removeMedication()
+    .verifyMedicationRemoved(medicineName);
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("should delete prescription", () => {
facilityCreation.selectFacility("GHC payyanur");
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication();
});
it("should delete prescription", () => {
facilityCreation.selectFacility("GHC payyanur");
const medicineName = "Senna 15 mg oral tablet";
// First add a medication to ensure we have something to delete
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.addMedication(medicineName, 6, "BID (1-0-1)", "", "", "", "", "");
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication()
.verifyMedicationRemoved(medicineName);
});

Comment on lines 59 to 64
removeMedication() {
cy.get('[data-cy="medication-remove"]').first().click();
cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
}
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 verification after medication removal.

The removeMedication method should include verification that the medication was actually removed.

   removeMedication() {
     cy.get('[data-cy="medication-remove"]').first().click();
     cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
     this.clickSubmitQuestionnaire();
     this.verifyQuestionnaireSubmission();
+    // Add verification that medication was removed
+    cy.get('[data-cy="medication-list"]').should('not.contain', this.lastRemovedMedication);
+    return this;
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
removeMedication() {
cy.get('[data-cy="medication-remove"]').first().click();
cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
}
removeMedication() {
cy.get('[data-cy="medication-remove"]').first().click();
cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove");
this.clickSubmitQuestionnaire();
this.verifyQuestionnaireSubmission();
// Add verification that medication was removed
cy.get('[data-cy="medication-list"]').should('not.contain', this.lastRemovedMedication);
return this;
}

@nihal467
Copy link
Member

@DonXavierdev is it ready for review ?

@nihal467 nihal467 added the question Further information is requested label Feb 27, 2025
@DonXavierdev
Copy link
Contributor Author

DonXavierdev commented Feb 27, 2025

@DonXavierdev is it ready for review ?

@nihal467 Yes i want to know the changes required in this to further implement this

@amjithtitus09 amjithtitus09 added needs testing and removed question Further information is requested labels Feb 28, 2025
@rithviknishad rithviknishad requested a review from nihal467 March 1, 2025 13:06

describe("Patient Prescription Management", () => {
beforeEach(() => {
cy.loginByApi("devnurse");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cy.loginByApi("devnurse");
cy.loginByApi("devnurse");
  • create a new user and update it in fixtures then use that id here

route,
site,
method,
notes,
Copy link
Member

@nihal467 nihal467 Mar 4, 2025

Choose a reason for hiding this comment

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

Suggested change
notes,
notes,
  • verify that the added medicine is reflected properly in the medicine module,
  • Verify the success notification and API request

notes,
);
});
it("should delete prescription", () => {
Copy link
Member

Choose a reason for hiding this comment

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

  • don't create a separate test, combine this with the above test itself

.openFirstEncounterDetails()
.clickMedicinesTab()
.clickEditPrescription()
.removeMedication();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.removeMedication();
.removeMedication();

once the medicine is removed, verify that the changes in the relevant module is verified

notes,
) {
cy.get('[data-cy="question-medication-request"]').click();
cy.get('[role="listbox"]')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cy.get('[role="listbox"]')
cy.get('[role="listbox"]')

check already existing command function to interact with dropdown, replace every usage with command function

.find('[role="option"]')
.contains(medicineName)
.click();
cy.get('input[inputmode="numeric"]').should("exist").type(dosage);
Copy link
Member

Choose a reason for hiding this comment

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

  • use proper id
  • use existing command function for this

@nihal467 nihal467 removed their assignment Mar 4, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Mar 6, 2025
Copy link

github-actions bot commented Mar 6, 2025

Conflicts have been detected against the base branch. Please merge the base branch into your branch.
cc: @DonXavierdev

See: https://docs.ohc.network/docs/contributing#how-to-resolve-merge-conflicts

@DonXavierdev
Copy link
Contributor Author

verify that the added medicine is reflected profile in the medicine module,

@nihal467 I dont understand this

@nihal467
Copy link
Member

nihal467 commented Mar 7, 2025

image

@DonXavierdev SORRY FOR THE TYPO MISTAKE. verify that the added medicine is properly visible in the medicine dashboard. for reference attached the screenshot

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Mar 7, 2025
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: 1

🧹 Nitpick comments (2)
cypress/pageObject/Patients/PatientEncounter.ts (2)

23-47: Consider simplifying or verifying typed input
There is a slight redundancy in typing the dosage and then calling clickAndSelectOption on the same selector ([data-cy="dosage"]). If this is intentional (e.g., typing triggers dropdown suggestions), consider clarifying through comments. Otherwise, consolidating these steps could reduce confusion.


75-96: Clarify function naming
The method is named verifyDeletedMedication, but we validate the presence of the medication in the "stopped medications" table. Renaming this function to something like verifyStoppedMedication might reduce 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 e90695b and 4434e2d.

📒 Files selected for processing (6)
  • cypress/e2e/patient_spec/patient_prescription.cy.ts (1 hunks)
  • cypress/fixtures/users.json (1 hunks)
  • cypress/pageObject/Patients/PatientEncounter.ts (1 hunks)
  • src/components/Medicine/MedicationRequestTable/index.tsx (2 hunks)
  • src/components/Medicine/MedicationsTable.tsx (1 hunks)
  • src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx (9 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/components/Medicine/MedicationsTable.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • cypress/e2e/patient_spec/patient_prescription.cy.ts
  • src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx
  • src/components/Medicine/MedicationRequestTable/index.tsx
🔇 Additional comments (4)
cypress/fixtures/users.json (1)

29-33: New Test User Addition: "testnurse4"

The new user entry is formatted consistently with the existing fixture data. The addition of the "testnurse4" user, with a username matching its key and a designated test password, appears appropriate for supporting the new prescription management tests. Please ensure that all test suites that require nurse authentication are updated to include or reference this user as needed. Additionally, verify that these test credentials remain strictly within your testing environment and are never used in production deployments.

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

15-18: Method is succinct and chainable
The clickMedicinesTab method follows a clear naming convention and returns this for chainability, which is consistent with the rest of the class.


19-22: Implementation is consistent
The clickEditPrescription method is aligned with the pattern used elsewhere in this file. It correctly verifies and clicks the edit button, then returns this for continued chaining.


70-74: Add verification after medication removal
This repeats a prior suggestion: confirm that the removed medication no longer appears in the active list or has moved to the "stopped" list. This helps detect potential failures if the UI or request fails.

Comment on lines +48 to +69
verifyMedication(
medicineName,
dosage,
frequency,
instructions,
route,
site,
method,
notes,
) {
cy.get('[data-cy="medications-table"]').within(() => {
cy.contains("td", medicineName).should("exist");
cy.contains("td", dosage).should("exist");
cy.contains("td", frequency).should("exist");
cy.contains("td", instructions).should("exist");
cy.contains("td", route).should("exist");
cy.contains("td", site).should("exist");
cy.contains("td", method).should("exist");
cy.contains("td", notes).should("exist");
});
return this;
}
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

Avoid potential false positives by verifying each medication field on the same row
Currently, verifying each field individually can pass if multiple rows share the same values. To ensure correctness, locate the row containing the medicine name and verify the other details on that row, for instance:

- cy.contains("td", medicineName).should("exist");
- cy.contains("td", dosage).should("exist");
...
+ cy.get('[data-cy="medications-table"]')
+   .contains('tr', medicineName)
+   .should('contain', dosage)
+   .should('contain', frequency)
+   .should('contain', instructions);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
verifyMedication(
medicineName,
dosage,
frequency,
instructions,
route,
site,
method,
notes,
) {
cy.get('[data-cy="medications-table"]').within(() => {
cy.contains("td", medicineName).should("exist");
cy.contains("td", dosage).should("exist");
cy.contains("td", frequency).should("exist");
cy.contains("td", instructions).should("exist");
cy.contains("td", route).should("exist");
cy.contains("td", site).should("exist");
cy.contains("td", method).should("exist");
cy.contains("td", notes).should("exist");
});
return this;
}
verifyMedication(
medicineName,
dosage,
frequency,
instructions,
route,
site,
method,
notes,
) {
- cy.get('[data-cy="medications-table"]').within(() => {
- cy.contains("td", medicineName).should("exist");
- cy.contains("td", dosage).should("exist");
- cy.contains("td", frequency).should("exist");
- cy.contains("td", instructions).should("exist");
- cy.contains("td", route).should("exist");
- cy.contains("td", site).should("exist");
- cy.contains("td", method).should("exist");
- cy.contains("td", notes).should("exist");
- });
+ cy.get('[data-cy="medications-table"]')
+ .contains('tr', medicineName)
+ .should('contain', dosage)
+ .should('contain', frequency)
+ .should('contain', instructions)
+ .should('contain', route)
+ .should('contain', site)
+ .should('contain', method)
+ .should('contain', notes);
return this;
}

@DonXavierdev DonXavierdev requested a review from nihal467 March 7, 2025 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a new cypress test to verify the medicine prescription module
3 participants