Skip to content

Commit a4eafd2

Browse files
samoussbobylito
authored andcommitted
fix(connectGeoSearch): correctly dispose the connector (#2845)
* fix(connectGeoSearch): reset insideBoundingBox on dispose * fix(connectGeoSearch): correctly reset the state on dispose
1 parent f31ef3c commit a4eafd2

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

src/connectors/geo-search/__tests__/connectGeoSearch-test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,63 @@ describe('connectGeoSearch - getConfiguration', () => {
12681268
});
12691269

12701270
describe('connectGeoSearch - dispose', () => {
1271+
it('expect reset insideBoundingBox', () => {
1272+
const render = jest.fn();
1273+
const unmount = jest.fn();
1274+
1275+
const customGeoSearch = connectGeoSearch(render, unmount);
1276+
const widget = customGeoSearch({
1277+
enableGeolocationWithIP: false,
1278+
});
1279+
1280+
const client = createFakeClient();
1281+
const helper = createFakeHelper(client);
1282+
1283+
helper
1284+
.setState(widget.getConfiguration(new SearchParameters()))
1285+
.setQueryParameter('insideBoundingBox', '10,12,12,14');
1286+
1287+
const expectation = {
1288+
insideBoundingBox: undefined,
1289+
};
1290+
1291+
const actual = widget.dispose({ state: helper.getState() });
1292+
1293+
expect(unmount).toHaveBeenCalled();
1294+
expect(actual).toMatchObject(expectation);
1295+
});
1296+
1297+
it('expect reset multiple parameters', () => {
1298+
const render = jest.fn();
1299+
const unmount = jest.fn();
1300+
1301+
const customGeoSearch = connectGeoSearch(render, unmount);
1302+
const widget = customGeoSearch({
1303+
radius: 100,
1304+
precision: 25,
1305+
position: {
1306+
lat: 10,
1307+
lng: 12,
1308+
},
1309+
});
1310+
1311+
const client = createFakeClient();
1312+
const helper = createFakeHelper(client);
1313+
1314+
helper.setState(widget.getConfiguration(new SearchParameters()));
1315+
1316+
const expectation = {
1317+
aroundRadius: undefined,
1318+
aroundPrecision: undefined,
1319+
aroundLatLng: undefined,
1320+
};
1321+
1322+
const actual = widget.dispose({ state: helper.getState() });
1323+
1324+
expect(unmount).toHaveBeenCalled();
1325+
expect(actual).toMatchObject(expectation);
1326+
});
1327+
12711328
describe('aroundLatLngViaIP', () => {
12721329
it('expect reset aroundLatLngViaIP', () => {
12731330
const render = jest.fn();

src/connectors/geo-search/connectGeoSearch.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,23 @@ const connectGeoSearch = (renderFn, unmountFn) => {
313313
let nextState = state;
314314

315315
if (enableGeolocationWithIP && !position) {
316-
nextState = state.setQueryParameter('aroundLatLngViaIP');
316+
nextState = nextState.setQueryParameter('aroundLatLngViaIP');
317317
}
318318

319319
if (position) {
320-
nextState = state.setQueryParameter('aroundLatLng');
320+
nextState = nextState.setQueryParameter('aroundLatLng');
321321
}
322322

323323
if (radius) {
324-
nextState = state.setQueryParameter('aroundRadius');
324+
nextState = nextState.setQueryParameter('aroundRadius');
325325
}
326326

327327
if (precision) {
328-
nextState = state.setQueryParameter('aroundPrecision');
328+
nextState = nextState.setQueryParameter('aroundPrecision');
329329
}
330330

331+
nextState = nextState.setQueryParameter('insideBoundingBox');
332+
331333
return nextState;
332334
},
333335
};

0 commit comments

Comments
 (0)