Skip to content

Commit

Permalink
Added cypress test for new patient creation (#5549)
Browse files Browse the repository at this point in the history
* Added test for patient creation

* Fixed patient creation suite

* Fixed edit and update test cases and removed unwanted changes

* Tried a fix

* submit patient form in edit test in patient crud

---------

Co-authored-by: Khavin Shankar <[email protected]>
  • Loading branch information
ShivamJhaa and khavinshankar authored Jun 4, 2023
1 parent fb07099 commit 5982c94
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 105 deletions.
226 changes: 127 additions & 99 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
@@ -1,107 +1,135 @@
// import { cy, describe, before, beforeEach, it, afterEach } from "local-cypress";
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";

// const username = "devdistrictadmin";
// const password = "Coronasafe@123";
// const phone_number = "9" + parseInt((Math.random() * 10 ** 9).toString());
// const emergency_phone_number = "9430123487";
// const yearOfBirth = "1999";
// let patient_url = "";
const username = "devdistrictadmin";
const password = "Coronasafe@123";
const phone_number = "9" + parseInt((Math.random() * 10 ** 9).toString());
const emergency_phone_number = "9430123487";
const yearOfBirth = "2023";
let patient_url = "";

// const calculateAge = () => {
// const currentYear = new Date().getFullYear();
// return currentYear - parseInt(yearOfBirth);
// };
const calculateAge = () => {
const currentYear = new Date().getFullYear();
return currentYear - parseInt(yearOfBirth);
};

// describe("Patient Creation", () => {
// before(() => {
// cy.loginByApi(username, password);
// cy.saveLocalStorage();
// });
describe("Patient Creation", () => {
before(() => {
cy.loginByApi(username, password);
cy.saveLocalStorage();
});

// beforeEach(() => {
// cy.restoreLocalStorage();
// cy.awaitUrl("/");
// });
beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/patients");
});

// it("Create", () => {
// cy.get("[id='facility-details']").first().click();
// cy.get("button").should("contain", "Add Details of a Patient");
// cy.get("button")
// .contains("Add Details of a Patient")
// .click({ force: true });
// cy.get("[data-testid=phone-number] input").type(phone_number);
// cy.get("[data-testid=date-of-birth] svg").click();
// cy.get("div").contains(yearOfBirth).click();
// cy.get("span").contains("OK").click();
// cy.get("[data-testid=name] input").type("Test E2E User");
// cy.get("[data-testid=Gender] select").select("Male");
// cy.get("[data-testid=state] select").select("Kerala");
// cy.get("[data-testid=district] select").select("Ernakulam");
// cy.get("[data-testid=localbody] select").select(
// "Alangad  Block Panchayat, Ernakulam District"
// );
// cy.get("[data-testid=current-address] textarea").type(
// "Test Patient Address"
// );
// cy.get("[data-testid=permanent-address] input").check();
// cy.get("[data-testid=ward-respective-lsgi] select").select(
// "1: MANAKKAPADY"
// );
// cy.get("h1").contains("COVID Details").click({ force: true });
// cy.get("select#test_type").select("ANTIGEN");
// cy.get("[name='is_vaccinated']").check();
// cy.get("[data-testid=pincode] input").type("159015");
// cy.get("[name=medical_history_check_1]").check();
// cy.get("[data-testid=blood-group] select").select("O+");
// cy.get("[data-testid=emergency-phone-number] input").type(
// emergency_phone_number,
// { delay: 100 }
// );
// cy.wait(1000);
// cy.get("button").get("[data-testid=submit-button]").click();
// cy.url().should("include", "/consultation");
// cy.url().then((url) => {
// cy.log(url);
// patient_url = url.split("/").slice(0, -1).join("/");
// cy.log(patient_url);
// });
// });
it("Create a patient", () => {
cy.get("button").should("contain", "Add Patient Details");
cy.get("#add-patient-div").click();
cy.get("input[name='facilities']")
.type("ABCD Hospital, Ernakulam")
.then(() => {
cy.get("[role='option']").contains("ABCD Hospital, Ernakulam").click();
});
cy.get("button").should("contain", "Select");
cy.get("button").get("#submit").click();
cy.get("#phone_number-div").type(phone_number);
cy.get("#emergency_phone_number-div").type(emergency_phone_number);
cy.get("[data-testid=date-of-birth] button").click();
cy.get("div").contains("1").click();
cy.get("[data-testid=name] input").type("Test E2E User");
cy.get("[data-testid=Gender] button")
.click()
.then(() => {
cy.get("[role='option']").contains("Male").click();
});
cy.get("[data-testid=state] button")
.click()
.then(() => {
cy.get("[role='option']").contains("Kerala").click();
});
cy.get("[data-testid=district] button")
.click()
.then(() => {
cy.get("[role='option']").contains("Ernakulam").click();
});
cy.get("[data-testid=localbody] button")
.click()
.then(() => {
cy.get("[role='option']").first().click();
});
cy.get("[data-testid=current-address] textarea").type(
"Test Patient Address"
);
cy.get("[data-testid=permanent-address] input").check();
cy.get("[data-testid=ward-respective-lsgi] button")
.click()
.then(() => {
cy.get("[role='option']").contains("1: PAZHAMTHOTTAM").click();
});
cy.get("button").contains("COVID Details").click();
cy.get("select#test_type").select("ANTIGEN");
cy.get("[name='is_vaccinated']").check();
cy.get("[data-testid=pincode] input").type("159015");
cy.get("[name=medical_history_check_1]").check();
cy.get("[data-testid=blood-group] button")
.click()
.then(() => {
cy.get("[role='option']").contains("O+").click();
});
cy.get("button").get("[data-testid=submit-button]").click();
cy.get("h2").should("contain", "Create Consultation");
cy.url().should("include", "/patient");
cy.url().then((url) => {
cy.log(url);
patient_url = url.split("/").slice(0, -1).join("/");
cy.log(patient_url);
});
});

// it("Dashboard", () => {
// cy.awaitUrl(patient_url);
// cy.url().should("include", "/patient/");
// cy.get("[data-testid=patient-dashboard]").should("contain", calculateAge());
// cy.get("[data-testid=patient-dashboard]").should(
// "contain",
// "Test E2E User"
// );
// cy.get("[data-testid=patient-dashboard]").should("contain", phone_number);
// cy.get("[data-testid=patient-dashboard]").should(
// "contain",
// emergency_phone_number
// );
// cy.get("[data-testid=patient-dashboard]").should("contain", "1999");
// cy.get("[data-testid=patient-dashboard]").should("contain", "O+");
// });
it("Dashboard", () => {
cy.log(patient_url);
cy.awaitUrl(patient_url);
cy.url().should("include", "/facility/");
cy.get("[data-testid=patient-dashboard]").should("contain", calculateAge());
cy.get("[data-testid=patient-dashboard]").should(
"contain",
"Test E2E User"
);
cy.get("[data-testid=patient-dashboard]").should("contain", phone_number);
cy.get("[data-testid=patient-dashboard]").should(
"contain",
emergency_phone_number
);
cy.get("[data-testid=patient-dashboard]").should("contain", yearOfBirth);
cy.get("[data-testid=patient-dashboard]").should("contain", "O+");
});

// it("Edit", () => {
// cy.awaitUrl(patient_url + "/update");
// cy.get("[data-testid=state] select").should("contain", "Kerala");
// cy.get("[data-testid=district] select").should("contain", "Ernakulam");
// cy.get("[data-testid=localbody] select").should("contain", "Alangad");
// cy.get("[data-testid=current-address] textarea").should(
// "contain",
// "Test Patient Address"
// );
// // cy.get("[data-testid=permanent-address] input").should("be.checked")
// cy.get("[data-testid=ward-respective-lsgi] select").should(
// "contain",
// "MANAKKAPADY"
// );
// cy.get("[data-testid=pincode] input").should("have.value", "159015");
// });
it("Edit", () => {
cy.awaitUrl(patient_url + "/update");
cy.get("[data-testid=state] button").should("contain", "Kerala");
cy.get("[data-testid=district] button").should("contain", "Ernakulam");
cy.get("[data-testid=localbody] button").should("contain", "Aikaranad");
cy.get("[data-testid=current-address] textarea").should(
"contain",
"Test Patient Address"
);
cy.get("[data-testid=permanent-address] input").should("be.checked");
cy.get("[data-testid=ward-respective-lsgi] button").should(
"contain",
"PAZHAMTHOTTAM"
);
cy.get("[data-testid=pincode] input").should("have.value", "159015");
cy.get("button").get("[data-testid=submit-button]").click();
cy.url().should("include", "/patient");
cy.url().then((url) => {
cy.log(url);
patient_url = url.split("/").slice(0, -1).join("/");
cy.log(patient_url);
});
});

// afterEach(() => {
// cy.saveLocalStorage();
// });
// });
afterEach(() => {
cy.saveLocalStorage();
});
});
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const App: React.FC = () => {

const updateRefreshToken = () => {
const refresh = localStorage.getItem(LocalStorageKeys.refreshToken);
const access = localStorage.getItem(LocalStorageKeys.accessToken);
// const access = localStorage.getItem(LocalStorageKeys.accessToken);
// if (!access && refresh) {
// localStorage.removeItem(LocalStorageKeys.refreshToken);
// document.location.reload();
Expand Down
4 changes: 2 additions & 2 deletions src/Common/hooks/useExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default function useExport() {
const date = d.toLocaleDateString();
const time = d.toLocaleTimeString();

return date+"_"+time;
}
return date + "_" + time;
};

const exportCSV = async (
filenamePrefix: string,
Expand Down
4 changes: 3 additions & 1 deletion src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,9 @@ export const PatientManager = () => {
}}
>
<CareIcon className="care-l-plus text-lg" />
<p className="lg:my-[2px]">Add Patient Details</p>
<p id="add-patient-div" className="lg:my-[2px]">
Add Patient Details
</p>
</ButtonV2>
<AdvancedFilterButton onClick={() => advancedFilter.setShow(true)} />
<SortDropdownMenu
Expand Down
2 changes: 0 additions & 2 deletions src/Redux/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
} from "../Components/Medicine/models";
import { fireRequest, fireRequestForFiles } from "./fireRequest";

import { LocalStorageKeys } from "../Common/constants";

export const getConfig = () => {
return fireRequestForFiles("config");
};
Expand Down

0 comments on commit 5982c94

Please sign in to comment.