Date: Tue, 26 Sep 2023 15:17:19 +0530
Subject: [PATCH 13/16] Create cypress test for asset transaction and service
history's (#6349)
* Asset page redirection
* Test for asset transaction and service history
---
cypress/e2e/assets_spec/assets_manage.cy.ts | 54 ++++++++++++++
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, 155 insertions(+), 9 deletions(-)
diff --git a/cypress/e2e/assets_spec/assets_manage.cy.ts b/cypress/e2e/assets_spec/assets_manage.cy.ts
index 1f89facd0a3..34c554b374e 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,6 +26,57 @@ describe("Asset", () => {
cy.awaitUrl("/assets");
});
+ 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", () => {
+ 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();
+ });
+
it("Delete an Asset", () => {
assetPage.openCreatedAsset();
assetPage.interceptDeleteAssetApi();
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 4565c48b33d..84325d704aa 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}
-
@@ -513,7 +518,10 @@ const AssetManage = (props: AssetManageProps) => {
asset?.asset_class &&
asset?.asset_class != AssetClass.NONE && }
Service History
-
+
@@ -540,7 +548,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 bbc60643faf..c4b3ea3686e 100644
--- a/src/Components/Form/FormFields/Autocomplete.tsx
+++ b/src/Components/Form/FormFields/Autocomplete.tsx
@@ -165,7 +165,7 @@ export const Autocomplete = (props: AutocompleteProps) => {
{value?.icon}
{value && !props.isLoading && !props.required && (
- |