Skip to content

Commit

Permalink
inventory management
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 committed Jan 4, 2024
1 parent 9f1b29c commit 4775be4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
55 changes: 51 additions & 4 deletions cypress/e2e/facility_spec/inventory.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
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 @@ -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"
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Facility/InventoryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function InventoryList(props: any) {
if (inventory?.length) {
inventoryList = inventory.map((inventoryItem: any) => (
<tr
id={`${inventoryItem.item_object?.name.replaceAll(" ", "-")}`}
key={inventoryItem.id}
className={classNames(
"cursor-pointer hover:bg-gray-200",
Expand Down Expand Up @@ -166,6 +167,7 @@ export default function InventoryList(props: any) {
Manage Inventory
</ButtonV2>
<ButtonV2
id="add-minimum-quantity"
className="w-full"
href={`/facility/${facilityId}/inventory/min_quantity/list`}
>
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Facility/InventoryLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export default function InventoryLog(props: any) {

let inventoryList: any = [];
if (inventory?.length) {
inventoryList = inventory.map((inventoryItem: any) => (
<tr key={inventoryItem.id} className="bg-white">
inventoryList = inventory.map((inventoryItem: any, index) => (
<tr id={`row-${index}`} key={inventoryItem.id} className="bg-white">
<td className="border-b border-gray-200 p-5 text-sm hover:bg-gray-100">
<div className="flex items-center">
<div className="ml-3">
Expand Down Expand Up @@ -270,6 +270,7 @@ export default function InventoryLog(props: any) {
as accident.
</div>
<ButtonV2
id="delete-last-entry"
variant="danger"
onClick={(_) =>
removeLastInventoryLog(inventory[0].item_object.id)
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Facility/MinQuantityList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default function MinQuantityList(props: any) {
{inventoryItem.item_object?.default_unit?.name}
</p>
<ButtonV2
id="update-minimum-quantity"
variant="secondary"
ghost
border
Expand Down Expand Up @@ -219,6 +220,7 @@ export default function MinQuantityList(props: any) {
<div className="container mx-auto px-4 sm:px-8">
<div className="py-8">
<ButtonV2
id="set-minimum-quantity"
className="ml-2"
href={`/facility/${facilityId}/inventory/min_quantity/set`}
authorizeFor={NonReadOnlyUsers}
Expand Down
7 changes: 6 additions & 1 deletion src/Components/Facility/MinQuantityRequiredModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ export const MinQuantityRequiredModal = (props: any) => {
/>
</div>
<div className="flex justify-end">
<ButtonV2 variant="primary" onClick={handleSubmit} className="mr-2">
<ButtonV2
variant="primary"
onClick={handleSubmit}
className="mr-2"
id="save-update-minimumquanitity"
>
Update
</ButtonV2>
<ButtonV2 variant="secondary" onClick={handleClose}>
Expand Down

0 comments on commit 4775be4

Please sign in to comment.