Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[fix] Image export legend positioning (#2895)

Igor Dykhtaccfc2e2add0f
diff --git a/examples/demo-app/src/app.tsx b/examples/demo-app/src/app.tsx
index 97afddf00..66ca90334 100644
--- a/examples/demo-app/src/app.tsx
+++ b/examples/demo-app/src/app.tsx
@@ -45,7 +45,7 @@ const KeplerGl = require('@kepler.gl/components').injectComponents([
/* eslint-disable no-unused-vars */
import sampleTripData, {testCsvData, sampleTripDataConfig} from './data/sample-trip-data';
import sampleGeojson from './data/sample-small-geojson';
-import sampleGeojsonPoints from './data/sample-geojson-points';
+// import sampleGeojsonPoints from './data/sample-geojson-points';
import sampleGeojsonConfig from './data/sample-geojson-config';
import sampleH3Data, {config as h3MapConfig} from './data/sample-hex-id-csv';
import sampleS2Data, {config as s2MapConfig, dataId as s2DataId} from './data/sample-s2-data';
@@ -160,7 +160,7 @@ const App = props => {
// window.setTimeout(_showBanner, 3000);
// }
// load sample data
- // _loadSampleData();
+ _loadSampleData();
// Notifications
// _loadMockNotifications();
@@ -180,7 +180,6 @@ const App = props => {
[dispatch]
);
- // eslint-disable-next-line no-unused-vars
const _showBanner = useCallback(() => {
toggleShowBanner(true);
}, [toggleShowBanner]);
@@ -542,7 +541,6 @@ const App = props => {
);
}, []);
- // eslint-disable-next-line no-unused-vars
const _loadSampleData = useCallback(() => {
// _loadPointData();
// _loadGeojsonData();
@@ -554,8 +552,8 @@ const App = props => {
// _loadGpsData();
// _loadRowData();
// _loadVectorTileData();
- _loadSyncedFilterWTripLayer();
- _replaceSyncedFilterWTripLayer();
+ // _loadSyncedFilterWTripLayer();
+ // _replaceSyncedFilterWTripLayer();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
_loadPointData,
diff --git a/src/common-utils/src/h3-utils.ts b/src/common-utils/src/h3-utils.ts
index aa2a669dd..97e519783 100644
--- a/src/common-utils/src/h3-utils.ts
+++ b/src/common-utils/src/h3-utils.ts
@@ -36,7 +36,7 @@ export function idToPolygonGeo(object?: {id: H3Index}, properties?: any) {
};
}
-export const isHexField = (field, fieldIdx, dataContainer) => {
+export const isHexField = (field, _fieldIdx, _dataContainer) => {
return field.type === ALL_FIELD_TYPES.h3;
};
diff --git a/src/components/src/common/histogram-plot.tsx b/src/components/src/common/histogram-plot.tsx
index 3ef5aa5aa..df671f920 100644
--- a/src/components/src/common/histogram-plot.tsx
+++ b/src/components/src/common/histogram-plot.tsx
@@ -132,7 +132,7 @@ function HistogramPlotFactory() {
const barWidth = useMemo(() => {
if (groupKeys.length === 0) return 0;
// find histogramsByGroup with max number of bins
- const maxGroup = groupKeys.reduce((accu, key, idx) => {
+ const maxGroup = groupKeys.reduce((accu, key, _idx) => {
if (histogramsByGroup[key].length > accu.length) {
return histogramsByGroup[key];
}
diff --git a/src/components/src/common/item-selector/dropdown-list.tsx b/src/components/src/common/item-selector/dropdown-list.tsx
index 386adf9fd..cafb23e35 100644
--- a/src/components/src/common/item-selector/dropdown-list.tsx
+++ b/src/components/src/common/item-selector/dropdown-list.tsx
@@ -26,7 +26,6 @@ export type ListItemProps<Option> = {
};
const defaultDisplay = d => d;
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const ListItem = ({
value,
displayOption = defaultDisplay,
diff --git a/src/components/src/common/sync-timeline-control.tsx b/src/components/src/common/sync-timeline-control.tsx
index 5a01f7c31..0a5ac759c 100644
--- a/src/components/src/common/sync-timeline-control.tsx
+++ b/src/components/src/common/sync-timeline-control.tsx
@@ -50,7 +50,7 @@ function SyncTimelineControlFactory() {
return (
<div>
{Object.values(syncTimelineAnimationItems)
- .filter((item, index) => item.id !== syncTimelineMode)
+ .filter((item, _index) => item.id !== syncTimelineMode)
.map(item => (
<IconButton
key={item.id}
diff --git a/src/components/src/container.tsx b/src/components/src/container.tsx
index f93af1146..dafa6a9bc 100644
--- a/src/components/src/container.tsx
+++ b/src/components/src/container.tsx
@@ -118,7 +118,15 @@ export function ContainerFactory(
dispatch(deleteEntry(id));
}
};
- }, [id]);
+ }, [
+ id,
+ dispatch,
+ initialUiState,
+ mapStylesReplaceDefault,
+ mapboxApiAccessToken,
+ mapboxApiUrl,
+ mint
+ ]);
useEffect(() => {
// check if id has changed, if true, copy state over
diff --git a/src/components/src/hooks/use-legend-position.ts b/src/components/src/hooks/use-legend-position.ts
index bd15e3a00..a59208009 100644
--- a/src/components/src/hooks/use-legend-position.ts
+++ b/src/components/src/hooks/use-legend-position.ts
@@ -43,23 +43,18 @@ const DEFAULT_POSITION: MapLegendControlSettings['position'] = {
};
const MIN_CONTENT_HEIGHT = 100;
-/**
- * Returns a function that calculates the anchored position of the map legend
- * that is being dragged.
- */
-export default function useLegendPosition({
+export type UseCalcLegendPositionProps = {
+ legendContentRef: React.MutableRefObject<HTMLElement | null>;
+ isSidePanelShown: boolean;
+ sidePanelWidth: number;
+};
+
+export function useCalcLegendPosition({
legendContentRef,
isSidePanelShown,
- settings,
- onChangeSettings,
- theme
-}: Params): ReturnType {
- const pos = settings?.position ?? DEFAULT_POSITION;
- const contentHeight = settings?.contentHeight ?? -1;
- const positionStyles = useMemo(() => ({[pos.anchorX]: pos.x, [pos.anchorY]: pos.y}), [pos]);
- const startHeightRef = useRef(0);
-
- const calcPosition = useCallback((): MapLegendControlSettings['position'] => {
+ sidePanelWidth
+}: UseCalcLegendPositionProps) {
+ return useCallback((): MapLegendControlSettings['position'] => {
const root = legendContentRef.current?.closest('.kepler-gl');
const legendContent = legendContentRef.current;
if (!legendContent || !(root instanceof HTMLElement)) {
@@ -86,7 +81,31 @@ export default function useLegendPosition({
? {y: topOffset, anchorY: 'top'}
: {y: bottomOffset, anchorY: 'bottom'})
};
- }, [isSidePanelShown]);
+ }, [isSidePanelShown, legendContentRef?.current, sidePanelWidth]);
+}
+
+/**
+ * Returns a function that calculates the anchored position of the map legend
+ * that is being dragged.
+ */
+export default function useLegendPosition({
+ legendContentRef,
+ isSidePanelShown,
+ settings,
+ onChangeSettings,
+ theme
+}: Params): ReturnType {
+ const pos = settings?.position ?? DEFAULT_POSITION;
+ const contentHeight = settings?.contentHeight ?? -1;
+ const positionStyles = useMemo(() => ({[pos.anchorX]: pos.x, [pos.anchorY]: pos.y}), [pos]);
+ const startHeightRef = useRef(0);
+ const sidePanelWidth = theme.sidePanel?.width || 0;
+
+ const calcPosition = useCalcLegendPosition({
+ legendContentRef,
+ isSidePanelShown,
+ sidePanelWidth
+ });
const updatePosition = useCallback(
() => onChangeSettings({position: calcPosition()}),
[calcPosition, onChangeSettings]
@@ -118,7 +137,6 @@ export default function useLegendPosition({
);
// Shift when side panel is shown/hidden
- const sidePanelWidth = theme.sidePanel?.width || 0;
const posRef = useRef(pos);
posRef.current = pos;
useEffect(() => {
diff --git a/src/components/src/map/map-legend-panel.tsx b/src/components/src/map/map-legend-panel.tsx
index 587ad4960..175bae123 100644
--- a/src/components/src/map/map-legend-panel.tsx
+++ b/src/components/src/map/map-legend-panel.tsx
@@ -19,7 +19,7 @@ import {hasPortableWidth} from '@kepler.gl/utils';
import {Legend, DraggableDots, HorizontalResizeHandle} from '../common/icons';
import {MapControlButton} from '../common/styled-components';
import {RootContext} from '../context';
-import useLegendPosition from '../hooks/use-legend-position';
+import useLegendPosition, {MapLegendControlSettings} from '../hooks/use-legend-position';
import {withState} from '../injector';
import MapControlPanelFactory from './map-control-panel';
import MapControlTooltipFactory from './map-control-tooltip';
@@ -218,6 +218,48 @@ const DraggableLegend = withState(
})
) as FC<{children: React.ReactNode}>;
+type ImageExportLegendProps = {
+ settings: MapLegendControlSettings;
+ isSidePanelShown: boolean;
+ children: React.ReactNode;
+};
+
+const ImageExportLegend = withTheme(({settings, isSidePanelShown, theme, children}) => {
+ const containerRef: React.MutableRefObject<HTMLDivElement | null> = useRef(null);
+ const legendContentRef: React.MutableRefObject<HTMLDivElement | null> = useRef(null);
+
+ const {positionStyles} = useLegendPosition({
+ legendContentRef,
+ isSidePanelShown,
+ theme,
+ settings,
+ onChangeSettings: () => {
+ // do nothing by default
+ }
+ });
+
+ const portalRoot = containerRef.current
+ ?.closest('.export-map-instance')
+ ?.querySelector('#default-deckgl-overlay-wrapper');
+
+ return (
+ <div ref={containerRef}>
+ {portalRoot
+ ? createPortal(
+ <div
+ className="fixed-legend"
+ ref={legendContentRef}
+ style={{...positionStyles, position: 'absolute'}}
+ >
+ {children}
+ </div>,
+ portalRoot
+ )
+ : null}
+ </div>
+ );
+}) as React.FC<ImageExportLegendProps>;
+
MapLegendPanelFactory.deps = [MapControlTooltipFactory, MapControlPanelFactory, MapLegendFactory];
interface MapLegendPanelIcons {
@@ -239,97 +281,131 @@ export type MapLegendPanelProps = {
isViewportUnsyncAllowed?: boolean;
onClickControlBtn?: (e?: MouseEvent) => void;
className: string;
+ settings: MapLegendControlSettings;
+ isSidePanelShown: boolean;
};
-function MapLegendPanelFactory(
- MapControlTooltip: ReturnType<typeof MapControlTooltipFactory>,
- MapControlPanel: ReturnType<typeof MapControlPanelFactory>,
- MapLegend: ReturnType<typeof MapLegendFactory>
-): React.FC<MapLegendPanelProps> {
- const defaultActionIcons = {
- legend: Legend
- };
- const MapLegendPanel: React.FC<MapLegendPanelProps> = ({
- theme,
- layers,
- mapControls,
- scale,
- onToggleMapControl,
- isExport,
- logoComponent,
- actionIcons = defaultActionIcons,
- mapState,
- onToggleSplitMapViewport,
- onClickControlBtn,
- isViewportUnsyncAllowed = true,
- className,
- onLayerVisConfigChange
- }) => {
- const mapLegend = mapControls?.mapLegend || ({} as MapControlMapLegend);
- const {active, disableEdit} = mapLegend || {};
- const rootContext = useContext(RootContext);
-
- const onClick = useCallback(() => {
- onClickControlBtn?.();
- if (mapControls?.mapDraw?.active) {
- onToggleMapControl('mapDraw');
- }
- onToggleMapControl('mapLegend');
- }, [onClickControlBtn, onToggleMapControl, mapControls]);
- const onCloseClick = useCallback(
- e => {
- e.preventDefault();
- onToggleMapControl('mapLegend');
- },
- [onToggleMapControl]
- );
+type MapLegendPanelComponentType = React.FC<MapLegendPanelProps>;
+
+const defaultActionIcons = {
+ legend: Legend
+};
- if (!mapLegend.show) {
- return null;
+const MapLegendPanelComponent = ({
+ layers,
+ mapControls,
+ scale,
+ onToggleMapControl,
+ isExport,
+ logoComponent,
+ actionIcons = defaultActionIcons,
+ mapState,
+ onLayerVisConfigChange,
+ onToggleSplitMapViewport,
+ onClickControlBtn,
+ isViewportUnsyncAllowed = true,
+ className,
+ interactionConfig,
+ settings,
+ isSidePanelShown,
+ MapControlTooltip,
+ MapControlPanel,
+ MapLegend
+}) => {
+ const mapLegend = mapControls?.mapLegend || ({} as MapControlMapLegend);
+ const {active, disableEdit} = mapLegend || {};
+ const rootContext = useContext(RootContext);
+
+ const onClick = useCallback(() => {
+ onClickControlBtn?.();
+ if (mapControls?.mapDraw?.active) {
+ onToggleMapControl('mapDraw');
}
- const legendPanel = active ? (
- <MapControlPanel
- scale={scale}
- header="header.layerLegend"
- {...{onClick: onCloseClick, pinnable: false, disableClose: false}}
- isExport={isExport}
- logoComponent={logoComponent}
+ onToggleMapControl('mapLegend');
+ }, [onClickControlBtn, onToggleMapControl, mapControls]);
+ const onCloseClick = useCallback(
+ e => {
+ e.preventDefault();
+ onToggleMapControl('mapLegend');
+ },
+ [onToggleMapControl]
+ );
+
+ if (!mapLegend.show) {
+ return null;
+ }
+
+ const legendPanel = active ? (
+ <MapControlPanel
+ scale={scale}
+ header="header.layerLegend"
+ {...{onClick: onCloseClick, pinnable: false, disableClose: false}}
+ isExport={isExport}
+ logoComponent={logoComponent}
+ mapState={mapState}
+ onToggleSplitMapViewport={onToggleSplitMapViewport}
+ isViewportUnsyncAllowed={isViewportUnsyncAllowed}
+ className={className}
+ >
+ <MapLegend
+ layers={layers}
mapState={mapState}
- onToggleSplitMapViewport={onToggleSplitMapViewport}
- isViewportUnsyncAllowed={isViewportUnsyncAllowed}
- className={className}
- >
- <MapLegend
- layers={layers}
- mapState={mapState}
- disableEdit={disableEdit}
- isExport={isExport}
- onLayerVisConfigChange={onLayerVisConfigChange}
- />
- </MapControlPanel>
- ) : null;
+ disableEdit={disableEdit}
+ isExport={isExport}
+ onLayerVisConfigChange={onLayerVisConfigChange}
+ />
+ </MapControlPanel>
+ ) : null;
- return (
- <>
- {active
- ? hasPortableWidth(breakPointValues) || isExport
- ? legendPanel
- : createPortal(
- <DraggableLegend>{legendPanel}</DraggableLegend>,
- rootContext?.current ?? document.body
- )
- : null}
+ return (
+ <>
+ {active ? (
+ hasPortableWidth(breakPointValues) ? (
+ legendPanel
+ ) : isExport ? (
+ <ImageExportLegend isSidePanelShown={isSidePanelShown} settings={settings}>
+ {legendPanel}
+ </ImageExportLegend>
+ ) : (
+ createPortal(
+ <DraggableLegend>{legendPanel}</DraggableLegend>,
+ rootContext?.current ?? document.body
+ )
+ )
+ ) : null}
+ {!isExport ? (
<MapControlTooltip id="show-legend" message="tooltip.showLegend">
<MapControlButton className="map-control-button show-legend" onClick={onClick}>
<actionIcons.legend height="22px" />
</MapControlButton>
</MapControlTooltip>
- </>
- );
- };
+ ) : null}
+ </>
+ );
+};
+
+function MapLegendPanelFactory(
+ MapControlTooltip: ReturnType<typeof MapControlTooltipFactory>,
+ MapControlPanel: ReturnType<typeof MapControlPanelFactory>,
+ MapLegend: ReturnType<typeof MapLegendFactory>
+): MapLegendPanelComponentType {
+ const MapLegendPanel = withState(
+ [],
+ state => {
+ const {activeSidePanel, mapControls} = state.demo?.keplerGl.map.uiState ?? {};
+ return {
+ isSidePanelShown: activeSidePanel,
+ settings: mapControls?.mapLegend?.settings,
+ MapControlTooltip,
+ MapControlPanel,
+ MapLegend
+ };
+ },
+ {setMapControlSettings}
+ )(MapLegendPanelComponent);
MapLegendPanel.displayName = 'MapLegendPanel';
- return withTheme(MapLegendPanel);
+ return withTheme(MapLegendPanel as MapLegendPanelComponentType) as MapLegendPanelComponentType;
}
export default MapLegendPanelFactory;
diff --git a/src/components/src/map/map-legend.tsx b/src/components/src/map/map-legend.tsx
index 0e4d72690..36840e57a 100644
--- a/src/components/src/map/map-legend.tsx
+++ b/src/components/src/map/map-legend.tsx
@@ -299,6 +299,7 @@ export type LayerLegendHeaderProps = {
options?: {
showLayerName?: boolean;
};
+ isExport?: boolean;
};
const isRadiusChannel = visualChannel =>
@@ -453,7 +454,7 @@ function MapLegendFactory(
key={index}
width={containerW}
>
- <LayerLegendHeader options={options} layer={layer} />
+ <LayerLegendHeader isExport={isExport} options={options} layer={layer} />
<LayerLegendContent
containerW={containerW}
layer={layer}
diff --git a/test/browser-headless/component/map-container-test.js b/test/browser-headless/component/map-container-test.js
index b6a06658f..64601fb68 100644
--- a/test/browser-headless/component/map-container-test.js
+++ b/test/browser-headless/component/map-container-test.js
@@ -17,6 +17,9 @@ import {
// import {Map} from 'react-map-gl'; // see other TODO below
import {gl, InteractionTestRunner} from '@deck.gl/test-utils';
+import {Provider} from 'react-redux';
+import configureStore from 'redux-mock-store';
+
import {mockKeplerProps, expectedLayerHoverProp} from '../../helpers/mock-state';
import {act} from 'react-dom/test-utils';
import {STYLED_COMPONENTS_DUPLICATED_ENTRIES} from '../../helpers/utils';
@@ -26,9 +29,13 @@ const MapPopover = appInjector.get(MapPopoverFactory);
const MapControl = appInjector.get(MapControlFactory);
const initialProps = mapFieldsSelector(mockKeplerProps);
+const initialState = {mapState: {latitude: 0, longitude: 0}};
+const mockStore = configureStore();
+
test('MapContainerFactory - display all options', t => {
const onMapStyleLoaded = sinon.spy();
const onLayerClick = sinon.spy();
+ const store = mockStore(initialState);
const props = {
...initialProps,
@@ -46,11 +53,13 @@ test('MapContainerFactory - display all options', t => {
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <MapViewStateContextProvider mapState={props.mapState}>
- <MapContainer {...props} />
- </MapViewStateContextProvider>
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={props.mapState}>
+ <MapContainer {...props} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
+ </Provider>
);
}, 'MapContainer should not fail');
@@ -78,14 +87,18 @@ test('MapContainerFactory - _renderDeckOverlay', t => {
...initialProps,
mapboxApiAccessToken: 'pyx-11'
};
+ const store = mockStore(initialState);
+
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <MapViewStateContextProvider mapState={props.mapState}>
- <MapContainer {...props} />
- </MapViewStateContextProvider>
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={props.mapState}>
+ <MapContainer {...props} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
+ </Provider>
);
}, 'MapContainer should not fail');
@@ -191,11 +204,13 @@ test('MapContainerFactory - _renderDeckOverlay', t => {
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <MapViewStateContextProvider mapState={propsWithHoverInfo.mapState}>
- <MapContainer {...propsWithHoverInfo} />
- </MapViewStateContextProvider>
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={propsWithHoverInfo.mapState}>
+ <MapContainer {...propsWithHoverInfo} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
+ </Provider>
);
}, 'render map container with map popover should not fail');
diff --git a/test/browser/components/map-container-test.js b/test/browser/components/map-container-test.js
index e085ac2da..bbdf47302 100644
--- a/test/browser/components/map-container-test.js
+++ b/test/browser/components/map-container-test.js
@@ -3,6 +3,8 @@
import React from 'react';
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
+import {Provider} from 'react-redux';
+import configureStore from 'redux-mock-store';
import sinon from 'sinon';
import test from 'tape';
@@ -17,9 +19,13 @@ import {mockKeplerProps} from '../../helpers/mock-state';
const MapContainer = appInjector.get(MapContainerFactory);
const initialProps = mapFieldsSelector(mockKeplerProps);
+const initialState = {mapState: {latitude: 0, longitude: 0}};
+const mockStore = configureStore();
+
test('MapContainerFactory - display all options', t => {
const onMapStyleLoaded = sinon.spy();
const onLayerClick = sinon.spy();
+ const store = mockStore(initialState);
const props = {
...initialProps,
@@ -36,11 +42,13 @@ test('MapContainerFactory - display all options', t => {
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <MapViewStateContextProvider mapState={props.mapState}>
- <MapContainer {...props} />
- </MapViewStateContextProvider>
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={props.mapState}>
+ <MapContainer {...props} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
+ </Provider>
);
}, 'MapContainer should not fail without props');
diff --git a/test/browser/components/map/map-control-test.js b/test/browser/components/map/map-control-test.js
index d11826948..063cd5833 100644
--- a/test/browser/components/map/map-control-test.js
+++ b/test/browser/components/map/map-control-test.js
@@ -81,14 +81,26 @@ test('MapControlFactory - display all options', t => {
});
test('MapControlFactory - display options', t => {
+ const store = mockStore({
+ demo: {
+ keplerGl: {
+ map: {
+ uiState: StateWSplitMaps.uiState
+ }
+ }
+ }
+ });
+
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <MapViewStateContextProvider mapState={initialProps.mapState}>
- <MapContainer {...initialProps} />
- </MapViewStateContextProvider>
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={initialProps.mapState}>
+ <MapContainer {...initialProps} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
+ </Provider>
);
}, 'Map Container should not fail without props');
@@ -107,22 +119,15 @@ test('MapControlFactory - display options', t => {
// with split map and active layer selector
const propsWithSplitMap = mapFieldsSelector(mockKeplerPropsWithState({state: StateWSplitMaps}));
- const store = mockStore({
- demo: {
- keplerGl: {
- map: {
- uiState: StateWSplitMaps.uiState
- }
- }
- }
- });
wrapper.setProps({
children: (
<Provider store={store}>
- <MapViewStateContextProvider mapState={propsWithSplitMap.mapState}>
- <MapContainer {...propsWithSplitMap} />
- </MapViewStateContextProvider>
+ <IntlWrapper>
+ <MapViewStateContextProvider mapState={propsWithSplitMap.mapState}>
+ <MapContainer {...propsWithSplitMap} />
+ </MapViewStateContextProvider>
+ </IntlWrapper>
</Provider>
)
});
diff --git a/test/browser/components/plot-container-test.js b/test/browser/components/plot-container-test.js
index bf2549f87..83ba64ea9 100644
--- a/test/browser/components/plot-container-test.js
+++ b/test/browser/components/plot-container-test.js
@@ -7,16 +7,23 @@ import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
import test from 'tape';
import {appInjector, PlotContainerFactory, plotContainerSelector} from '@kepler.gl/components';
import {mockKeplerProps} from '../../helpers/mock-state';
+import {Provider} from 'react-redux';
+import configureStore from 'redux-mock-store';
const PlotContainer = appInjector.get(PlotContainerFactory);
const initialProps = plotContainerSelector(mockKeplerProps);
+const initialState = {mapState: {latitude: 0, longitude: 0}};
+const mockStore = configureStore();
test('PlotContainer -> mount', t => {
+ const store = mockStore(initialState);
t.doesNotThrow(() => {
mountWithTheme(
- <IntlWrapper>
- <PlotContainer {...initialProps} />
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <PlotContainer {...initialProps} />
+ </IntlWrapper>
+ </Provider>
);
}, 'PlotContainer should not fail without props');
@@ -34,11 +41,14 @@ test('PlotContainer -> mount -> imageSize', t => {
}
};
+ const store = mockStore(initialState);
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <PlotContainer {...initialProps} exportImageSetting={exportImageSetting} />
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <PlotContainer {...initialProps} exportImageSetting={exportImageSetting} />
+ </IntlWrapper>
+ </Provider>
);
}, 'PlotContainer should not fail without props');
@@ -52,9 +62,11 @@ test('PlotContainer -> mount -> imageSize', t => {
t.doesNotThrow(() => {
wrapper = mountWithTheme(
- <IntlWrapper>
- <PlotContainer {...initialProps} exportImageSetting={exportImageSetting} />
- </IntlWrapper>
+ <Provider store={store}>
+ <IntlWrapper>
+ <PlotContainer {...initialProps} exportImageSetting={exportImageSetting} />
+ </IntlWrapper>
+ </Provider>
);
}, 'PlotContainer should not fail without props');