Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Cypress Test | Facility Inventory Management | Facility Module #6979

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions cypress/e2e/facility_spec/inventory.cy.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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();
});
Expand Down
50 changes: 50 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 Expand Up @@ -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;
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
Loading