From f2a192b34cee4733a8eec4cb8d7836de1085b8d7 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:20:14 +0530 Subject: [PATCH] New Cypress Test | Bulk Administration of Medicine | Prescription Module (#7978) * bulk administration partial * fix flaky interception --- .../patient_spec/patient_prescription.cy.ts | 49 ++++++++++++++++--- .../pageobject/Patient/PatientPrescription.ts | 29 ++++++++--- .../Medicine/MedicineAdministration.tsx | 6 ++- .../BulkAdminister.tsx | 1 + 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/cypress/e2e/patient_spec/patient_prescription.cy.ts b/cypress/e2e/patient_spec/patient_prescription.cy.ts index d9a7bf7a080..6bb3fc82f37 100644 --- a/cypress/e2e/patient_spec/patient_prescription.cy.ts +++ b/cypress/e2e/patient_spec/patient_prescription.cy.ts @@ -1,3 +1,4 @@ +import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress"; import PatientPrescription from "../../pageobject/Patient/PatientPrescription"; import LoginPage from "../../pageobject/Login/LoginPage"; import { PatientPage } from "../../pageobject/Patient/PatientCreation"; @@ -5,11 +6,13 @@ import { PatientPage } from "../../pageobject/Patient/PatientCreation"; const patientPrescription = new PatientPrescription(); const loginPage = new LoginPage(); const patientPage = new PatientPage(); -const medicineName = "DOLO"; +const medicineNameOne = "DOLO"; +const medicineNameTwo = "FDEP PLUS"; const medicineBaseDosage = "4"; const medicineTargetDosage = "9"; const medicineFrequency = "Twice daily"; const medicineAdministerNote = "Medicine Administration Note"; +const medicineIndicator = "Test Indicator"; describe("Patient Medicine Administration", () => { before(() => { @@ -23,6 +26,40 @@ describe("Patient Medicine Administration", () => { cy.awaitUrl("/patients"); }); + it("Add a PRN Prescription medicine | Group Administrate it |", () => { + patientPage.visitPatient("Dummy Patient 6"); + patientPrescription.visitMedicineTab(); + patientPrescription.visitEditPrescription(); + // Add First Medicine + patientPrescription.clickAddPrnPrescriptionButton(); + patientPrescription.interceptMedibase(); + patientPrescription.selectMedicinebox(); + patientPrescription.selectMedicine(medicineNameOne); + patientPrescription.enterDosage(medicineBaseDosage); + patientPrescription.enterIndicator(medicineIndicator); + cy.submitButton("Submit"); + cy.verifyNotification("Medicine prescribed"); + cy.closeNotification(); + // Add Second Medicine + patientPrescription.clickAddPrnPrescriptionButton(); + patientPrescription.interceptMedibase(); + patientPrescription.selectMedicinebox(); + patientPrescription.selectMedicine(medicineNameTwo); + patientPrescription.enterDosage(medicineBaseDosage); + patientPrescription.enterIndicator(medicineIndicator); + cy.submitButton("Submit"); + cy.verifyNotification("Medicine prescribed"); + cy.closeNotification(); + patientPrescription.clickReturnToDashboard(); + // Group Administer the PRN Medicine + patientPrescription.visitMedicineTab(); + patientPrescription.clickAdministerBulkMedicine(); + patientPrescription.clickAllVisibleAdministration(); + patientPrescription.clickAdministerSelectedMedicine(); + cy.verifyNotification("Medicine(s) administered"); + cy.closeNotification(); + }); + it("Add a new titrated medicine for a patient | Individual Administeration |", () => { patientPage.visitPatient("Dummy Patient 5"); patientPrescription.visitMedicineTab(); @@ -30,7 +67,7 @@ describe("Patient Medicine Administration", () => { patientPrescription.clickAddPrescription(); patientPrescription.interceptMedibase(); patientPrescription.selectMedicinebox(); - patientPrescription.selectMedicine(medicineName); + patientPrescription.selectMedicine(medicineNameOne); patientPrescription.clickTitratedDosage(); patientPrescription.enterDosage(medicineBaseDosage); patientPrescription.enterTargetDosage(medicineTargetDosage); @@ -47,14 +84,14 @@ describe("Patient Medicine Administration", () => { cy.closeNotification(); // Verify the Reflection on the Medicine cy.verifyContentPresence("#medicine-preview", [ - medicineName, + medicineNameOne, medicineBaseDosage, medicineTargetDosage, ]); patientPrescription.clickReturnToDashboard(); // Go to medicine tab and administer it again patientPrescription.visitMedicineTab(); - cy.verifyAndClickElement("#0", medicineName); + cy.verifyAndClickElement("#0", medicineNameOne); cy.submitButton("Administer"); patientPrescription.enterAdministerDosage(medicineBaseDosage); cy.submitButton("Administer Medicine"); @@ -68,7 +105,7 @@ describe("Patient Medicine Administration", () => { patientPrescription.clickAddPrescription(); patientPrescription.interceptMedibase(); patientPrescription.selectMedicinebox(); - patientPrescription.selectMedicine(medicineName); + patientPrescription.selectMedicine(medicineNameOne); patientPrescription.enterDosage(medicineBaseDosage); patientPrescription.selectDosageFrequency(medicineFrequency); cy.submitButton("Submit"); @@ -78,7 +115,7 @@ describe("Patient Medicine Administration", () => { patientPrescription.clickAddPrescription(); patientPrescription.interceptMedibase(); patientPrescription.selectMedicinebox(); - patientPrescription.selectMedicine(medicineName); + patientPrescription.selectMedicine(medicineNameOne); patientPrescription.enterDosage(medicineBaseDosage); patientPrescription.selectDosageFrequency(medicineFrequency); cy.submitButton("Submit"); diff --git a/cypress/pageobject/Patient/PatientPrescription.ts b/cypress/pageobject/Patient/PatientPrescription.ts index a4b92b0a5fa..50f072f1d9b 100644 --- a/cypress/pageobject/Patient/PatientPrescription.ts +++ b/cypress/pageobject/Patient/PatientPrescription.ts @@ -1,3 +1,4 @@ +import { cy } from "local-cypress"; export class PatientPrescription { clickAddPrescription() { cy.get("#add-prescription").scrollIntoView(); @@ -7,6 +8,10 @@ export class PatientPrescription { ); } + clickAddPrnPrescriptionButton() { + cy.contains("button", "Add PRN Prescription").click(); + } + interceptMedibase() { cy.intercept("GET", "**/api/v1/medibase/**").as("getMedibase"); } @@ -27,6 +32,15 @@ export class PatientPrescription { cy.verifyAndClickElement("#administer-medicine", "Administer"); } + clickAdministerBulkMedicine() { + cy.get("#bulk-administer").should("be.visible"); + cy.get("#bulk-administer").click(); + } + + clickAllVisibleAdministration() { + cy.get("#should_administer").should("be.visible").click(); + } + selectMedicinebox() { cy.get( "div#medicine_object input[placeholder='Select'][role='combobox']", @@ -41,6 +55,10 @@ export class PatientPrescription { cy.get("#base_dosage").type(doseAmount, { force: true }); } + enterIndicator(indicator: string) { + cy.get("#indicator").type(indicator); + } + enterAdministerDosage(dosage: string) { cy.get("#dosage").type(dosage); } @@ -64,14 +82,9 @@ export class PatientPrescription { ); } - discontinuePreviousPrescription() { - cy.intercept( - "POST", - "**/api/v1/consultation/*/prescriptions/*/discontinue/", - ).as("deletePrescription"); - cy.get("button").contains("Discontinue").click(); - cy.get("#submit").contains("Discontinue").click(); - cy.wait("@deletePrescription").its("response.statusCode").should("eq", 200); + clickAdministerSelectedMedicine() { + cy.get("#administer-selected-medicine").should("be.visible"); + cy.get("#administer-selected-medicine").click(); } visitMedicineTab() { diff --git a/src/Components/Medicine/MedicineAdministration.tsx b/src/Components/Medicine/MedicineAdministration.tsx index d495ed162bc..650f720caa0 100644 --- a/src/Components/Medicine/MedicineAdministration.tsx +++ b/src/Components/Medicine/MedicineAdministration.tsx @@ -223,7 +223,11 @@ export default function MedicineAdministration(props: Props) { ))}
- + {t("administer_selected_medicines")}{" "} {selectedCount > 0 && `(${selectedCount})`} diff --git a/src/Components/Medicine/MedicineAdministrationSheet/BulkAdminister.tsx b/src/Components/Medicine/MedicineAdministrationSheet/BulkAdminister.tsx index abd609871c8..f4111f24eb0 100644 --- a/src/Components/Medicine/MedicineAdministrationSheet/BulkAdminister.tsx +++ b/src/Components/Medicine/MedicineAdministrationSheet/BulkAdminister.tsx @@ -18,6 +18,7 @@ export default function BulkAdminister({ prescriptions, onDone }: Props) { return ( <> setShowBulkAdminister(true)}