From f8238622b80bdf0dbc54c01cd012121264803869 Mon Sep 17 00:00:00 2001 From: MjStar Date: Mon, 1 Apr 2024 00:05:00 +0530 Subject: [PATCH] cypress tests for patient details page --- .../e2e/patient_spec/patient_details.cy.ts | 102 ++++++++++++++++++ .../pageobject/Patient/AssignToVolunteer.ts | 15 +++ .../Patient/PatientSampleRequest.ts | 76 +++++++++++++ cypress/pageobject/Patient/ShiftPatient.ts | 43 ++++++++ .../Facility/ConsultationDetails/index.tsx | 1 + src/Components/Patient/PatientHome.tsx | 3 + 6 files changed, 240 insertions(+) create mode 100644 cypress/e2e/patient_spec/patient_details.cy.ts create mode 100644 cypress/pageobject/Patient/AssignToVolunteer.ts create mode 100644 cypress/pageobject/Patient/PatientSampleRequest.ts create mode 100644 cypress/pageobject/Patient/ShiftPatient.ts diff --git a/cypress/e2e/patient_spec/patient_details.cy.ts b/cypress/e2e/patient_spec/patient_details.cy.ts new file mode 100644 index 00000000000..5c2efb6cf02 --- /dev/null +++ b/cypress/e2e/patient_spec/patient_details.cy.ts @@ -0,0 +1,102 @@ +import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress"; +import LoginPage from "../../pageobject/Login/LoginPage"; +import { PatientPage } from "../../pageobject/Patient/PatientCreation"; +import { PatientSampleRequest } from "../../pageobject/Patient/PatientSampleRequest"; +import { AssignToVolunteer } from "../../pageobject/Patient/AssignToVolunteer"; +import { ShiftPatient } from "../../pageobject/Patient/ShiftPatient"; + +describe("patient details", () => { + const loginPage = new LoginPage(); + const patientPage = new PatientPage(); + const patientSampleRequest = new PatientSampleRequest(); + const assignToVolunteer = new AssignToVolunteer(); + const shiftPatient = new ShiftPatient(); + + before(() => { + loginPage.loginAsDisctrictAdmin(); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); + cy.awaitUrl("/patients"); + }); + + const patientName = "Gigin"; + const ICMRlabel = "ICMR"; + const fastTrackRequired = true; + const fastTrackReason = "dummy reason"; + const atypicalPresentation = true; + const atypicalDetails = "dummy details"; + const doctorName = "dummy doctor"; + const diagnosis = "dummy diagnosis"; + const etiology = "dummy etiology"; + const differentialDiagnosis = "dummy diagnosis"; + const ari = true; + const sari = true; + const isUnusual = true; + + it("Create Patient Sample Test Request", () => { + patientPage.visitPatient(patientName); + patientSampleRequest.visitPatientDetails(); + patientSampleRequest.visitSampleRequest(); + patientSampleRequest.selectSampleTestType(); + patientSampleRequest.selectICMRCategory(); + patientSampleRequest.typeICMRLabel(ICMRlabel); + patientSampleRequest.selectIsFastTrackRequired(fastTrackRequired); + patientSampleRequest.fastTrackReason(fastTrackRequired, fastTrackReason); + patientSampleRequest.selectIsATypicalPresentation(atypicalPresentation); + patientSampleRequest.atypicalDetails(atypicalPresentation, atypicalDetails); + patientSampleRequest.typeDoctorName(doctorName); + patientSampleRequest.typeDiagnosis(diagnosis); + patientSampleRequest.typeEtiologyIdentified(etiology); + patientSampleRequest.typeDifferentialDiagnosis(differentialDiagnosis); + patientSampleRequest.selectHasAri(ari); + patientSampleRequest.selectHasSari(sari); + patientSampleRequest.selectIsUnusual(isUnusual); + // patientSampleRequest.clickCancelButton(); + patientSampleRequest.clickSubmitButton(); + }); + + const contactPersonName = "Manas"; + const phoneNumber = "9650244789"; + const facilityName = "Govt"; + const patientCategory = "Comfort"; + const shiftReason = "dummy reason"; + const driverName = "Mohit"; + const ambulancePhoneNumber = "7845968745"; + const ambulanceNumber = "201301"; + const comment = "dummy comment"; + + it("Create Patient Shift Patient Request", () => { + patientPage.visitPatient(patientName); + patientSampleRequest.visitPatientDetails(); + shiftPatient.visitShiftPatient(); + shiftPatient.typeContactPersonName(contactPersonName); + shiftPatient.typePhoneNumber(phoneNumber); + shiftPatient.selectFacility(facilityName); + shiftPatient.selectPatientCategory(patientCategory); + shiftPatient.typeReasonForShift(shiftReason); + shiftPatient.typeNameOfDriver(driverName); + shiftPatient.typeAmbulancePhoneNumber(ambulancePhoneNumber); + shiftPatient.typeAmbulanceNumber(ambulanceNumber); + shiftPatient.typeOtherComments(comment); + shiftPatient.clickSubmitButton(); + // shiftPatient.clickCancelButton(); + }); + + const volunteerName = "Volunteer"; + + it("assign volunteer", () => { + patientPage.visitPatient(patientName); + patientSampleRequest.visitPatientDetails(); + assignToVolunteer.visitAssignToVolunteer(); + assignToVolunteer.selectVolunteer(volunteerName); + assignToVolunteer.clickCancelButton(); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); +}); diff --git a/cypress/pageobject/Patient/AssignToVolunteer.ts b/cypress/pageobject/Patient/AssignToVolunteer.ts new file mode 100644 index 00000000000..adf72c7fcb1 --- /dev/null +++ b/cypress/pageobject/Patient/AssignToVolunteer.ts @@ -0,0 +1,15 @@ +import { cy } from "local-cypress"; +export class AssignToVolunteer { + visitAssignToVolunteer() { + cy.get("#volunteer_assign").click({ force: true }); + } + selectVolunteer(volunteer: string) { + cy.searchAndSelectOption("#assign_volunteer input", volunteer); + } + clickSubmitButton() { + cy.get("#submit").click(); + } + clickCancelButton() { + cy.get("#cancel").click(); + } +} diff --git a/cypress/pageobject/Patient/PatientSampleRequest.ts b/cypress/pageobject/Patient/PatientSampleRequest.ts new file mode 100644 index 00000000000..46d772c0376 --- /dev/null +++ b/cypress/pageobject/Patient/PatientSampleRequest.ts @@ -0,0 +1,76 @@ +import { cy } from "local-cypress"; +export class PatientSampleRequest { + visitPatientDetails() { + cy.get("#patient-details").click(); + } + visitSampleRequest() { + cy.get("#sample-request").click({ force: true }); + } + selectSampleTestType() { + cy.get("#sample_type").click(); + cy.get("#sample_type ul").first().click(); + } + selectICMRCategory() { + cy.get("#icmr_category").click(); + cy.get("#icmr_category ul").first().click(); + } + typeICMRLabel(name: string) { + cy.get("input[name=icmr_label]").type(name); + } + selectIsFastTrackRequired(bool: boolean) { + if (bool) cy.get("input[name=isFastTrack]").click(); + else return; + } + fastTrackReason(bool: boolean, reason: string) { + if (bool) cy.get("#fast_track").type(reason); + else return; + } + selectTestingFacility(facility: string) { + cy.searchAndSelectOption("input[name=testing_facility]", facility); + } + typeDoctorName(name: string) { + cy.get("#doctor_name").type(name); + } + selectIsATypicalPresentation(bool: boolean) { + if (bool) cy.get("input[name=is_atypical_presentation]").click(); + else return; + } + + atypicalDetails(bool: boolean, details: string) { + if (bool) cy.get("#atypical_presentation").type(details); + else return; + } + typeDiagnosis(diagnosis: string) { + cy.get("#diagnosis").type(diagnosis); + } + typeEtiologyIdentified(etiology: string) { + cy.get("#etiology_identified").type(etiology); + } + typeDifferentialDiagnosis(diagnosis: string) { + cy.get("#diff_diagnosis").type(diagnosis); + } + selectHasSari(bool: boolean) { + if (bool) cy.get("input[name=has_sari]").click(); + else return; + } + selectHasAri(bool: boolean) { + if (bool) cy.get("input[name=has_ari]").click(); + else return; + } + selectIsUnusual(bool: boolean) { + if (bool) cy.get("input[name=is_unusual_course]").click(); + else return; + } + clickSubmitButton() { + cy.intercept("POST", "**/api/v1/patient/*/test_sample").as( + "createSampleRequest" + ); + cy.get("#submit").click(); + cy.wait("@createSampleRequest") + .its("response.statusCode") + .should("eq", 201); + } + clickCancelButton() { + cy.get("#cancel").click(); + } +} diff --git a/cypress/pageobject/Patient/ShiftPatient.ts b/cypress/pageobject/Patient/ShiftPatient.ts new file mode 100644 index 00000000000..7d456ab93e1 --- /dev/null +++ b/cypress/pageobject/Patient/ShiftPatient.ts @@ -0,0 +1,43 @@ +import { cy } from "local-cypress"; +export class ShiftPatient { + visitShiftPatient() { + cy.get("#shift_patient").click({ force: true }); + } + typeContactPersonName(name: string) { + cy.get("#refering_facility_contact_name").type(name); + } + typePhoneNumber(phone: string) { + cy.get("#refering_facility_contact_number").type(phone); + } + selectFacility(facility: string) { + cy.searchAndSelectOption("input[name=assigned_facility]", facility); + } + selectPatientCategory(category: string) { + cy.clickAndSelectOption("#patient_category", category); + } + typeReasonForShift(reason: string) { + cy.get("textarea[name=reason]").type(reason); + } + typeNameOfDriver(name: string) { + cy.get("input[name=ambulance_driver_name]").type(name); + } + typeAmbulancePhoneNumber(phone: string) { + cy.get("#ambulance_phone_number").type(phone); + } + typeAmbulanceNumber(num: string) { + cy.get("#ambulance_number").type(num); + } + typeOtherComments(comment: string) { + cy.get("textarea[name=comments]").type(comment); + } + clickSubmitButton() { + cy.intercept("POST", "**/api/v1/shift/").as("createSampleRequest"); + cy.get("#submit").click(); + cy.wait("@createSampleRequest") + .its("response.statusCode") + .should("eq", 201); + } + clickCancelButton() { + cy.get("#cancel").click(); + } +} diff --git a/src/Components/Facility/ConsultationDetails/index.tsx b/src/Components/Facility/ConsultationDetails/index.tsx index b422fc8867d..8b98beabea1 100644 --- a/src/Components/Facility/ConsultationDetails/index.tsx +++ b/src/Components/Facility/ConsultationDetails/index.tsx @@ -318,6 +318,7 @@ export const ConsultationDetails = (props: any) => { Patient Details diff --git a/src/Components/Patient/PatientHome.tsx b/src/Components/Patient/PatientHome.tsx index 59ec27b3c36..195624c400e 100644 --- a/src/Components/Patient/PatientHome.tsx +++ b/src/Components/Patient/PatientHome.tsx @@ -1108,6 +1108,7 @@ export const PatientHome = (props: any) => {

{

{