Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(maps): render provider when map is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour committed Feb 19, 2019
1 parent f72e67e commit b696a11
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 38 deletions.
14 changes: 8 additions & 6 deletions packages/react-instantsearch-dom-maps/src/GoogleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ class GoogleMaps extends Component {
const { isMapReady } = this.state;

return (
<GoogleMapsContext.Provider value={this.state.value}>
<div className={cx('')}>
<div ref={this.mapRef} className={cx('map')} />
{isMapReady && children}
</div>
</GoogleMapsContext.Provider>
<div className={cx('')}>
<div ref={this.mapRef} className={cx('map')} />
{isMapReady && (
<GoogleMapsContext.Provider value={this.state.value}>
{children}
</GoogleMapsContext.Provider>
)}
</div>
);
}
}
Expand Down
46 changes: 20 additions & 26 deletions packages/react-instantsearch-dom-maps/src/__tests__/GoogleMaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ describe('GoogleMaps', () => {
const wrapper = shallow(
<GoogleMaps {...props}>
<div>This is the children</div>
</GoogleMaps>,
{
disableLifecycleMethods: true,
}
</GoogleMaps>
);

expect(wrapper.html()).toMatchSnapshot();
expect(wrapper).toMatchSnapshot();
expect(wrapper.state().isMapReady).toBe(false);
});

Expand All @@ -61,14 +58,11 @@ describe('GoogleMaps', () => {

const wrapper = shallow(
<GoogleMaps {...props}>
<div>This is the children</div>
</GoogleMaps>,
{
disableLifecycleMethods: true,
}
<div className="children">This is the children</div>
</GoogleMaps>
);

expect(wrapper.html()).toMatchSnapshot();
expect(wrapper).toMatchSnapshot();
expect(wrapper.state().isMapReady).toBe(false);

// Simulate didMount
Expand All @@ -79,11 +73,11 @@ describe('GoogleMaps', () => {
// Trigger the update
wrapper.update();

expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.find('.children')).toBeTruthy();
expect(wrapper.state().isMapReady).toBe(true);
});

describe.skip('creation', () => {
describe('creation', () => {
it('expect to create the GoogleMaps on didMount with the default options', () => {
const google = createFakeGoogleReference();

Expand All @@ -106,7 +100,7 @@ describe('GoogleMaps', () => {
});
});

it('expect to create the GoogleMaps on didMount witht the given options', () => {
it('expect to create the GoogleMaps on didMount with the given options', () => {
const google = createFakeGoogleReference();

const props = {
Expand Down Expand Up @@ -382,8 +376,8 @@ describe('GoogleMaps', () => {

expect(mapInstance.fitBounds).toHaveBeenCalledTimes(0);

expect(mapInstance.setZoom).toHaveBeenCalledTimes(2); // cDM
expect(mapInstance.setCenter).toHaveBeenCalledTimes(2); // cDM
expect(mapInstance.setZoom).toHaveBeenCalledTimes(1); // cDM
expect(mapInstance.setCenter).toHaveBeenCalledTimes(1); // cDM

wrapper.setProps({
boundingBoxPadding: 0,
Expand Down Expand Up @@ -414,8 +408,8 @@ describe('GoogleMaps', () => {
0
);

expect(mapInstance.setZoom).toHaveBeenCalledTimes(2); // cDM
expect(mapInstance.setCenter).toHaveBeenCalledTimes(2); // cDM
expect(mapInstance.setZoom).toHaveBeenCalledTimes(1); // cDM
expect(mapInstance.setCenter).toHaveBeenCalledTimes(1); // cDM
});

it('expect to call setCenter & setZoom when boundingBox is not provided', () => {
Expand Down Expand Up @@ -444,17 +438,17 @@ describe('GoogleMaps', () => {

expect(mapInstance.fitBounds).toHaveBeenCalledTimes(0);

expect(mapInstance.setZoom).toHaveBeenCalledTimes(2); // cDM
expect(mapInstance.setCenter).toHaveBeenCalledTimes(2); // cDM
expect(mapInstance.setZoom).toHaveBeenCalledTimes(1); // cDM
expect(mapInstance.setCenter).toHaveBeenCalledTimes(1); // cDM

wrapper.setProps();

expect(mapInstance.fitBounds).toHaveBeenCalledTimes(0);

expect(mapInstance.setZoom).toHaveBeenCalledTimes(3); // cDM + cDU
expect(mapInstance.setZoom).toHaveBeenCalledTimes(2); // cDM + cDU
expect(mapInstance.setZoom).toHaveBeenCalledWith(1);

expect(mapInstance.setCenter).toHaveBeenCalledTimes(3); // cDM + cDU
expect(mapInstance.setCenter).toHaveBeenCalledTimes(2); // cDM + cDU
expect(mapInstance.setCenter).toHaveBeenCalledWith({
lat: 0,
lng: 0,
Expand Down Expand Up @@ -509,20 +503,20 @@ describe('GoogleMaps', () => {

const wrapper = shallow(
<GoogleMaps {...props}>
<div>This is the children</div>
<div className="children">This is the children</div>
</GoogleMaps>
);

simulateMapReadyEvent(google);
simulateEvent(mapInstance, 'center_changed');

expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.find('.children')).toMatchSnapshot();

wrapper.setProps({
children: <div>This is the children updated</div>,
children: <div className="children">This is the children updated</div>,
});

expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.find('.children')).toMatchSnapshot();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`GoogleMaps expect render correctly with the map rendered 1`] = `"<div class=\\"ais-GeoSearch\\"><div class=\\"ais-GeoSearch-map\\"></div></div>"`;
exports[`GoogleMaps expect render correctly with the map rendered 1`] = `
<div
className="ais-GeoSearch"
>
<div
className="ais-GeoSearch-map"
/>
</div>
`;

exports[`GoogleMaps expect render correctly with the map rendered 2`] = `"<div class=\\"ais-GeoSearch\\"><div class=\\"ais-GeoSearch-map\\"></div><div>This is the children</div></div>"`;
exports[`GoogleMaps expect render correctly without the map rendered 1`] = `
<div
className="ais-GeoSearch"
>
<div
className="ais-GeoSearch-map"
/>
</div>
`;

exports[`GoogleMaps expect render correctly without the map rendered 1`] = `"<div class=\\"ais-GeoSearch\\"><div class=\\"ais-GeoSearch-map\\"></div></div>"`;
exports[`GoogleMaps update expect to still render the children when shouldUpdate return false 1`] = `
<div
className="children"
>
This is the children
</div>
`;

exports[`GoogleMaps update expect to still render the children when shouldUpdate return false 1`] = `"<div class=\\"ais-GeoSearch\\"><div class=\\"ais-GeoSearch-map\\"></div><div>This is the children</div></div>"`;
exports[`GoogleMaps update expect to still render the children when shouldUpdate return false 2`] = `"<div class=\\"ais-GeoSearch\\"><div class=\\"ais-GeoSearch-map\\"></div><div>This is the children updated</div></div>"`;
exports[`GoogleMaps update expect to still render the children when shouldUpdate return false 2`] = `
<div
className="children"
>
This is the children updated
</div>
`;

0 comments on commit b696a11

Please sign in to comment.