Skip to content

Commit

Permalink
fix: Added source checks
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Oct 25, 2023
1 parent 72af7cc commit 981e906
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => {
touchZoomRotate: { disableRotation: jest.fn() },
};
mapboxgl.Map.mockReturnValue(map);
map.getSource.mockReturnValueOnce();
map.getSource.mockReturnValueOnce({
setData: jest.fn(),
loaded: jest.fn().mockReturnValue(true),
});
useParams.mockReturnValue({
groupSlug: 'slug-1',
configSlug: 'config-slug',
Expand Down
9 changes: 8 additions & 1 deletion src/sharedData/visualization/components/Visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ const getSourceBounds = async (map, sourceId) => {
return new mapboxgl.LngLatBounds(loadedSource.bounds);
}

if (!loadedSource._data) {
return;
}

const calculatedBbox = bbox(loadedSource._data);
return new mapboxgl.LngLatBounds(
[calculatedBbox[0], calculatedBbox[1]],
Expand Down Expand Up @@ -203,7 +207,10 @@ const MapboxLayer = props => {
if (!source) {
return;
}
const features = source._data.features;
const features = source?._data?.features;
if (_.isEmpty(features)) {
return;
}
openPopup(features[0]);
}, [
showPopup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ const setup = async testParams => {
dragRotate: { disable: jest.fn() },
touchZoomRotate: { disableRotation: jest.fn() },
};
map.getSource.mockReturnValueOnce();
map.getSource.mockReturnValue({
setData: jest.fn(),
loaded: jest.fn().mockReturnValue(true),
});
mapboxgl.Map.mockReturnValue(map);
mapboxgl.LngLat = jest.fn();
useParams.mockReturnValue({
Expand Down

0 comments on commit 981e906

Please sign in to comment.