Skip to content

Commit

Permalink
Merge branch 'develop' into issue#6434
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored Oct 18, 2023
2 parents ed57d50 + a92ad24 commit 5d5f933
Show file tree
Hide file tree
Showing 52 changed files with 920 additions and 812 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/assets_spec/asset_homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe("Asset Tab", () => {
assetPage.selectImportOption();
assetPage.selectImportFacility("Dummy Facility 1");
assetPage.importAssetFile();
assetPage.selectImportLocation("Camera Loc");
assetPage.selectImportLocation("Camera Locations");
assetPage.clickImportAsset();
});

Expand Down
33 changes: 33 additions & 0 deletions cypress/e2e/assets_spec/assets_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import { AssetFilters } from "../../pageobject/Asset/AssetFilters";

function addDaysToDate(numberOfDays: number) {
const inputDate = new Date();
inputDate.setDate(inputDate.getDate() + numberOfDays);
return inputDate.toISOString().split("T")[0];
}

describe("Asset", () => {
const assetPage = new AssetPage();
const loginPage = new LoginPage();
Expand All @@ -26,6 +32,33 @@ describe("Asset", () => {
cy.awaitUrl("/assets");
});

it("Verify Asset Warranty Expiry Label", () => {
assetSearchPage.typeSearchKeyword(assetname);
assetSearchPage.pressEnter();
assetSearchPage.verifyBadgeContent(assetname);
assetSearchPage.clickAssetByName(assetname);
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(100)); // greater than 3 months
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("");
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(80)); // less than 3 months
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("3 months");
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(20)); // less than 1 month
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("1 month");
assetPage.clickupdatedetailbutton();
assetPage.scrollintoWarrantyDetails();
assetPage.enterWarrantyExpiryDate(addDaysToDate(100)); // check for greater than 3 months again to verify the label is removed
assetPage.clickassetupdatebutton();
assetPage.verifyWarrantyExpiryLabel("");
});

it("Create & Edit a service history and verify reflection", () => {
assetSearchPage.typeSearchKeyword(assetname);
assetSearchPage.pressEnter();
Expand Down
29 changes: 26 additions & 3 deletions cypress/pageobject/Asset/AssetCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class AssetPage {

configureVitalAsset(hostName: string, localIp: string) {
cy.get("[data-testid=asset-configure-button]").click();
cy.get("#middlewareHostname").type(hostName);
cy.get("#middleware_hostname").type(hostName);
cy.get("#localipAddress").type(localIp);
}

Expand Down Expand Up @@ -285,16 +285,39 @@ export class AssetPage {
cy.get("#notes").scrollIntoView();
}

enterAssetNotes(text) {
enterAssetNotes(text: string) {
cy.get("#notes").click().clear();
cy.get("#notes").click().type(text);
}

enterAssetservicedate(text) {
enterAssetservicedate(text: string) {
cy.get("input[name='last_serviced_on']").click();
cy.get("#date-input").click().type(text);
}

scrollintoWarrantyDetails() {
cy.get("#warranty-details").scrollIntoView();
}

enterWarrantyExpiryDate(text: string) {
cy.get("#WarrantyAMCExpiry").click();
cy.get("#WarrantyAMCExpiry").click().type(text);
}

verifyWarrantyExpiryLabel(duration: string) {
if (duration === "") {
cy.get("#warranty-amc-expired-red").should("not.exist");
cy.get("#warranty-amc-expiring-soon-orange").should("not.exist");
cy.get("#warranty-amc-expiring-soon-yellow").should("not.exist");
} else if (duration === "expired") {
cy.get("#warranty-amc-expired-red").should("be.visible");
} else if (duration === "1 month") {
cy.get("#warranty-amc-expiring-soon-orange").should("be.visible");
} else if (duration === "3 months") {
cy.get("#warranty-amc-expiring-soon-yellow").should("be.visible");
}
}

clickassetupdatebutton() {
cy.get("#submit").click();
}
Expand Down
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"events": "^3.3.0",
"i18next": "^23.2.7",
"i18next-browser-languagedetector": "^7.1.0",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"postcss-loader": "^7.3.3",
"qrcode.react": "^3.1.0",
"raviger": "^4.1.2",
Expand Down Expand Up @@ -113,7 +113,7 @@
"@types/cypress": "^1.1.3",
"@types/echarts": "^4.9.18",
"@types/google.maps": "^3.53.4",
"@types/lodash": "^4.14.195",
"@types/lodash-es": "^4.17.9",
"@types/lodash.get": "^4.4.7",
"@types/node": "^20.4.0",
"@types/prop-types": "*",
Expand Down
2 changes: 2 additions & 0 deletions src/CAREUI/display/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Props {
text: string;
tooltip?: string;
className?: string;
id?: string;
}

export default function Chip({
Expand All @@ -21,6 +22,7 @@ export default function Chip({
}: Props) {
return (
<span
id={props?.id}
className={classNames(
"inline-flex items-center gap-2 font-medium leading-4",

Expand Down
2 changes: 1 addition & 1 deletion src/CAREUI/misc/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function useContextualized<TItem>() {
return ctx as PaginatedListContext<TItem>;
}

interface Props<TItem> extends QueryOptions {
interface Props<TItem> extends QueryOptions<PaginatedResponse<TItem>> {
route: QueryRoute<PaginatedResponse<TItem>>;
perPage?: number;
children: (ctx: PaginatedListContext<TItem>) => JSX.Element | JSX.Element[];
Expand Down
1 change: 1 addition & 0 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ export const TELEMEDICINE_ACTIONS = [
{ id: 60, text: "COMPLETE", desc: "Complete" },
{ id: 70, text: "REVIEW", desc: "Review" },
{ id: 80, text: "NOT_REACHABLE", desc: "Not Reachable" },
{ id: 90, text: "DISCHARGE_RECOMMENDED", desc: "Discharge Recommended" },
];

export const FRONTLINE_WORKER = [
Expand Down
2 changes: 1 addition & 1 deletion src/Common/hooks/useAsyncOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from "lodash";
import { debounce } from "lodash-es";
import { useMemo, useState } from "react";
import { useDispatch } from "react-redux";

Expand Down
79 changes: 27 additions & 52 deletions src/Components/Assets/AssetFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { useState, useEffect, useCallback } from "react";
import { useAbortableEffect, statusType } from "../../Common/utils";
import { navigate, useQueryParams } from "raviger";
import { FacilitySelect } from "../Common/FacilitySelect";
import { FacilityModel } from "../Facility/models";
import { useDispatch } from "react-redux";
import {
getFacilityAssetLocation,
getPermittedFacility,
} from "../../Redux/actions";
import * as Notification from "../../Utils/Notifications.js";
import { LocationSelect } from "../Common/LocationSelect";
import { AssetClass, AssetLocationObject } from "./AssetTypes";
import { FieldLabel } from "../Form/FormFields/FormField";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover";
import routes from "../../Redux/api";
import useQuery from "../../Utils/request/useQuery";
import DateRangeFormField from "../Form/FormFields/DateRangeFormField";
import dayjs from "dayjs";
import { FieldChangeEvent } from "../Form/FormFields/Utils";
Expand All @@ -35,7 +30,6 @@ const getDate = (value: any) =>

function AssetFilter(props: any) {
const { filter, onChange, closeFilter } = props;
const dispatch: any = useDispatch();
const [facility, setFacility] = useState<FacilityModel>({ name: "" });
const [location, setLocation] =
useState<AssetLocationObject>(initialLocation);
Expand All @@ -46,16 +40,39 @@ function AssetFilter(props: any) {
const [asset_class, setAssetClass] = useState<string>(
filter.asset_class || ""
);
const [facilityId, setFacilityId] = useState<number | "">(filter.facility);
const [facilityId, setFacilityId] = useState<string | "">(filter.facility);
const [locationId, setLocationId] = useState<string | "">(filter.location);
const [warrantyExpiry, setWarrantyExpiry] = useState({
before: filter.warranty_amc_end_of_validity_before || null,
after: filter.warranty_amc_end_of_validity_after || null,
});
const [qParams, _] = useQueryParams();

useQuery(routes.getPermittedFacility, {
pathParams: { id: facilityId },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setFacility(data);
}
},
prefetch: !!facilityId,
});

useQuery(routes.getFacilityAssetLocation, {
pathParams: {
facilityId: String(facilityId),
locationId: String(locationId),
},
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setLocation(data);
}
},
prefetch: !!(facilityId && locationId),
});

useEffect(() => {
setFacilityId(facility?.id ? facility?.id : "");
setFacilityId(facility?.id ? `${facility?.id}` : "");
setLocationId(
facility?.id === qParams.facility ? qParams.location ?? "" : ""
);
Expand All @@ -75,48 +92,6 @@ function AssetFilter(props: any) {
else navigate("/assets");
}, [qParams]);

const fetchFacility = useCallback(
async (status: statusType) => {
if (facilityId) {
const facilityData: any = await dispatch(
getPermittedFacility(facilityId)
);
if (!status.aborted) {
setFacility(facilityData?.data);
}
}
},
[filter.facility]
);

const fetchLocation = useCallback(
async (status: statusType) => {
if (locationId && facilityId) {
const [locationData]: any = await Promise.all([
dispatch(
getFacilityAssetLocation(String(facilityId), String(locationId))
),
]);
if (!status.aborted && locationData !== undefined) {
if (!locationData.data)
Notification.Error({
msg: "Something went wrong..!",
});
else {
setLocation(locationData.data);
}
}
} else {
setLocation(initialLocation);
}
},
[filter.location]
);

useAbortableEffect((status: statusType) => {
filter.facility && fetchFacility(status);
filter.location && fetchLocation(status);
}, []);
const applyFilter = () => {
const data = {
facility: facilityId,
Expand Down
22 changes: 9 additions & 13 deletions src/Components/Assets/AssetImportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { FacilityModel } from "../Facility/models";
import { AssetData } from "./AssetTypes";
import * as Notification from "../../Utils/Notifications.js";
import { Cancel, Submit } from "../Common/components/ButtonV2";
import { listFacilityAssetLocation } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { Link } from "raviger";
import readXlsxFile from "read-excel-file";
import {
Expand All @@ -16,6 +14,8 @@ import {
import { parseCsvFile } from "../../Utils/utils";
import useConfig from "../../Common/hooks/useConfig";
import DialogModal from "../Common/Dialog";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import { SelectFormField } from "../Form/FormFields/SelectFormField";

interface Props {
Expand All @@ -34,7 +34,6 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
location: "",
});
const [locations, setLocations] = useState<any>([]);
const dispatchAction: any = useDispatch();
const { sample_format_asset_import } = useConfig();
const [locationsLoading, setLocationsLoading] = useState(false);

Expand All @@ -43,18 +42,14 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
setSelectedFile(undefined);
onClose && onClose();
};

useEffect(() => {
setLocationsLoading(true);
dispatchAction(
listFacilityAssetLocation({}, { facility_external_id: facility.id })
).then(({ data }: any) => {
setLocationsLoading(false);
if (data.count > 0) {
useQuery(routes.listFacilityAssetLocation, {
pathParams: { facility_external_id: `${facility.id}` },
onResponse: ({ res, data }) => {
if (res?.status === 200 && data) {
setLocations(data.results);
}
});
}, []);
},
});

useEffect(() => {
const readFile = async () => {
Expand Down Expand Up @@ -362,6 +357,7 @@ const AssetImportModal = ({ open, onClose, facility }: Props) => {
<Submit
onClick={handleUpload}
disabled={isImporting || !selectedFile}
data-testid="asset-import-btn"
>
{isImporting ? (
<i className="fa-solid fa-spinner animate-spin" />
Expand Down
Loading

0 comments on commit 5d5f933

Please sign in to comment.