From e452bb5e075ec1e4670a848dca0846c94158d458 Mon Sep 17 00:00:00 2001 From: Shivam Jha <86483059+ShivamJhaa@users.noreply.github.com> Date: Fri, 20 Oct 2023 06:38:06 +0530 Subject: [PATCH] Added test of patient_crud.cy.ts (#6135) * Added test for importing and configuring an asset * Revert few changes * nits * Migrated to POM approach * Migrated patient_crud to POM approach * reverted some chnages * FIx * Merge conflicts * Fixed test * Added test for patient_test * nits * add responsiveness to virtual nursing assistant card (#6130) * allow use stock as well (#6115) * fixed responsive issue of 'Update Log' button in patient consultation page (#6113) * fix multiple bed bug (#6111) * Fixed typo in Date format in Asset management (#6105) * Added padding to count block on patients page * fixed date format in asset manage page * show only items with no min value (#6103) * check for id in response (#6100) * Added Responsiveness to File upload (#6096) * add responsiveness * refactor * remove overlap (#6094) * fixed failing test * Fix * Fixed comments * fix comments * Fixed all comments * Migrated test to new test suite * Added upload file test * fixed failing test * Fix failing test * Revert unwanted changes * fixed conflict * random failure fixed * temporary fixed medicine selection --------- Co-authored-by: Pranshu Aggarwal <70687348+Pranshu1902@users.noreply.github.com> Co-authored-by: Gokulram A Co-authored-by: Kshitij Verma <101321276+kshitijv256@users.noreply.github.com> Co-authored-by: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> --- cypress/e2e/patient_spec/patient_crud.cy.ts | 17 +- cypress/e2e/patient_spec/patient_manage.cy.ts | 78 ++++++++++ .../pageobject/Patient/PatientConsultation.ts | 146 +++++++++++++++++- cypress/pageobject/Patient/PatientCreation.ts | 6 + src/Components/Facility/ConsultationCard.tsx | 1 + .../Facility/ConsultationDetails/index.tsx | 8 +- src/Components/Patient/FileUpload.tsx | 2 + src/Components/Patient/PatientNotes.tsx | 2 + 8 files changed, 256 insertions(+), 4 deletions(-) create mode 100644 cypress/e2e/patient_spec/patient_manage.cy.ts diff --git a/cypress/e2e/patient_spec/patient_crud.cy.ts b/cypress/e2e/patient_spec/patient_crud.cy.ts index fcfd97039f7..4fef861aeab 100644 --- a/cypress/e2e/patient_spec/patient_crud.cy.ts +++ b/cypress/e2e/patient_spec/patient_crud.cy.ts @@ -130,12 +130,27 @@ describe("Patient Creation with consultation", () => { patientConsultationPage.interceptMediaBase(); patientConsultationPage.selectMedicinebox(); patientConsultationPage.waitForMediabaseStatusCode(); - patientConsultationPage.prescribeMedicine(); + patientConsultationPage.prescribefirstMedicine(); patientConsultationPage.enterDosage("3"); patientConsultationPage.selectDosageFrequency("Twice daily"); patientConsultationPage.submitPrescriptionAndReturn(); }); + it("Edit created consultation to existing patient", () => { + updatePatientPage.visitUpdatedPatient(); + patientConsultationPage.visitEditConsultationPage(); + patientConsultationPage.fillIllnessHistory("editted"); + patientConsultationPage.selectConsultationStatus( + "Referred from other hospital" + ); + patientConsultationPage.updateSymptoms("FEVER"); + patientConsultationPage.setSymptomsDate("01082023"); + patientConsultationPage.updateConsultation(); + patientConsultationPage.verifySuccessNotification( + "Consultation updated successfully" + ); + }); + afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/patient_manage.cy.ts b/cypress/e2e/patient_spec/patient_manage.cy.ts new file mode 100644 index 00000000000..e8d381286aa --- /dev/null +++ b/cypress/e2e/patient_spec/patient_manage.cy.ts @@ -0,0 +1,78 @@ +import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress"; +import LoginPage from "../../pageobject/Login/LoginPage"; +import { PatientConsultationPage } from "../../pageobject/Patient/PatientConsultation"; +import { PatientPage } from "../../pageobject/Patient/PatientCreation"; + +describe("Patient", () => { + const loginPage = new LoginPage(); + const patientPage = new PatientPage(); + const patientConsultationPage = new PatientConsultationPage(); + + before(() => { + loginPage.loginAsDisctrictAdmin(); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.awaitUrl("/patients"); + }); + + // it("Create Patient shift requests.", () => { + // patientPage.visitPatient(); + // patientConsultationPage.visitShiftRequestPage(); + // patientConsultationPage.enterPatientShiftDetails( + // "Test User", + // phone_number, + // "Dummy Shifting", + // "Reason" + // ); + // patientConsultationPage.createShiftRequest(); + // patientConsultationPage.verifySuccessNotification( + // "Shift request created successfully" + // ); + // }); + // commented out the shifting request, as logic need to be re-visited + + it("Post doctor notes for an already created patient", () => { + patientPage.visitPatient(); + patientConsultationPage.visitDoctorNotesPage(); + patientConsultationPage.addDoctorsNotes("Test Doctor Notes"); + patientConsultationPage.postDoctorNotes(); + patientConsultationPage.verifySuccessNotification( + "Note added successfully" + ); + }); + + it("Edit prescription for an already created patient", () => { + patientPage.visitPatient(); + patientConsultationPage.visitEditPrescriptionPage(); + patientConsultationPage.clickAddPrescription(); + patientConsultationPage.interceptMediaBase(); + patientConsultationPage.selectMedicinebox(); + patientConsultationPage.waitForMediabaseStatusCode(); + patientConsultationPage.prescribesecondMedicine(); + patientConsultationPage.enterDosage("4"); + patientConsultationPage.selectDosageFrequency("Twice daily"); + patientConsultationPage.submitPrescription(); + }); + + it("Upload consultations file ", () => { + patientPage.visitPatient(); + patientConsultationPage.visitFilesPage(); + patientConsultationPage.uploadFile(); + patientConsultationPage.clickUploadFile(); + }); + + it("Discharge a patient", () => { + patientPage.visitPatient(); + patientConsultationPage.clickDischargePatient(); + patientConsultationPage.selectDischargeReason("Recovered"); + patientConsultationPage.addDischargeNotes("Discharge notes"); + patientConsultationPage.confirmDischarge(); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); +}); diff --git a/cypress/pageobject/Patient/PatientConsultation.ts b/cypress/pageobject/Patient/PatientConsultation.ts index 2eb6550cb8b..bf301641898 100644 --- a/cypress/pageobject/Patient/PatientConsultation.ts +++ b/cypress/pageobject/Patient/PatientConsultation.ts @@ -1,5 +1,7 @@ export class PatientConsultationPage { selectConsultationStatus(status: string) { + cy.get("#consultation_status").scrollIntoView(); + cy.get("#consultation_status").should("be.visible"); cy.get("#consultation_status") .click() .then(() => { @@ -83,10 +85,18 @@ export class PatientConsultationPage { cy.intercept("GET", "**/api/v1/medibase/**").as("getMediaBase"); } - prescribeMedicine() { + prescribefirstMedicine() { cy.get("div#medicine_object input[placeholder='Select'][role='combobox']") .click() - .type("dolo{enter}"); + .type("dolo") + .type("{downarrow}{enter}"); + } + + prescribesecondMedicine() { + cy.get("div#medicine_object input[placeholder='Select'][role='combobox']") + .click() + .type("dolo") + .type("{downarrow}{downarrow}{enter}"); } selectMedicinebox() { @@ -95,6 +105,23 @@ export class PatientConsultationPage { ).click(); } + visitFilesPage() { + cy.get("a").contains("Files").click(); + } + + uploadFile() { + cy.get("#file_upload_patient").selectFile( + "cypress/fixtures/sampleAsset.xlsx", + { force: true } + ); + } + + clickUploadFile() { + cy.intercept("POST", "**/api/v1/files/").as("uploadFile"); + cy.get("#upload_file_button").click(); + cy.wait("@uploadFile").its("response.statusCode").should("eq", 201); + } + waitForMediabaseStatusCode() { cy.wait("@getMediaBase").its("response.statusCode").should("eq", 200); } @@ -119,4 +146,119 @@ export class PatientConsultationPage { cy.get("[data-testid='return-to-patient-dashboard']").click(); cy.wait("@submitPrescription").its("response.statusCode").should("eq", 201); } + + visitEditConsultationPage() { + cy.get("#view_consulation_updates").click(); + cy.get("button").contains("Edit Consultation Details").click(); + } + + setSymptomsDate(date: string) { + cy.get("#symptoms_onset_date") + .click() + .then(() => { + cy.get("[placeholder='DD/MM/YYYY']").type(date); + }); + } + + updateConsultation() { + cy.intercept("PUT", "**/api/v1/consultation/**").as("updateConsultation"); + cy.get("#submit").contains("Update Consultation").click(); + cy.wait("@updateConsultation").its("response.statusCode").should("eq", 200); + } + + verifySuccessNotification(message: string) { + cy.verifyNotification(message); + } + + updateSymptoms(symptoms: string) { + this.selectSymptoms(symptoms); + cy.get("#symptoms").click(); + } + + visitShiftRequestPage() { + cy.get("#create_shift_request").click(); + } + + enterPatientShiftDetails( + name: string, + phone_number: string, + facilityName: string, + reason: string + ) { + cy.get("#refering_facility_contact_name").type(name); + cy.get("#refering_facility_contact_number").type(phone_number); + cy.get("input[name='assigned_facility']") + .type(facilityName) + .then(() => { + cy.get("[role='option']").first().click(); + }); + cy.get("#reason").type(reason); + } + + createShiftRequest() { + cy.intercept("POST", "**/api/v1/shift/").as("createShiftRequest"); + cy.get("#submit").click(); + cy.wait("@createShiftRequest").its("response.statusCode").should("eq", 201); + } + + visitDoctorNotesPage() { + cy.get("#patient_doctor_notes").click(); + } + + addDoctorsNotes(notes: string) { + cy.get("#doctor_notes_textarea").type(notes); + } + + postDoctorNotes() { + cy.intercept("POST", "**/api/v1/patient/*/notes").as("postDoctorNotes"); + cy.get("#submit").contains("Post Your Note").click(); + cy.wait("@postDoctorNotes").its("response.statusCode").should("eq", 201); + } + + clickDischargePatient() { + cy.get("#discharge_patient_from_care").click(); + } + + selectDischargeReason(reason: string) { + cy.get("#discharge_reason") + .click() + .then(() => { + cy.get("[role='option']").contains(reason).click(); + }); + } + + addDischargeNotes(notes: string) { + cy.get("#discharge_notes").type(notes); + } + + confirmDischarge() { + cy.intercept("POST", "**/api/v1/consultation/*/discharge_patient/").as( + "dischargePatient" + ); + cy.get("#submit").contains("Confirm Discharge").click(); + cy.wait("@dischargePatient").its("response.statusCode").should("eq", 200); + } + + 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); + } + + visitEditPrescriptionPage() { + cy.get("#consultation_tab_nav").contains("Medicines").click(); + cy.get("a[href='prescriptions']").first().click(); + } + + submitPrescription() { + cy.intercept("POST", "**/api/v1/consultation/*/prescriptions/").as( + "submitPrescription" + ); + cy.get("#submit").contains("Submit").click(); + cy.wait("@submitPrescription").its("response.statusCode").should("eq", 201); + } } diff --git a/cypress/pageobject/Patient/PatientCreation.ts b/cypress/pageobject/Patient/PatientCreation.ts index 4fcd43dc490..47bf9c913ad 100644 --- a/cypress/pageobject/Patient/PatientCreation.ts +++ b/cypress/pageobject/Patient/PatientCreation.ts @@ -10,6 +10,12 @@ export class PatientPage { cy.wait("@getFacilities").its("response.statusCode").should("eq", 200); } + visitPatient() { + cy.intercept("GET", "**/api/v1/consultation/**").as("getPatient"); + cy.get("[data-cy='patient']").first().click(); + cy.wait("@getPatient").its("response.statusCode").should("eq", 200); + } + selectFacility(facilityName: string) { cy.get("input[name='facilities']") .type(facilityName) diff --git a/src/Components/Facility/ConsultationCard.tsx b/src/Components/Facility/ConsultationCard.tsx index f6b4484b477..4859b981e8f 100644 --- a/src/Components/Facility/ConsultationCard.tsx +++ b/src/Components/Facility/ConsultationCard.tsx @@ -131,6 +131,7 @@ export const ConsultationCard = (props: ConsultationProps) => {
navigate( diff --git a/src/Components/Facility/ConsultationDetails/index.tsx b/src/Components/Facility/ConsultationDetails/index.tsx index 3d3271b16d5..d21200543c3 100644 --- a/src/Components/Facility/ConsultationDetails/index.tsx +++ b/src/Components/Facility/ConsultationDetails/index.tsx @@ -309,6 +309,7 @@ export const ConsultationDetails = (props: any) => { ) : ( navigate( `/facility/${patientData.facility}/patient/${patientData.id}/shift/new` @@ -352,6 +353,7 @@ export const ConsultationDetails = (props: any) => { Patient Details @@ -450,6 +452,7 @@ export const ConsultationDetails = (props: any) => { setOpenDischargeDialog(true)} disabled={!!consultationData.discharge_date} > @@ -496,7 +499,10 @@ export const ConsultationDetails = (props: any) => {
-