From 89d91ec0925981ca9c535001f49133ed3f7ee5a2 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Wed, 20 Sep 2023 02:34:13 +0530 Subject: [PATCH 1/2] Asset page redirection --- cypress/e2e/assets_spec/assets_manage.cy.ts | 24 +++++++++++++ .../pageobject/Facility/FacilityCreation.ts | 35 +++++++++++++++++++ src/Components/Facility/FacilityHome.tsx | 3 ++ 3 files changed, 62 insertions(+) diff --git a/cypress/e2e/assets_spec/assets_manage.cy.ts b/cypress/e2e/assets_spec/assets_manage.cy.ts index f27fd302a0c..1f89facd0a3 100644 --- a/cypress/e2e/assets_spec/assets_manage.cy.ts +++ b/cypress/e2e/assets_spec/assets_manage.cy.ts @@ -1,10 +1,17 @@ import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress"; import { AssetPage } from "../../pageobject/Asset/AssetCreation"; import LoginPage from "../../pageobject/Login/LoginPage"; +import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch"; +import FacilityPage from "../../pageobject/Facility/FacilityCreation"; +import { AssetFilters } from "../../pageobject/Asset/AssetFilters"; describe("Asset", () => { const assetPage = new AssetPage(); const loginPage = new LoginPage(); + const facilityPage = new FacilityPage(); + const assetSearchPage = new AssetSearchPage(); + const assetFilters = new AssetFilters(); + const fillFacilityName = "Dummy Facility 1"; before(() => { loginPage.loginAsDisctrictAdmin(); @@ -23,6 +30,23 @@ describe("Asset", () => { assetPage.verifyDeleteStatus(); }); + it("Verify Facility Asset Page Redirection", () => { + cy.visit("/facility"); + assetSearchPage.typeSearchKeyword(fillFacilityName); + assetSearchPage.pressEnter(); + facilityPage.verifyFacilityBadgeContent(fillFacilityName); + facilityPage.visitAlreadyCreatedFacility(); + facilityPage.clickManageFacilityDropdown(); + facilityPage.clickCreateAssetFacilityOption(); + facilityPage.verifyfacilitycreateassetredirection(); + facilityPage.verifyassetfacilitybackredirection(); + facilityPage.clickManageFacilityDropdown(); + facilityPage.clickviewAssetFacilityOption(); + facilityPage.verifyfacilityviewassetredirection(); + assetFilters.assertFacilityText(fillFacilityName); + facilityPage.verifyassetfacilitybackredirection(); + }); + afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index ef4e65781e0..0c12d4655fd 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -120,6 +120,14 @@ class FacilityPage { cy.get("#configure-facility").contains("Configure Facility").click(); } + clickCreateAssetFacilityOption() { + cy.get("#create-assets").contains("Create Asset").click(); + } + + clickviewAssetFacilityOption() { + cy.get("#view-assets").contains("View Assets").click(); + } + clickInventoryManagementOption() { cy.get("#inventory-management", { timeout: 10000 }).should("be.visible"); cy.get("#inventory-management").click(); @@ -175,6 +183,33 @@ class FacilityPage { cy.wait("@getFacilities").its("response.statusCode").should("eq", 200); } + verifyFacilityBadgeContent(expectedText: string) { + cy.get("[data-testid='Facility/District Name']").should( + "contain", + expectedText + ); + } + + verifyfacilitycreateassetredirection() { + cy.intercept("GET", "**/api/v1/facility/**").as("getNewAssets"); + cy.url().should("include", "/assets/new"); + cy.wait("@getNewAssets").its("response.statusCode").should("eq", 200); + } + + verifyassetfacilitybackredirection() { + cy.intercept("GET", "**/api/v1/facility/**").as("getManagePage"); + cy.go("back"); + cy.wait("@getManagePage").its("response.statusCode").should("eq", 200); + cy.get("#manage-facility-dropdown").scrollIntoView(); + cy.get("#manage-facility-dropdown").should("exist"); + } + + verifyfacilityviewassetredirection() { + cy.intercept("GET", "**api/v1/getallfacilities/**").as("getViewAssets"); + cy.url().should("include", "/assets?facility="); + cy.wait("@getViewAssets").its("response.statusCode").should("eq", 200); + } + clickManageInventory() { cy.contains("Manage Inventory").click(); } diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index 81e7fa4906f..15317b1b56c 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -575,6 +575,7 @@ export const FacilityHome = (props: any) => { Resource Request navigate(`/facility/${facilityId}/assets/new`)} authorizeFor={NonReadOnlyUsers} icon={} @@ -582,12 +583,14 @@ export const FacilityHome = (props: any) => { Create Asset navigate(`/assets?facility=${facilityId}`)} icon={} > View Assets navigate(`/facility/${facilityId}/users`)} icon={} > From 7f55921ae0d63f6aa4644fd06d586ee494fb8cd0 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:46:22 +0530 Subject: [PATCH 2/2] Test for asset transaction and service history --- cypress/e2e/assets_spec/assets_manage.cy.ts | 47 ++++++++++-- cypress/pageobject/Asset/AssetCreation.ts | 74 +++++++++++++++++++ .../pageobject/Facility/FacilityCreation.ts | 2 - src/Components/Assets/AssetManage.tsx | 17 ++++- .../Assets/AssetServiceEditModal.tsx | 15 +++- .../Form/FormFields/Autocomplete.tsx | 2 +- 6 files changed, 143 insertions(+), 14 deletions(-) diff --git a/cypress/e2e/assets_spec/assets_manage.cy.ts b/cypress/e2e/assets_spec/assets_manage.cy.ts index 1f89facd0a3..4748de92beb 100644 --- a/cypress/e2e/assets_spec/assets_manage.cy.ts +++ b/cypress/e2e/assets_spec/assets_manage.cy.ts @@ -12,6 +12,9 @@ describe("Asset", () => { const assetSearchPage = new AssetSearchPage(); const assetFilters = new AssetFilters(); const fillFacilityName = "Dummy Facility 1"; + const assetname = "Dummy Camera"; + const locationName = "Dummy Location 1"; + const initiallocationName = "Camera Location"; before(() => { loginPage.loginAsDisctrictAdmin(); @@ -23,11 +26,38 @@ describe("Asset", () => { cy.awaitUrl("/assets"); }); - it("Delete an Asset", () => { - assetPage.openCreatedAsset(); - assetPage.interceptDeleteAssetApi(); - assetPage.deleteAsset(); - assetPage.verifyDeleteStatus(); + it("Create & Edit a service history and verify reflection", () => { + assetSearchPage.typeSearchKeyword(assetname); + assetSearchPage.pressEnter(); + assetSearchPage.verifyBadgeContent(assetname); + assetSearchPage.clickAssetByName(assetname); + assetPage.clickupdatedetailbutton(); + assetPage.scrollintonotes(); + assetPage.enterAssetNotes("Dummy Notes"); + assetPage.enterAssetservicedate("01092023"); + assetPage.clickassetupdatebutton(); + assetPage.scrollintoservicehistory(); + assetPage.clickedithistorybutton(); + assetPage.scrollintonotes(); + assetPage.enterAssetNotes("Dummy Notes Editted"); + assetPage.clickassetupdatebutton(); + assetPage.scrollintoservicehistory(); + assetPage.viewassetservicehistorybutton(); + assetPage.openassetservicehistory(); + assetPage.verifyassetupdateservicehistory(); + assetPage.viewassetservicehistorybutton(); + }); + + it("Create a asset transaction and verify history", () => { + assetSearchPage.typeSearchKeyword(assetname); + assetSearchPage.pressEnter(); + assetSearchPage.verifyBadgeContent(assetname); + assetSearchPage.clickAssetByName(assetname); + assetPage.clickupdatedetailbutton(); + assetPage.clickassetlocation(locationName); + assetPage.clickUpdateAsset(); + assetPage.verifyassetlocation(locationName); + assetPage.verifytransactionStatus(initiallocationName, locationName); }); it("Verify Facility Asset Page Redirection", () => { @@ -47,6 +77,13 @@ describe("Asset", () => { facilityPage.verifyassetfacilitybackredirection(); }); + it("Delete an Asset", () => { + assetPage.openCreatedAsset(); + assetPage.interceptDeleteAssetApi(); + assetPage.deleteAsset(); + assetPage.verifyDeleteStatus(); + }); + afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/pageobject/Asset/AssetCreation.ts b/cypress/pageobject/Asset/AssetCreation.ts index b939c31405f..45356a1a4e7 100644 --- a/cypress/pageobject/Asset/AssetCreation.ts +++ b/cypress/pageobject/Asset/AssetCreation.ts @@ -276,4 +276,78 @@ export class AssetPage { cy.get("#submit").contains("Import").click(); cy.wait("@importAsset").its("response.statusCode").should("eq", 201); } + + clickupdatedetailbutton() { + cy.get("[data-testid=asset-update-button]").click(); + } + + scrollintonotes() { + cy.get("#notes").scrollIntoView(); + } + + enterAssetNotes(text) { + cy.get("#notes").click().clear(); + cy.get("#notes").click().type(text); + } + + enterAssetservicedate(text) { + cy.get("input[name='last_serviced_on']").click(); + cy.get("#date-input").click().type(text); + } + + clickassetupdatebutton() { + cy.get("#submit").click(); + } + + viewassetservicehistorybutton() { + cy.get("#view-service-history").should("be.visible"); + } + + openassetservicehistory() { + cy.get("#view-service-history").click(); + cy.get("#view-asset-edit-history").first().click(); + } + + verifyassetupdateservicehistory() { + cy.get("#edit-history-asset-servicedon").should("have.text", "01/09/2023"); + cy.get("#edit-history-asset-note").should( + "have.text", + "Dummy Notes Editted" + ); + cy.get("#view-history-back-button").contains("Back").click(); + cy.get("#view-history-back-button").contains("Close").click(); + } + + scrollintoservicehistory() { + cy.get("#service-history").scrollIntoView(); + } + + clickedithistorybutton() { + cy.get("#edit-service-history").click(); + } + + verifytransactionStatus(initiallocationName: string, locationName: string) { + cy.get("#transaction-history").scrollIntoView(); + cy.get("#transaction-history table tbody tr:first-child td:eq(0)").should( + "contain", + initiallocationName + ); + cy.get("#transaction-history table tbody tr:first-child td:eq(1)").should( + "contain", + locationName + ); + } + + verifyassetlocation(locationName: string) { + cy.get("#asset-current-location").should("contain", locationName); + } + + clickassetlocation(locationName: string) { + cy.get("#clear-button").click(); + cy.get("[data-testid=asset-location-input] button").click(); + cy.get("[data-testid=asset-location-input] button") + .click() + .type(locationName); + cy.get("[role='option']").contains(locationName).click(); + } } diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index 0c12d4655fd..b6285bff72b 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -205,9 +205,7 @@ class FacilityPage { } verifyfacilityviewassetredirection() { - cy.intercept("GET", "**api/v1/getallfacilities/**").as("getViewAssets"); cy.url().should("include", "/assets?facility="); - cy.wait("@getViewAssets").its("response.statusCode").should("eq", 200); } clickManageInventory() { diff --git a/src/Components/Assets/AssetManage.tsx b/src/Components/Assets/AssetManage.tsx index 1df9fbde9a6..a173289fc8a 100644 --- a/src/Components/Assets/AssetManage.tsx +++ b/src/Components/Assets/AssetManage.tsx @@ -231,6 +231,7 @@ const AssetManage = (props: AssetManageProps) => { { setServiceEditData({ ...service, open: true }); @@ -240,6 +241,7 @@ const AssetManage = (props: AssetManageProps) => { {
{item.label}
-
+
{item.content || "--"}
@@ -514,7 +519,10 @@ const AssetManage = (props: AssetManageProps) => { asset?.asset_class && asset?.asset_class != AssetClass.NONE && }
Service History
-
+
@@ -541,7 +549,10 @@ const AssetManage = (props: AssetManageProps) => {
Transaction History
-
+
diff --git a/src/Components/Assets/AssetServiceEditModal.tsx b/src/Components/Assets/AssetServiceEditModal.tsx index 75c9dd9fc60..66d44d11907 100644 --- a/src/Components/Assets/AssetServiceEditModal.tsx +++ b/src/Components/Assets/AssetServiceEditModal.tsx @@ -97,7 +97,10 @@ export const AssetServiceEditModal = (props: { {edit.edited_by.username}

-
+
@@ -124,19 +127,25 @@ export const AssetServiceEditModal = (props: {

Serviced On

-

+

{formatDate(editRecord.serviced_on)}

Notes

-

{editRecord.note || "-"}

+

+ {editRecord.note || "-"} +

)}
{ editRecord ? setEditRecord(undefined) : props.handleClose(); diff --git a/src/Components/Form/FormFields/Autocomplete.tsx b/src/Components/Form/FormFields/Autocomplete.tsx index dcf3ab5e8b6..7a2c37351e4 100644 --- a/src/Components/Form/FormFields/Autocomplete.tsx +++ b/src/Components/Form/FormFields/Autocomplete.tsx @@ -164,7 +164,7 @@ export const Autocomplete = (props: AutocompleteProps) => { {value?.icon} {value && !props.isLoading && !props.required && ( -
+
{