diff --git a/source/frontend/src/components/maps/hooks/useActiveFeatureLayer.test.tsx b/source/frontend/src/components/maps/hooks/useActiveFeatureLayer.test.tsx index 5ebf62a051..31b075bf8f 100644 --- a/source/frontend/src/components/maps/hooks/useActiveFeatureLayer.test.tsx +++ b/source/frontend/src/components/maps/hooks/useActiveFeatureLayer.test.tsx @@ -1,6 +1,7 @@ import { waitFor } from '@testing-library/react'; import { renderHook } from '@testing-library/react-hooks'; import { useLayerQuery } from 'components/maps/leaflet/LayerPopup'; +import { useMapProperties } from 'features/properties/map/hooks/useMapProperties'; import { createMemoryHistory } from 'history'; import { geoJSON } from 'leaflet'; import { noop } from 'lodash'; @@ -10,11 +11,13 @@ import { Router } from 'react-router-dom'; import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import { createPoints } from '../leaflet/mapUtils'; import useActiveFeatureLayer from './useActiveFeatureLayer'; const mapRef = { current: { leafletMap: {} } }; jest.mock('leaflet'); jest.mock('components/maps/leaflet/LayerPopup'); +jest.mock('features/properties/map/hooks/useMapProperties'); let clearLayers = jest.fn(); let addData = jest.fn(); @@ -30,6 +33,24 @@ const useLayerQueryMock = { }; (useLayerQuery as jest.Mock).mockReturnValue(useLayerQueryMock); +(useMapProperties as unknown as jest.Mock>).mockReturnValue({ + loadProperties: { + execute: jest.fn().mockResolvedValue({ + features: createPoints([ + { + id: 1, + latitude: 54.917061, + longitude: -122.749672, + pid: '123-456-789', + address: { provinceId: 1, streetAddress1: 'test' }, + }, + ]), + type: 'FeatureCollection', + bbox: undefined, + }), + }, +}); + const mockStore = configureMockStore([thunk]); const history = createMemoryHistory(); const getStore = (values?: any) => mockStore(values ?? { properties: {} }); @@ -185,6 +206,9 @@ describe('useActiveFeatureLayer hook tests', () => { useLayerQueryMock.findOneWhereContains.mockResolvedValueOnce({ features: [], }); + useLayerQueryMock.findOneWhereContains.mockResolvedValueOnce({ + features: [], + }); renderHook( () => useActiveFeatureLayer({ diff --git a/source/frontend/src/components/maps/hooks/useMapSearch.tsx b/source/frontend/src/components/maps/hooks/useMapSearch.tsx index 8da5961f3d..3b6860e8ac 100644 --- a/source/frontend/src/components/maps/hooks/useMapSearch.tsx +++ b/source/frontend/src/components/maps/hooks/useMapSearch.tsx @@ -51,7 +51,9 @@ export const useMapSearch = () => { tileData = pimsProperties.features.length ? pimsProperties : parcel; } else { let task1, task2, task3; + task1 = loadProperties(filter); + if (filter?.PIN) { task2 = parcelsService.findByPin(filter?.PIN); } @@ -59,13 +61,22 @@ export const useMapSearch = () => { task3 = parcelsService.findByPid(filter?.PID); } - const [pidPinInventoryData, pinNonInventoryData, pidNonInventoryData] = await Promise.all([ - task1, - task2, - task3, - ]); + try { + const [pidPinInventoryData, pinNonInventoryData, pidNonInventoryData] = await Promise.all( + [task1, task2, task3], + ); - if (pidPinInventoryData?.features === undefined) { + tileData = pidPinInventoryData?.features?.length + ? pidPinInventoryData + : ({ + type: 'FeatureCollection', + features: [ + ...(pinNonInventoryData?.features || []), + ...(pidNonInventoryData?.features || []), + ], + bbox: pinNonInventoryData?.bbox || pidNonInventoryData?.bbox, + } as FeatureCollection); + } catch (err) { setModalContent({ title: 'Unable to connect to PIMS Inventory', message: @@ -81,17 +92,6 @@ export const useMapSearch = () => { }); setDisplayModal(true); } - - tileData = pidPinInventoryData?.features?.length - ? pidPinInventoryData - : ({ - type: 'FeatureCollection', - features: [ - ...(pinNonInventoryData?.features || []), - ...(pidNonInventoryData?.features || []), - ], - bbox: pinNonInventoryData?.bbox || pidNonInventoryData?.bbox, - } as FeatureCollection); } if (tileData) { const validFeatures = tileData.features.filter(feature => !!feature?.geometry); diff --git a/source/frontend/src/features/properties/map/hooks/useMapProperties.tsx b/source/frontend/src/features/properties/map/hooks/useMapProperties.tsx index 34450629f6..54f6263f22 100644 --- a/source/frontend/src/features/properties/map/hooks/useMapProperties.tsx +++ b/source/frontend/src/features/properties/map/hooks/useMapProperties.tsx @@ -29,6 +29,7 @@ export const useMapProperties = () => { const loadProperties = useApiRequestWrapper({ requestFunction: loadPropertiesRequest, requestName: 'LOAD_PROPERTIES', + throwError: true, }); return { loadProperties }; };