diff --git a/cypress/e2e/facility_spec/facility.cy.ts b/cypress/e2e/facility_spec/facility.cy.ts index f8fe04b4f30..f2ff847c9d9 100644 --- a/cypress/e2e/facility_spec/facility.cy.ts +++ b/cypress/e2e/facility_spec/facility.cy.ts @@ -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(); @@ -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; }); }); @@ -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(); diff --git a/cypress/e2e/resource_spec/resources.cy.ts b/cypress/e2e/resource_spec/resources.cy.ts index b3393d0942b..93b1056e75d 100644 --- a/cypress/e2e/resource_spec/resources.cy.ts +++ b/cypress/e2e/resource_spec/resources.cy.ts @@ -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(); @@ -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, + "cypress", + "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(); @@ -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"); diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index aa46d4f1105..ef4e65781e0 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -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() { @@ -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(); diff --git a/cypress/pageobject/Resource/ResourcePage.ts b/cypress/pageobject/Resource/ResourcePage.ts index 1fecf86b9e1..f7feac925bf 100644 --- a/cypress/pageobject/Resource/ResourcePage.ts +++ b/cypress/pageobject/Resource/ResourcePage.ts @@ -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(); }