Skip to content

Commit

Permalink
Merge branch 'develop' into fix-linting-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 committed Jun 27, 2023
2 parents 86c34d3 + a7fdef2 commit 2ded92a
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 193 deletions.
235 changes: 46 additions & 189 deletions cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
@@ -1,206 +1,63 @@
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
// FacilityCreation
import FacilityPage from "../../pageobject/Facility/FacilityCreation";

class facility {
static create(facility) {
cy.awaitUrl("/facility/create");
this.fillForm({
...facility,
latitude: 800,
longitude: 500,
});
cy.get("[id=submit]").should("exist").click();
cy.verifyNotification("Facility added successfully");
}

static update(facility) {
cy.get("[id=manage-facility-dropdown]").click();
cy.get("[id=update-facility]").click();
cy.url().should("include", "update");
this.fillForm({
...facility,
latitude: 900,
longitude: 600,
});
cy.get("[id=submit]").should("exist").click();
cy.verifyNotification("Facility updated successfully");
}

static fillForm({
type,
name,
features,
address,
pincode,
phone,
state,
district,
localbody,
ward,
oxygen_capacity,
oxygen_requirement,
type_b_cylinders,
expected_type_b_cylinders,
type_c_cylinders,
expected_type_c_cylinders,
type_d_cylinders,
expected_type_d_cylinders,
latitude,
longitude,
}) {
cy.get("[id=facility_type] > div > button").click();
cy.get("div").contains(type).click();

cy.get("input[id=pincode]").should("exist").clear().type(pincode);
cy.get("input[id=name]").should("exist").type(name);

cy.get("[id=state] > div > button").click();
cy.get("div").contains(state).click();

cy.get("[id=features] > div > div > button").click();
cy.get("li").contains(features[0]).click();
cy.get("li").contains(features[1]).click();
cy.get("body").click();

cy.get("[id=district] > div > button").click();
cy.get("div").contains(district).click();

cy.get("textarea[id=address]").should("exist").type(address);

cy.get("[id=local_body] > div > button").click();
cy.get("div").contains(localbody).click();

cy.get("input[name=phone_number]").clear();
cy.get("input[name=phone_number]").type(phone);

cy.get("[id=ward] > div > button").click();
cy.get("div").contains(ward).click();

cy.get("input[id=oxygen_capacity]").clear().type(oxygen_capacity);
cy.get("input[id=expected_oxygen_requirement]")
.should("exist")
.clear()
.type(oxygen_requirement);
describe("Facility Creation", () => {
let facilityUrl: string;
const facilityPage = new FacilityPage();

cy.get("input[id=type_b_cylinders]")
.should("exist")
.clear()
.type(type_b_cylinders);
cy.get("input[id=expected_type_b_cylinders]")
.should("exist")
.clear()
.type(expected_type_b_cylinders);

cy.get("input[id=type_c_cylinders]")
.should("exist")
.clear()
.type(type_c_cylinders);
cy.get("input[id=expected_type_c_cylinders]")
.should("exist")
.clear()
.type(expected_type_c_cylinders);

cy.get("input[id=type_d_cylinders]")
.should("exist")
.clear()
.type(type_d_cylinders);
cy.get("input[id=expected_type_d_cylinders]")
.should("exist")
.clear()
.type(expected_type_d_cylinders);

cy.get("[id=facility-location-button]").click();
cy.get("body").wait(7000).click(latitude, longitude);
cy.get("body").click();
}
}

let current_url = "/";

describe("Facility", () => {
before(() => {
cy.loginByApi("devdistrictadmin", "Coronasafe@123");
cy.saveLocalStorage();
});

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

it("create facility", () => {
facility.create({
type: "Private Hospital",
name: "cypress facility",
features: ["CT Scan", "X-Ray"],
pincode: "682001",
state: "Kerala",
district: "Ernakulam",
localbody: "Aikaranad",
ward: "EZHIPRAM",
address: "some address",
phone: "+919985784535",
oxygen_capacity: "20",
oxygen_requirement: "30",
type_b_cylinders: "20",
expected_type_b_cylinders: "46",
type_c_cylinders: "43",
expected_type_c_cylinders: "34",
type_d_cylinders: "342",
expected_type_d_cylinders: "43",
latitude: "-4.214943141390639",
longitude: "1.494140625",
});

cy.verifyNotification("Facility added successfully");

// add bed type
cy.get("[id=bed-type] > div > button").click();
cy.get("div").contains("Non-Covid Ordinary Beds").click();
cy.get("input[id=total-capacity]").should("exist").type("150");
cy.get("input[id=currently-occupied]").should("exist").type("100");
cy.get("[id=bed-capacity-save-and-exit]").click();

cy.verifyNotification("Bed capacity added successfully");

// add doctor information
cy.get("[id=area-of-specialization] > div > button").click();
cy.get("ul > li:nth-child(2)").click();
cy.get("[id=count]").type("15");
cy.get("[id=save-and-exit").click();

cy.verifyNotification("Doctor count added successfully");
cy.url().then((url) => {
current_url = url;
it("Create a new facility", () => {
facilityPage.visitCreateFacilityPage();
facilityPage.fillFacilityName("cypress facility");
facilityPage.fillPincode("682001");
facilityPage.selectState("Kerala");
facilityPage.selectDistrict("Ernakulam");
facilityPage.selectLocalBody("Aluva");
facilityPage.selectWard("4");
facilityPage.fillAddress("Cypress Address");
facilityPage.fillPhoneNumber("9898469865");
facilityPage.submitForm();

facilityPage.selectBedType("Non-Covid Oxygen beds");
facilityPage.fillTotalCapacity("10");
facilityPage.fillCurrentlyOccupied("5");
facilityPage.saveAndExitBedCapacityForm();

facilityPage.selectAreaOfSpecialization("General Medicine");
facilityPage.fillDoctorCount("5");
facilityPage.saveAndExitDoctorForm();

cy.url().then((initialUrl) => {
cy.get("button#save-and-exit").should("not.exist");
cy.url()
.should("not.equal", initialUrl)
.then((newUrl) => {
facilityUrl = newUrl;
});
});
});

it("update facility", () => {
facility.update({
type: "TeleMedicine",
name: " update",
features: ["X-Ray", "Neonatal Care"],
pincode: "682003",
state: "Kerala",
district: "Ernakulam",
localbody: "Alangad",
ward: "VELIYATHUNADU",
address: " update",
phone: "+919985784535",
oxygen_capacity: "30",
oxygen_requirement: "40",
type_b_cylinders: "23",
expected_type_b_cylinders: "29",
type_c_cylinders: "72",
expected_type_c_cylinders: "84",
type_d_cylinders: "64",
expected_type_d_cylinders: "4",
latitude: "-16.97274101999901",
longitude: "11.77734375",
});
cy.verifyNotification("Facility updated successfully");
cy.url().then((url) => {
current_url = url;
});
it("Update the existing facility", () => {
facilityPage.visitUpdateFacilityPage(facilityUrl);
facilityPage.clickManageFacilityDropdown();
facilityPage.clickUpdateFacilityOption();
facilityPage.fillFacilityName("cypress facility updated");
facilityPage.fillAddress("Cypress Facility Updated Address");
facilityPage.fillOxygenCapacity("100");
facilityPage.fillExpectedOxygenRequirement("80");
facilityPage.selectLocation("Kochi, Kerala");
facilityPage.submitForm();

cy.url().should("not.include", "/update");
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 phone_number = "9" + Math.floor(100000000 + Math.random() * 900000000);
const emergency_phone_number = "9430123487";
const yearOfBirth = "2023";
let patient_url = "";
Expand All @@ -29,7 +29,7 @@ describe("Patient Creation with consultation", () => {
cy.get("input[name='facilities']")
.type("cypress facility")
.then(() => {
cy.get("[role='option']").contains("cypress facility").click();
cy.get("[role='option']").first().click();
});
cy.get("button").should("contain", "Select");
cy.get("button").get("#submit").click();
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/users_spec/user_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("User management", () => {
.click()
.type("cypress facility")
.wait("@facility");
cy.get("li[role='option']").contains("cypress facility").click();
cy.get("li[role='option']").first().click();
cy.get("input[type='checkbox']").click();
cy.get("[name='phone_number']").type(phone_number);
cy.get("[name='alt_phone_number']").type(alt_phone_number);
Expand Down Expand Up @@ -106,7 +106,7 @@ describe("User management", () => {
.click()
.type("cypress facility")
.wait("@getFacilities");
cy.get("li[role='option']").contains("cypress facility").click();
cy.get("li[role='option']").first().click();
cy.intercept(/\/api\/v1\/users\/\w+\/add_facility\//).as("addFacility");
cy.get("button[id='link-facility']").click();
cy.wait("@addFacility")
Expand Down
106 changes: 106 additions & 0 deletions cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// FacilityPage.ts
class FacilityPage {
visitCreateFacilityPage() {
cy.visit("/facility/create");
}

visitUpdateFacilityPage(url: string) {
cy.visit(url);
}

fillFacilityName(name: string) {
cy.get("#name").clear().type(name);
}

fillPincode(pincode: string) {
cy.get("#pincode").click().type(pincode);
}

selectState(state: string) {
cy.get("div#state button").click();
cy.get("[role='option']").contains(state).click();
}

selectDistrict(district: string) {
cy.get("div#district button").click();
cy.get("[role='option']").contains(district).click();
}

selectLocalBody(localBody: string) {
cy.get("div#local_body button").click();
cy.get("[role='option']").contains(localBody).click();
}

selectWard(ward: string) {
cy.get("div#ward button").click();
cy.get("[role='option']").contains(ward).click();
}

fillAddress(address: string) {
cy.get("#address").click().clear().type(address);
}

fillPhoneNumber(phoneNumber: string) {
cy.get("#phone_number").type(phoneNumber);
}

submitForm() {
cy.get("button#submit").click();
}

selectBedType(bedType: string) {
cy.get("div#bed-type button").click();
cy.get("[role='option']").contains(bedType).click();
}

fillTotalCapacity(capacity: string) {
cy.get("input#total-capacity").click().type(capacity);
}

fillCurrentlyOccupied(occupied: string) {
cy.get("input#currently-occupied").click().type(occupied);
}

saveAndExitBedCapacityForm() {
cy.get("button#bed-capacity-save-and-exit").click();
}

selectAreaOfSpecialization(area: string) {
cy.get("div#area-of-specialization button").click();
cy.get("[role='option']").contains(area).click();
}

fillDoctorCount(count: string) {
cy.get("input#count").click().type(count);
}

fillOxygenCapacity(capacity: string) {
cy.get("#oxygen_capacity").click().clear().type(capacity);
}

fillExpectedOxygenRequirement(requirement: string) {
cy.get("#expected_oxygen_requirement").click().clear().type(requirement);
}

saveAndExitDoctorForm() {
cy.get("button#save-and-exit").click();
}

clickManageFacilityDropdown() {
cy.get("#manage-facility-dropdown").click();
}

clickUpdateFacilityOption() {
cy.get("#update-facility").contains("Update Facility").click();
}

selectLocation(location: string) {
cy.get("span > svg.care-svg-icon__baseline.care-l-map-marker").click();
cy.intercept("https://maps.googleapis.com/maps/api/mapsjs/*").as("mapApi");
cy.wait("@mapApi").its("response.statusCode").should("eq", 200);
cy.get("input#pac-input").type(location).type("{enter}");
cy.get("div#map-close").click();
}
}

export default FacilityPage;

0 comments on commit 2ded92a

Please sign in to comment.