Skip to content

Commit

Permalink
fix(connectGeoSearch): correctly dispose the connector (#2845)
Browse files Browse the repository at this point in the history
* fix(connectGeoSearch): reset insideBoundingBox on dispose
* fix(connectGeoSearch): correctly reset the state on dispose
  • Loading branch information
samouss authored and bobylito committed Mar 29, 2018
1 parent f31ef3c commit a4eafd2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
57 changes: 57 additions & 0 deletions src/connectors/geo-search/__tests__/connectGeoSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,63 @@ describe('connectGeoSearch - getConfiguration', () => {
});

describe('connectGeoSearch - dispose', () => {
it('expect reset insideBoundingBox', () => {
const render = jest.fn();
const unmount = jest.fn();

const customGeoSearch = connectGeoSearch(render, unmount);
const widget = customGeoSearch({
enableGeolocationWithIP: false,
});

const client = createFakeClient();
const helper = createFakeHelper(client);

helper
.setState(widget.getConfiguration(new SearchParameters()))
.setQueryParameter('insideBoundingBox', '10,12,12,14');

const expectation = {
insideBoundingBox: undefined,
};

const actual = widget.dispose({ state: helper.getState() });

expect(unmount).toHaveBeenCalled();
expect(actual).toMatchObject(expectation);
});

it('expect reset multiple parameters', () => {
const render = jest.fn();
const unmount = jest.fn();

const customGeoSearch = connectGeoSearch(render, unmount);
const widget = customGeoSearch({
radius: 100,
precision: 25,
position: {
lat: 10,
lng: 12,
},
});

const client = createFakeClient();
const helper = createFakeHelper(client);

helper.setState(widget.getConfiguration(new SearchParameters()));

const expectation = {
aroundRadius: undefined,
aroundPrecision: undefined,
aroundLatLng: undefined,
};

const actual = widget.dispose({ state: helper.getState() });

expect(unmount).toHaveBeenCalled();
expect(actual).toMatchObject(expectation);
});

describe('aroundLatLngViaIP', () => {
it('expect reset aroundLatLngViaIP', () => {
const render = jest.fn();
Expand Down
10 changes: 6 additions & 4 deletions src/connectors/geo-search/connectGeoSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,23 @@ const connectGeoSearch = (renderFn, unmountFn) => {
let nextState = state;

if (enableGeolocationWithIP && !position) {
nextState = state.setQueryParameter('aroundLatLngViaIP');
nextState = nextState.setQueryParameter('aroundLatLngViaIP');
}

if (position) {
nextState = state.setQueryParameter('aroundLatLng');
nextState = nextState.setQueryParameter('aroundLatLng');
}

if (radius) {
nextState = state.setQueryParameter('aroundRadius');
nextState = nextState.setQueryParameter('aroundRadius');
}

if (precision) {
nextState = state.setQueryParameter('aroundPrecision');
nextState = nextState.setQueryParameter('aroundPrecision');
}

nextState = nextState.setQueryParameter('insideBoundingBox');

return nextState;
},
};
Expand Down

0 comments on commit a4eafd2

Please sign in to comment.