Skip to content

Commit

Permalink
Create cypress test for asset transaction and service history's (ohcn…
Browse files Browse the repository at this point in the history
…etwork#6349)

* Asset page redirection

* Test for asset transaction and service history
  • Loading branch information
nihal467 authored Sep 26, 2023
1 parent 2973d6e commit 0a7bee3
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 9 deletions.
54 changes: 54 additions & 0 deletions cypress/e2e/assets_spec/assets_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
74 changes: 74 additions & 0 deletions cypress/pageobject/Asset/AssetCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 0 additions & 2 deletions cypress/pageobject/Facility/FacilityCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 14 additions & 3 deletions src/Components/Assets/AssetManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ const AssetManage = (props: AssetManageProps) => {
</td>
<td className="gap-4 whitespace-nowrap px-6 py-4 text-left text-sm leading-5">
<ButtonV2
id="edit-service-history"
authorizeFor={NonReadOnlyUsers}
onClick={() => {
setServiceEditData({ ...service, open: true });
Expand All @@ -240,6 +241,7 @@ const AssetManage = (props: AssetManageProps) => {
<CareIcon icon="l-pen" className="text-lg" />
</ButtonV2>
<ButtonV2
id="view-service-history"
authorizeFor={NonReadOnlyUsers}
tooltip={service.edits?.length < 2 ? "No previous edits" : ""}
tooltipClassName="tooltip-left"
Expand Down Expand Up @@ -296,7 +298,10 @@ const AssetManage = (props: AssetManageProps) => {
</div>
<div className="break-words text-gray-700">{item.label}</div>
</div>
<div className="ml-8 grow-0 break-words text-lg font-semibold">
<div
className="ml-8 grow-0 break-words text-lg font-semibold"
id="asset-current-location"
>
{item.content || "--"}
</div>
</div>
Expand Down Expand Up @@ -513,7 +518,10 @@ const AssetManage = (props: AssetManageProps) => {
asset?.asset_class &&
asset?.asset_class != AssetClass.NONE && <Uptime assetId={asset?.id} />}
<div className="mb-4 mt-8 text-xl font-semibold">Service History</div>
<div className="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg">
<div
className="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg"
id="service-history"
>
<table className="min-w-full divide-y divide-gray-200">
<thead>
<tr>
Expand All @@ -540,7 +548,10 @@ const AssetManage = (props: AssetManageProps) => {
</table>
</div>
<div className="mb-4 mt-8 text-xl font-semibold">Transaction History</div>
<div className="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg">
<div
className="min-w-full overflow-hidden overflow-x-auto align-middle shadow sm:rounded-lg"
id="transaction-history"
>
<table className="min-w-full divide-y divide-gray-200">
<thead>
<tr>
Expand Down
15 changes: 12 additions & 3 deletions src/Components/Assets/AssetServiceEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export const AssetServiceEditModal = (props: {
{edit.edited_by.username}
</p>
</div>
<div className="flex items-center justify-center">
<div
className="flex items-center justify-center"
id="view-asset-edit-history"
>
<CareIcon icon="l-eye" className="text-lg" />
</div>
</div>
Expand All @@ -124,19 +127,25 @@ export const AssetServiceEditModal = (props: {
<p className="text-sm font-medium text-gray-500">
Serviced On
</p>
<p className="text-gray-900">
<p
className="text-gray-900"
id="edit-history-asset-servicedon"
>
{formatDate(editRecord.serviced_on)}
</p>
</div>
<div className="mt-4 grow">
<p className="text-sm font-medium text-gray-500">Notes</p>
<p className="text-gray-900">{editRecord.note || "-"}</p>
<p className="text-gray-900" id="edit-history-asset-note">
{editRecord.note || "-"}
</p>
</div>
</div>
</div>
)}
<div className="flex justify-end">
<ButtonV2
id="view-history-back-button"
variant="secondary"
onClick={() => {
editRecord ? setEditRecord(undefined) : props.handleClose();
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
<span>{value?.icon}</span>

{value && !props.isLoading && !props.required && (
<div className="tooltip">
<div className="tooltip" id="clear-button">
<CareIcon
className="care-l-times-circle h-4 w-4 text-gray-800 transition-colors duration-200 ease-in-out hover:text-gray-500"
onClick={(e) => {
Expand Down

0 comments on commit 0a7bee3

Please sign in to comment.