From 4775be49171cd33f52d213a89a2db7735e4b250b Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Fri, 5 Jan 2024 01:46:46 +0530 Subject: [PATCH] inventory management --- cypress/e2e/facility_spec/inventory.cy.ts | 55 +++++++++++++++++-- .../pageobject/Facility/FacilityCreation.ts | 10 ++++ src/Components/Facility/InventoryList.tsx | 2 + src/Components/Facility/InventoryLog.tsx | 5 +- src/Components/Facility/MinQuantityList.tsx | 2 + .../Facility/MinQuantityRequiredModal.tsx | 7 ++- 6 files changed, 74 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/facility_spec/inventory.cy.ts b/cypress/e2e/facility_spec/inventory.cy.ts index 79077d6e6a6..28210844604 100644 --- a/cypress/e2e/facility_spec/inventory.cy.ts +++ b/cypress/e2e/facility_spec/inventory.cy.ts @@ -16,16 +16,63 @@ 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("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 + cy.get("#PPE").contains("PPE").should("be.visible"); + cy.get("#PPE").contains("5").should("be.visible"); + // delete the last Entry + cy.get("#PPE").click(); + cy.get("#delete-last-entry").click(); + // verify the last entry deletion + cy.get("#row-0").contains("Added Stock").should("be.visible"); + cy.get("#row-1").contains("Used Stock").should("be.visible"); + cy.wait(3000); + cy.go(-1); + cy.get("#PPE").contains("PPE").should("be.visible"); + }); + + it("Add New Inventory | Verify Backend and manual Minimum", () => { + // Add Inventory facilityPage.clickManageInventory(); - facilityPage.fillInventoryDetails("Liquid Oxygen", "Add Stock", "120"); + facilityPage.fillInventoryDetails("PPE", "Add Stock", "5"); facilityPage.clickAddInventory(); facilityPage.verifySuccessNotification("Inventory created successfully"); + // Verify Backend minimum badge + cy.get(".badge-danger").contains("Low Stock").should("exist"); + // modify with manual minimum badge + cy.get("#add-minimum-quantity").click(); + 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 + cy.get("#update-minimum-quantity").first().click(); + cy.get("#quantity").click().clear().click().type("5"); + cy.get("#save-update-minimumquanitity").click(); + } else { + // Otherwise, click the 'set-minimum-quantity' element + cy.get("#set-minimum-quantity").click(); + facilityPage.fillInventoryMinimumDetails("PPE", "1"); + facilityPage.clickSetButton(); + } + }); + cy.get("#set-minimum-quantity").should("be.visible"); + cy.go(-1); + cy.get(".badge-danger").contains("Low Stock").should("not.be.visible"); }); afterEach(() => { diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index 2d6aa9ff375..399f7468b17 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, 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) => (