From abf92d181a0037d49c0ee2bc4f5e76b2fe0d15d0 Mon Sep 17 00:00:00 2001 From: Don Xavier Date: Fri, 21 Feb 2025 13:22:44 +0530 Subject: [PATCH 1/2] prescription test to add and remove medicines --- .../patient_spec/patient_prescription.cy.ts | 49 +++++++++++++++++++ .../pageObject/Patients/PatientEncounter.ts | 49 +++++++++++++++++++ .../Medicine/MedicationRequestTable/index.tsx | 1 + .../MedicationRequestQuestion.tsx | 5 +- .../QuestionTypes/NotesInput.tsx | 2 + src/pages/Encounters/EncounterShow.tsx | 1 + 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/patient_spec/patient_prescription.cy.ts diff --git a/cypress/e2e/patient_spec/patient_prescription.cy.ts b/cypress/e2e/patient_spec/patient_prescription.cy.ts new file mode 100644 index 00000000000..3a62ac97360 --- /dev/null +++ b/cypress/e2e/patient_spec/patient_prescription.cy.ts @@ -0,0 +1,49 @@ +import { PatientEncounter } from "@/pageObject/Patients/PatientEncounter"; +import { FacilityCreation } from "@/pageObject/facility/FacilityCreation"; + +const facilityCreation = new FacilityCreation(); +const patientEncounter = new PatientEncounter(); + +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(); + }); +}); diff --git a/cypress/pageObject/Patients/PatientEncounter.ts b/cypress/pageObject/Patients/PatientEncounter.ts index e38abe91b40..5b1403b61e6 100644 --- a/cypress/pageObject/Patients/PatientEncounter.ts +++ b/cypress/pageObject/Patients/PatientEncounter.ts @@ -12,7 +12,56 @@ export class PatientEncounter { .click(); return this; } + clickMedicinesTab() { + cy.verifyAndClickElement('[data-cy="tab-medicines"]', "Medicines"); + return this; + } + clickEditPrescription() { + cy.verifyAndClickElement('[data-cy="edit-prescription"]', "Edit"); + 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(); + cy.contains("Select additional instructions").click(); + cy.get('[role="listbox"]') + .find('[role="option"]') + .contains(instructions) + .click(); + cy.contains("Select route").click(); + cy.get('[role="listbox"]').find('[role="option"]').contains(route).click(); + cy.contains("Select site").click(); + cy.get('[role="listbox"]').find('[role="option"]').contains(site).click(); + cy.contains("Select method").click(); + cy.get('[role="listbox"]').get('[role="option"]').contains(method).click(); + cy.get('[data-cy="notes"]').click(); + cy.get('[data-cy="notes-textarea"]').type(notes); + this.clickSubmitQuestionnaire(); + this.verifyQuestionnaireSubmission(); + return this; + } + removeMedication() { + cy.get('[data-cy="medication-remove"]').first().click(); + cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove"); + this.clickSubmitQuestionnaire(); + this.verifyQuestionnaireSubmission(); + } clickUpdateEncounter() { cy.verifyAndClickElement( '[data-cy="update-encounter-option"]', diff --git a/src/components/Medicine/MedicationRequestTable/index.tsx b/src/components/Medicine/MedicationRequestTable/index.tsx index 2e811025048..891b3f63893 100644 --- a/src/components/Medicine/MedicationRequestTable/index.tsx +++ b/src/components/Medicine/MedicationRequestTable/index.tsx @@ -158,6 +158,7 @@ export default function MedicationRequestTable({ variant="outline" size="sm" className="text-gray-950 hover:text-gray-700 h-9" + data-cy="edit-prescription" > {t("remove")} @@ -317,6 +318,7 @@ export function MedicationRequestQuestion({ medication.status === "entered_in_error" } className="h-8 w-8" + data-cy="medication-remove" > @@ -619,7 +621,7 @@ const MedicationRequestGridRow: React.FC = ({ }} disabled={disabled || isReadOnly} > - + @@ -879,6 +881,7 @@ const MedicationRequestGridRow: React.FC = ({ onClick={onRemove} disabled={disabled} className="h-8 w-8" + data-cy="medication-remove" > diff --git a/src/components/Questionnaire/QuestionTypes/NotesInput.tsx b/src/components/Questionnaire/QuestionTypes/NotesInput.tsx index 5cbec9d3a5a..753f17dd10d 100644 --- a/src/components/Questionnaire/QuestionTypes/NotesInput.tsx +++ b/src/components/Questionnaire/QuestionTypes/NotesInput.tsx @@ -38,6 +38,7 @@ export function NotesInput({ size="sm" className="h-full w-28 text-sm font-normal text-gray-700 hover:text-gray-900" disabled={disabled} + data-cy="notes" > {hasNotes ? (
@@ -54,6 +55,7 @@ export function NotesInput({ className=" border-yellow-200 focus-visible:border-yellow-300 focus-visible:ring-yellow-300" placeholder="Add notes..." disabled={disabled} + data-cy="notes-textarea" /> diff --git a/src/pages/Encounters/EncounterShow.tsx b/src/pages/Encounters/EncounterShow.tsx index 56681f7a483..1d5f7b03026 100644 --- a/src/pages/Encounters/EncounterShow.tsx +++ b/src/pages/Encounters/EncounterShow.tsx @@ -170,6 +170,7 @@ export const EncounterShow = (props: Props) => { {keysOf(tabs).map((tab) => ( From 4434e2d97a6b900f23800278a77664f82c53b32f Mon Sep 17 00:00:00 2001 From: Don Xavier Date: Fri, 7 Mar 2025 23:46:18 +0530 Subject: [PATCH 2/2] Verify necessary actions,use existing command functions --- .../patient_spec/patient_prescription.cy.ts | 39 ++++++--- cypress/fixtures/users.json | 4 + .../pageObject/Patients/PatientEncounter.ts | 82 +++++++++++++------ .../Medicine/MedicationRequestTable/index.tsx | 1 + src/components/Medicine/MedicationsTable.tsx | 5 +- .../MedicationRequestQuestion.tsx | 29 +++++-- 6 files changed, 117 insertions(+), 43 deletions(-) diff --git a/cypress/e2e/patient_spec/patient_prescription.cy.ts b/cypress/e2e/patient_spec/patient_prescription.cy.ts index 3a62ac97360..f27cc0aa2e8 100644 --- a/cypress/e2e/patient_spec/patient_prescription.cy.ts +++ b/cypress/e2e/patient_spec/patient_prescription.cy.ts @@ -6,14 +6,15 @@ const patientEncounter = new PatientEncounter(); describe("Patient Prescription Management", () => { beforeEach(() => { - cy.loginByApi("devnurse"); + cy.loginByApi("testnurse4"); cy.visit("/"); }); it("should add a new medicine for the patient", () => { facilityCreation.selectFacility("GHC payyanur"); - const medicineName = "Senna 15 mg oral tablet"; + const medicineName = "Estriol 1 mg oral tablet"; const dosage = 6; + const dosageInput = "6 Milligram"; const frequency = "BID (1-0-1)"; const instructions = "Until symptoms improve"; const route = "Sublabial route"; @@ -34,16 +35,32 @@ describe("Patient Prescription Management", () => { site, method, notes, - ); - }); - it("should delete prescription", () => { - facilityCreation.selectFacility("GHC payyanur"); - - patientEncounter - .navigateToEncounters() - .openFirstEncounterDetails() + ) + .submitQuestionnaire() .clickMedicinesTab() + .verifyMedication( + medicineName, + dosageInput, + frequency, + instructions, + route, + site, + method, + notes, + ) .clickEditPrescription() - .removeMedication(); + .removeMedication() + .submitQuestionnaire() + .clickMedicinesTab() + .verifyDeletedMedication( + medicineName, + dosageInput, + frequency, + instructions, + route, + site, + method, + notes, + ); }); }); diff --git a/cypress/fixtures/users.json b/cypress/fixtures/users.json index db27e9969f7..739ca18ffd0 100644 --- a/cypress/fixtures/users.json +++ b/cypress/fixtures/users.json @@ -26,5 +26,9 @@ "teststaff4": { "username": "teststaff4", "password": "Test@123" + }, + "testnurse4": { + "username": "testnurse4", + "password": "Test@123" } } diff --git a/cypress/pageObject/Patients/PatientEncounter.ts b/cypress/pageObject/Patients/PatientEncounter.ts index 5b1403b61e6..5699a997b6f 100644 --- a/cypress/pageObject/Patients/PatientEncounter.ts +++ b/cypress/pageObject/Patients/PatientEncounter.ts @@ -30,37 +30,69 @@ export class PatientEncounter { 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(); - cy.contains("Select additional instructions").click(); - cy.get('[role="listbox"]') - .find('[role="option"]') - .contains(instructions) - .click(); - cy.contains("Select route").click(); - cy.get('[role="listbox"]').find('[role="option"]').contains(route).click(); - cy.contains("Select site").click(); - cy.get('[role="listbox"]').find('[role="option"]').contains(site).click(); - cy.contains("Select method").click(); - cy.get('[role="listbox"]').get('[role="option"]').contains(method).click(); + cy.clickAndSelectOption( + '[data-cy="question-medication-request"]', + medicineName, + ); + cy.get('[data-cy="dosage"]').click().type(dosage); + cy.clickAndSelectOption('[data-cy="dosage"]', dosage); + cy.clickAndSelectOption('[data-cy="frequency"]', frequency); + cy.clickAndSelectOption('[data-cy="instructions"]', instructions); + cy.clickAndSelectOption('[data-cy="route"]', route); + cy.clickAndSelectOption('[data-cy="site"]', site); + cy.clickAndSelectOption('[data-cy="method"]', method); cy.get('[data-cy="notes"]').click(); cy.get('[data-cy="notes-textarea"]').type(notes); - - this.clickSubmitQuestionnaire(); - this.verifyQuestionnaireSubmission(); + 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"); + }); return this; } removeMedication() { - cy.get('[data-cy="medication-remove"]').first().click(); + cy.get('[data-cy="remove-medication"]').first().click(); cy.verifyAndClickElement('[data-cy="confirm-remove-medication"]', "Remove"); - this.clickSubmitQuestionnaire(); - this.verifyQuestionnaireSubmission(); + return this; + } + verifyDeletedMedication( + medicineName, + dosage, + frequency, + instructions, + route, + site, + method, + notes, + ) { + cy.get('[data-cy="toggle-stopped-medications"]').click(); + 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"); + }); } clickUpdateEncounter() { cy.verifyAndClickElement( diff --git a/src/components/Medicine/MedicationRequestTable/index.tsx b/src/components/Medicine/MedicationRequestTable/index.tsx index 40ea54e20b4..d24e721e4fe 100644 --- a/src/components/Medicine/MedicationRequestTable/index.tsx +++ b/src/components/Medicine/MedicationRequestTable/index.tsx @@ -199,6 +199,7 @@ export default function MedicationRequestTable({
setShowStopped(!showStopped)} + data-cy="toggle-stopped-medications" > { } return ( -
+
diff --git a/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx b/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx index 4538a8a6077..56df58c8ff9 100644 --- a/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx @@ -319,6 +319,7 @@ export function MedicationRequestQuestion({ medication.status === "entered_in_error" } className="h-8 w-8" + data-cy="remove-medication" > @@ -515,7 +516,10 @@ const MedicationRequestGridRow: React.FC = ({ {/* Dosage */} -
+
{dosageInstruction?.dose_and_rate?.dose_range ? ( @@ -530,6 +534,7 @@ const MedicationRequestGridRow: React.FC = ({ ) : ( <> { if (!value.value || !value.unit) return; @@ -708,7 +713,10 @@ const MedicationRequestGridRow: React.FC = ({
{/* Instructions */} -
+
@@ -751,11 +759,15 @@ const MedicationRequestGridRow: React.FC = ({ } placeholder={t("select_additional_instructions")} disabled={disabled || isReadOnly} + data-cy="medication-instructions" /> )}
{/* Route */} -
+
= ({ />
{/* Site */} -
+
= ({ />
{/* Method */} -
+
= ({ onClick={onRemove} disabled={disabled} className="h-8 w-8" - data-cy="medication-remove" >