diff --git a/cypress/e2e/facility_spec/inventory.cy.ts b/cypress/e2e/facility_spec/inventory.cy.ts index 79077d6e6a6..e7f1c35cb93 100644 --- a/cypress/e2e/facility_spec/inventory.cy.ts +++ b/cypress/e2e/facility_spec/inventory.cy.ts @@ -1,10 +1,12 @@ import { cy, describe, before, beforeEach, it, afterEach } from "local-cypress"; import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import LoginPage from "../../pageobject/Login/LoginPage"; +import FacilityHome from "../../pageobject/Facility/FacilityHome"; describe("Inventory Management Section", () => { const facilityPage = new FacilityPage(); const loginPage = new LoginPage(); + const facilityHome = new FacilityHome(); before(() => { loginPage.loginAsDisctrictAdmin(); @@ -16,18 +18,64 @@ describe("Inventory Management Section", () => { cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/"); cy.viewport(1280, 720); - }); - - it("Adds Inventory", () => { facilityPage.visitAlreadyCreatedFacility(); facilityPage.clickManageFacilityDropdown(); facilityPage.clickInventoryManagementOption(); + }); + + it("Add New Inventory | Modify data and delete last entry ", () => { + // add a new item facilityPage.clickManageInventory(); - facilityPage.fillInventoryDetails("Liquid Oxygen", "Add Stock", "120"); + facilityPage.fillInventoryDetails("PPE", "Add Stock", "10"); facilityPage.clickAddInventory(); facilityPage.verifySuccessNotification("Inventory created successfully"); + facilityPage.clickManageInventory(); + // modify the new item + facilityPage.fillInventoryDetails("PPE", "Use Stock", "5"); + facilityPage.clickAddInventory(); + facilityPage.verifySuccessNotification("Inventory created successfully"); + // verify the new modification + facilityPage.verifyPpeQuantity("PPE"); + facilityPage.verifyPpeQuantity("5"); + // delete the last Entry + facilityPage.clickPpeQuantity(); + facilityPage.clickLastEntry(); + // verify the last entry deletion + facilityPage.verifyStockInRow("#row-0", "Added Stock"); + facilityPage.verifyStockInRow("#row-1", "Used Stock"); + cy.wait(3000); + facilityHome.navigateBack(); + facilityPage.verifyPpeQuantity("PPE"); }); + it("Add New Inventory | Verify Backend and manual Minimum", () => { + // Add Inventory + facilityPage.clickManageInventory(); + facilityPage.fillInventoryDetails("PPE", "Add Stock", "5"); + facilityPage.clickAddInventory(); + facilityPage.verifySuccessNotification("Inventory created successfully"); + // Verify Backend minimum badge + facilityPage.verifyBadgeWithText(".badge-danger", "Low Stock"); + // modify with manual minimum badge + facilityPage.clickAddMinimumQuanitity(); + cy.wait(3000); + cy.get("body").then(($body) => { + if ($body.find("#update-minimum-quantity").is(":visible")) { + // If the 'update-minimum-quantity' element is visible, click it + facilityPage.clickUpdateMinimumQuantity(); + facilityPage.setQuantity("5"); + facilityPage.clickSaveUpdateMinimumQuantity(); + } else { + // Otherwise, click the 'set-minimum-quantity' element + facilityPage.clickSetMinimumQuantity(); + facilityPage.fillInventoryMinimumDetails("PPE", "1"); + facilityPage.clickSetButton(); + facilityPage.verifySuccessNotification( + "Minimum quantiy updated successfully" + ); + } + }); + }); afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index 2d6aa9ff375..bb6cf0e19f2 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -372,6 +372,12 @@ class FacilityPage { cy.get("[name='quantity']").type(quantity); } + fillInventoryMinimumDetails(name: string, quantity: string) { + cy.get("div#id").click(); + cy.get("div#id ul li").contains(name).click(); + cy.get("[name='quantity']").type(quantity); + } + clickAddInventory() { cy.intercept("POST", "**/api/v1/facility/*/inventory/").as( "createInventory" @@ -380,6 +386,10 @@ class FacilityPage { cy.wait("@createInventory").its("response.statusCode").should("eq", 201); } + clickSetButton() { + cy.get("#submit").contains("Set").click(); + } + fillResourceRequestDetails( name: string, phone_number: string, @@ -443,6 +453,46 @@ class FacilityPage { } }); } + + verifyPpeQuantity(text: string) { + cy.get("#PPE").contains(text).should("be.visible"); + } + + clickPpeQuantity() { + cy.get("#PPE").click(); + } + + clickLastEntry() { + cy.get("#delete-last-entry").click(); + } + + verifyStockInRow(rowId: string, stockText: string) { + cy.get(rowId).contains(stockText).should("be.visible"); + } + + verifyBadgeWithText(badgeClass: string, text: string) { + cy.get(badgeClass).contains(text).should("exist"); + } + + clickAddMinimumQuanitity() { + cy.get("#add-minimum-quantity").click(); + } + + clickUpdateMinimumQuantity() { + cy.get("#update-minimum-quantity").first().click(); + } + + setQuantity(quantity: string) { + cy.get("#quantity").click().clear().click().type(quantity); + } + + clickSaveUpdateMinimumQuantity() { + cy.get("#save-update-minimumquanitity").click(); + } + + clickSetMinimumQuantity() { + cy.get("#set-minimum-quantity").click(); + } } export default FacilityPage; diff --git a/src/Components/Facility/InventoryList.tsx b/src/Components/Facility/InventoryList.tsx index 26f1af87191..837b0b2ce2a 100644 --- a/src/Components/Facility/InventoryList.tsx +++ b/src/Components/Facility/InventoryList.tsx @@ -71,6 +71,7 @@ export default function InventoryList(props: any) { if (inventory?.length) { inventoryList = inventory.map((inventoryItem: any) => (