Skip to content

Commit

Permalink
HOTFIX: Psp 6408 - separate unmounted vs. error map search behaviour. (
Browse files Browse the repository at this point in the history
…#3297)

* separate unmounted vs error behaviour on usemapsearch.

* test corrections.

* correct try/catch location.
  • Loading branch information
devinleighsmith authored Jun 29, 2023
1 parent 2c4609b commit f9aad22
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand All @@ -30,6 +33,24 @@ const useLayerQueryMock = {
};
(useLayerQuery as jest.Mock).mockReturnValue(useLayerQueryMock);

(useMapProperties as unknown as jest.Mock<Partial<typeof useMapProperties>>).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: {} });
Expand Down Expand Up @@ -185,6 +206,9 @@ describe('useActiveFeatureLayer hook tests', () => {
useLayerQueryMock.findOneWhereContains.mockResolvedValueOnce({
features: [],
});
useLayerQueryMock.findOneWhereContains.mockResolvedValueOnce({
features: [],
});
renderHook(
() =>
useActiveFeatureLayer({
Expand Down
34 changes: 17 additions & 17 deletions source/frontend/src/components/maps/hooks/useMapSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,32 @@ 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);
}
if (filter?.PID) {
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:
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const useMapProperties = () => {
const loadProperties = useApiRequestWrapper({
requestFunction: loadPropertiesRequest,
requestName: 'LOAD_PROPERTIES',
throwError: true,
});
return { loadProperties };
};

0 comments on commit f9aad22

Please sign in to comment.