Skip to content

Commit

Permalink
Fix WidgetLegend preview (geosolutions-it#3994)
Browse files Browse the repository at this point in the history
* Fix WidgetLegend preview

* Update web/client/components/widgets/enhancers/legendWidget.js
  • Loading branch information
MV88 authored and Tobia Di Pisa committed Jul 22, 2019
1 parent d28f792 commit c9a0b07
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
4 changes: 2 additions & 2 deletions web/client/components/widgets/enhancers/legendWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const {getScales} = require('../../../utils/MapUtils');
* Add also base tools and menu to the widget
*/
module.exports = compose(
withProps(({ dependencies = {} }) => ({
layers: dependencies.layers || [],
withProps(({ dependencies = {}, dependenciesMap = {} }) => ({
layers: dependencies[dependenciesMap.layers] || dependencies.layers || [],
scales: getScales(
// TODO: this is a fallback that checks the viewport if projection is not defined. We should use only projection
dependencies.projection || dependencies.viewport && dependencies.viewport.crs || 'EPSG:3857',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const LegendWidget = compose(
defaultProps({canEdit: true}),
legendWidget
)(require('../LegendWidget'));

describe('LegendWidget component', () => {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
Expand Down Expand Up @@ -73,4 +74,41 @@ describe('LegendWidget component', () => {
expect(el).toExist();
expect(container.querySelector('.compact-legend-grid')).toExist();
});
it('LegendWidget rendering with layers specified in dependenciesMap', () => {
const layers = [
{
type: 'wms',
url: 'https://gs-stable.geo-solutions.it/geoserver/wms',
visibility: true,
dimensions: [],
name: 'gs:us_states',
title: 'States of US',
description: '',
bbox: {
crs: 'EPSG:4326',
bounds: {
minx: -124.73142200000001,
miny: 24.955967,
maxx: -66.969849,
maxy: 49.371735
}
},
links: [],
params: {},
allowedSRS: {},
search: {
type: 'wfs',
url: 'https://gs-stable.geo-solutions.it/geoserver/wfs'
},
id: 'gs:us_states__qxhbmc4jmko'
}
];
ReactDOM.render(<LegendWidget
dependencies={{"widgets[3fe79110-ac81-11e9-9a66-39723a13a30f].map.layers": layers}}
dependenciesMap={{layers: "widgets[3fe79110-ac81-11e9-9a66-39723a13a30f].map.layers" }} />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.mapstore-widget-card');
expect(el).toExist();
expect(container.querySelector('.compact-legend-grid')).toExist();
});
});

0 comments on commit c9a0b07

Please sign in to comment.