Skip to content

Commit

Permalink
Fixed Cypress Failure in Facility and Resource Page (ohcnetwork#6293)
Browse files Browse the repository at this point in the history
* Cypress failure

* Fix facility name
  • Loading branch information
nihal467 authored Sep 15, 2023
1 parent d790af0 commit 5ac9e15
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
30 changes: 3 additions & 27 deletions cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe("Facility Creation", () => {
let facilityUrl: string;
const facilityPage = new FacilityPage();
const loginPage = new LoginPage();
const phone_number = "9999999999";

before(() => {
loginPage.loginAsDisctrictAdmin();
Expand Down Expand Up @@ -40,14 +39,9 @@ describe("Facility Creation", () => {
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;
});
facilityPage.verifyfacilitynewurl();
cy.url().then((newUrl) => {
facilityUrl = newUrl;
});
});

Expand Down Expand Up @@ -75,24 +69,6 @@ describe("Facility Creation", () => {
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();
Expand Down
34 changes: 32 additions & 2 deletions cypress/e2e/resource_spec/resources.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
import LoginPage from "../../pageobject/Login/LoginPage";
import ResourcePage from "../../pageobject/Resource/ResourcePage";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";

describe("Resource Page", () => {
let createdResource: string;
const loginPage = new LoginPage();
const resourcePage = new ResourcePage();
const facilityPage = new FacilityPage();
const phone_number = "9999999999";

before(() => {
loginPage.loginAsDisctrictAdmin();
Expand Down Expand Up @@ -34,8 +38,34 @@ describe("Resource Page", () => {
resourcePage.clickBoardViewButton();
});

it("Create a resource request", () => {
cy.visit("/facility");
cy.get("#search").click().type("dummy facility 1");
cy.intercept("GET", "**/api/v1/facility/**").as("loadFacilities");
cy.get("#facility-details").click();
cy.wait("@loadFacilities").its("response.statusCode").should("eq", 200);
facilityPage.clickManageFacilityDropdown();
facilityPage.clickResourceRequestOption();
facilityPage.fillResourceRequestDetails(
"Test User",
phone_number,
"Dummy",
"Test title",
"10",
"Test description"
);
facilityPage.clickSubmitRequestButton();
facilityPage.verifySuccessNotification(
"Resource request created successfully"
);
facilityPage.verifyresourcenewurl();
cy.url().then((url) => {
createdResource = url;
});
});

it("Update the status of resource", () => {
resourcePage.openAlreadyCreatedResource();
cy.visit(createdResource);
resourcePage.clickUpdateStatus();
resourcePage.updateStatus("APPROVED");
resourcePage.clickSubmitButton();
Expand All @@ -45,7 +75,7 @@ describe("Resource Page", () => {
});

it("Post comment for a resource", () => {
resourcePage.openAlreadyCreatedResource();
cy.visit(createdResource);
resourcePage.addCommentForResource("Test comment");
resourcePage.clickPostCommentButton();
resourcePage.verifySuccessNotification("Comment added successfully");
Expand Down
10 changes: 10 additions & 0 deletions cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class FacilityPage {
}

saveAndExitDoctorForm() {
cy.intercept("GET", "**/api/v1/facility/**").as("createFacilities");
cy.get("button#save-and-exit").click();
cy.wait("@createFacilities").its("response.statusCode").should("eq", 200);
}

clickManageFacilityDropdown() {
Expand Down Expand Up @@ -131,6 +133,14 @@ class FacilityPage {
cy.get("#delete-facility").contains("Delete Facility").click();
}

verifyfacilitynewurl() {
cy.url().should("match", /facility\/[a-z\d-]+/);
}

verifyresourcenewurl() {
cy.url().should("match", /resource\/[a-z\d-]+/);
}

confirmDeleteFacility() {
cy.intercept("DELETE", "**/api/v1/facility/**").as("deleteFacility");
cy.get("#submit").contains("Delete").click();
Expand Down
4 changes: 0 additions & 4 deletions cypress/pageobject/Resource/ResourcePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ class ResourcePage {
cy.contains("Board View").click();
}

openAlreadyCreatedResource() {
cy.get("[data-testid='resource-details']").first().click();
}

clickUpdateStatus() {
cy.get("[data-testid='update-status']").click();
}
Expand Down

0 comments on commit 5ac9e15

Please sign in to comment.