Skip to content

Commit

Permalink
Added test for resource, facility and migrated them to POM approach (o…
Browse files Browse the repository at this point in the history
…hcnetwork#6106)

* lints

* Added test for resource and migrated it to POM

* trying a fix

* nits

* backend change

* Reverted useless changes

* fix test

* Fixed failing test

* Added api verification

* Diagnosis: Adds field Principal Diagnosis (ohcnetwork#6218)

* adds field principle diagnosis

* show in consultation details

* fix typo

* fix cypress

* try adding wait

* fix tests

* open pdf file preview in new tab (ohcnetwork#6226)

* Changed weekly to average weekly for working hours (ohcnetwork#6228)

* Added padding to count block on patients page

* fixed date format in asset manage page

* Merged configure facility and configure health facility in one page

* removed commented code

* changed weekly to average weekly for working hours

* Resolved comments

---------

Co-authored-by: Mohammed Nihal <[email protected]>
Co-authored-by: Rithvik Nishad <[email protected]>
Co-authored-by: Ashesh <[email protected]>
Co-authored-by: Kshitij Verma <[email protected]>
  • Loading branch information
5 people authored Sep 7, 2023
1 parent 3f1a0cb commit e1f00fa
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 50 deletions.
41 changes: 40 additions & 1 deletion cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// FacilityCreation
import { cy, describe, before, beforeEach, it, afterEach } from "local-cypress";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import LoginPage from "../../pageobject/Login/LoginPage";

describe("Facility Creation", () => {
let facilityUrl: string;
const facilityPage = new FacilityPage();
const loginPage = new LoginPage();
const phone_number = "9999999999";

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

Expand Down Expand Up @@ -51,6 +55,7 @@ describe("Facility Creation", () => {
facilityPage.visitUpdateFacilityPage(facilityUrl);
facilityPage.clickManageFacilityDropdown();
facilityPage.clickUpdateFacilityOption();
facilityPage.clickUpdateFacilityType();
facilityPage.fillFacilityName("cypress facility updated");
facilityPage.fillAddress("Cypress Facility Updated Address");
facilityPage.fillOxygenCapacity("100");
Expand All @@ -61,6 +66,40 @@ describe("Facility Creation", () => {
cy.url().should("not.include", "/update");
});

it("Configure the existing facility", () => {
facilityPage.visitUpdateFacilityPage(facilityUrl);
facilityPage.clickManageFacilityDropdown();
facilityPage.clickConfigureFacilityOption();
facilityPage.fillMiddleWareAddress("dev_middleware.coronasafe.live");
facilityPage.clickupdateMiddleWare();
facilityPage.verifySuccessNotification("Facility updated successfully");
});

it("Create a resource request", () => {
facilityPage.visitUpdateFacilityPage(facilityUrl);
facilityPage.clickManageFacilityDropdown();
facilityPage.clickResourceRequestOption();
facilityPage.fillResourceRequestDetails(
"Test User",
phone_number,
"cypress",
"Test title",
"10",
"Test description"
);
facilityPage.clickSubmitRequestButton();
facilityPage.verifySuccessNotification(
"Resource request created successfully"
);
});

it("Delete a facility", () => {
facilityPage.visitUpdateFacilityPage(facilityUrl);
facilityPage.clickManageFacilityDropdown();
facilityPage.clickDeleteFacilityOption();
facilityPage.confirmDeleteFacility();
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
28 changes: 13 additions & 15 deletions cypress/e2e/facility_spec/inventory.cy.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import { cy, describe, before, beforeEach, it, afterEach } from "local-cypress";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import LoginPage from "../../pageobject/Login/LoginPage";

describe("Inventory Management Section", () => {
const facilityPage = new FacilityPage();
const loginPage = new LoginPage();

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

beforeEach(() => {
cy.restoreLocalStorage();
cy.awaitUrl("/");
cy.viewport(1280, 720);
cy.intercept("GET", "**/api/v1/facility/**").as("getFacilities");
cy.get("[id='facility-details']").first().click();
cy.wait("@getFacilities").its("response.statusCode").should("eq", 200);
cy.get("#manage-facility-dropdown button").should("be.visible");
cy.get("[id='manage-facility-dropdown']").scrollIntoView().click();
cy.get("[id=inventory-management]").click();
});

it("Adds Inventory", () => {
cy.contains("Manage Inventory").click();
cy.get("div#id").click();
cy.get("div#id ul li").contains("Liquid Oxygen").click();
cy.get("div#isIncoming").click();
cy.get("div#isIncoming ul li").contains("Add Stock").click();
cy.get("[name='quantity']").type("120");
cy.get("button").contains("Add/Update Inventory").click();
cy.verifyNotification("Inventory created successfully");
facilityPage.visitAlreadyCreatedFacility();
facilityPage.clickManageFacilityDropdown();
facilityPage.clickInventoryManagementOption();
facilityPage.clickManageInventory();
facilityPage.fillInventoryDetails("Liquid Oxygen", "Add Stock", "120");
facilityPage.clickAddInventory();
facilityPage.verifySuccessNotification("Inventory created successfully");
});

afterEach(() => {
Expand Down
70 changes: 39 additions & 31 deletions cypress/e2e/resource_spec/resources.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
import LoginPage from "../../pageobject/Login/LoginPage";
import ResourcePage from "../../pageobject/Resource/ResourcePage";

describe("Resource Page", () => {
const loginPage = new LoginPage();
const resourcePage = new ResourcePage();

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

Expand All @@ -11,36 +16,39 @@ describe("Resource Page", () => {
cy.awaitUrl("/resource");
});

it("checks if all download button works", () => {
cy.get("svg.care-svg-icon__baseline.care-l-export").each(($button) => {
cy.intercept(/\/api\/v1\/resource/).as("resource_download");
cy.wrap($button).click({ force: true });
cy.wait("@resource_download").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
});
});

it("switch between active/completed", () => {
cy.intercept(/\/api\/v1\/resource/).as("resource");
cy.contains("Completed").click();
cy.wait("@resource").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.contains("Active").should("have.class", "text-primary-500");
cy.contains("Completed").should("have.class", "text-white");
cy.intercept(/\/api\/v1\/resource/).as("resource");
cy.contains("Active").click();
cy.wait("@resource").then((interception) => {
expect(interception.response.statusCode).to.equal(200);
});
cy.contains("Active").should("have.class", "text-white");
cy.contains("Completed").should("have.class", "text-primary-500");
});

it("switch between list view and board view", () => {
cy.contains("List View").click();
cy.contains("Board View").click();
it("Checks if all download button works", () => {
resourcePage.verifyDownloadButtonWorks();
});

it("Switch between active/completed", () => {
resourcePage.spyResourceApi();
resourcePage.clickCompletedResources();
resourcePage.verifyCompletedResources();
resourcePage.spyResourceApi();
resourcePage.clickActiveResources();
resourcePage.verifyActiveResources();
});

it("Switch between list view and board view", () => {
resourcePage.clickListViewButton();
resourcePage.clickBoardViewButton();
});

it("Update the status of resource", () => {
resourcePage.openAlreadyCreatedResource();
resourcePage.clickUpdateStatus();
resourcePage.updateStatus("APPROVED");
resourcePage.clickSubmitButton();
resourcePage.verifySuccessNotification(
"Resource request updated successfully"
);
});

it("Post comment for a resource", () => {
resourcePage.openAlreadyCreatedResource();
resourcePage.addCommentForResource("Test comment");
resourcePage.clickPostCommentButton();
resourcePage.verifySuccessNotification("Comment added successfully");
});

afterEach(() => {
Expand Down
106 changes: 106 additions & 0 deletions cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// FacilityPage.ts
import { cy } from "local-cypress";

class FacilityPage {
visitCreateFacilityPage() {
cy.intercept("GET", "**/facility/create").as("getCreateFacilities");
cy.visit("/facility/create");
cy.wait("@getCreateFacilities")
.its("response.statusCode")
.should("eq", 200);
}

visitUpdateFacilityPage(url: string) {
Expand All @@ -11,6 +17,14 @@ class FacilityPage {
cy.get("#manage-facility-dropdown button").should("be.visible");
}

clickUpdateFacilityType() {
cy.get("#facility_type")
.click()
.then(() => {
cy.get("[role='option']").contains("Request Approving Center").click();
});
}

fillFacilityName(name: string) {
cy.get("#name").clear().type(name);
}
Expand Down Expand Up @@ -99,13 +113,105 @@ class FacilityPage {
cy.get("#update-facility").contains("Update Facility").click();
}

clickConfigureFacilityOption() {
cy.get("#configure-facility").contains("Configure Facility").click();
}

clickInventoryManagementOption() {
cy.get("[id=inventory-management]").click();
}

clickResourceRequestOption() {
cy.get("#resource-request").contains("Resource Request").click();
}

clickDeleteFacilityOption() {
cy.get("#delete-facility").contains("Delete Facility").click();
}

confirmDeleteFacility() {
cy.intercept("DELETE", "**/api/v1/facility/**").as("deleteFacility");
cy.get("#submit").contains("Delete").click();
cy.wait("@deleteFacility").its("response.statusCode").should("eq", 403);
}

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();
}

fillMiddleWareAddress(url: string) {
cy.get("#middleware_address").type(url);
}

clickupdateMiddleWare() {
cy.intercept("PATCH", "**/api/v1/facility/**").as("updateMiddleWare");
cy.get("button#submit").first().click();
cy.wait("@updateMiddleWare").its("response.statusCode").should("eq", 200);
}

verifySuccessNotification(message: string) {
cy.verifyNotification(message);
}

visitAlreadyCreatedFacility() {
cy.intercept("GET", "**/api/v1/facility/**").as("getFacilities");
cy.get("[id='facility-details']").first().click();
cy.wait("@getFacilities").its("response.statusCode").should("eq", 200);
cy.get("#manage-facility-dropdown button").should("be.visible");
cy.get("[id=manage-facility-dropdown]").scrollIntoView().click();
}

clickManageInventory() {
cy.contains("Manage Inventory").click();
}

fillInventoryDetails(name: string, status: string, quantity: string) {
cy.get("div#id").click();
cy.get("div#id ul li").contains(name).click();
cy.get("div#isIncoming").click();
cy.get("div#isIncoming ul li").contains(status).click();
cy.get("[name='quantity']").type(quantity);
}

clickAddInventory() {
cy.intercept("POST", "**/api/v1/facility/*/inventory/").as(
"createInventory"
);
cy.get("button").contains("Add/Update Inventory").click();
cy.wait("@createInventory").its("response.statusCode").should("eq", 201);
}

fillResourceRequestDetails(
name: string,
phone_number: string,
facility: string,
title: string,
quantity: string,
description: string
) {
cy.get("#refering_facility_contact_name").type(name);
cy.get("#refering_facility_contact_number").type(phone_number);
cy.get("[name='approving_facility']")
.type(facility)
.then(() => {
cy.get("[role='option']").first().click();
});
cy.get("#title").type(title);
cy.get("#requested_quantity").type(quantity);
cy.get("#reason").type(description);
}

clickSubmitRequestButton() {
cy.intercept("POST", "**/api/v1/resource/").as("createResourceRequest");
cy.get("button").contains("Submit").click();
cy.wait("@createResourceRequest")
.its("response.statusCode")
.should("eq", 201);
}
}

export default FacilityPage;
2 changes: 2 additions & 0 deletions cypress/pageobject/Login/LoginPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// LoginPage.ts
import { cy } from "local-cypress";

class LoginPage {
loginAsDisctrictAdmin(): void {
cy.loginByApi("devdistrictadmin", "Coronasafe@123");
Expand Down
Loading

0 comments on commit e1f00fa

Please sign in to comment.