Skip to content

Commit

Permalink
geosolutions-it#10235: Interactive legend in dashboard and geostory (…
Browse files Browse the repository at this point in the history
…resolve reviews)

Description:
- add unit test for layers key
- refactor createMapObject method based on the new review
  • Loading branch information
mahmoudadel54 committed Jul 8, 2024
1 parent b950b02 commit c575d40
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
8 changes: 1 addition & 7 deletions web/client/utils/GeoStoryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,7 @@ export const applyDefaults = (options = {}) => merge({}, DEFAULT_MAP_OPTIONS, op
* @return {object} options merged with defaults
*/
export const createMapObject = (baseMap = {}, overrides = {}) => {
const baseMapCloned = { ...baseMap };
// use override [replace] logic instead of merge to get the updated map
const updatedMap = Object.keys(overrides).reduce((cumulatedMap, key) => {
cumulatedMap[key] = overrides[key];
return cumulatedMap;
}, baseMapCloned);
return updatedMap;
return merge({}, baseMap, overrides);
};
/**
* check if a string matches a regex
Expand Down
70 changes: 68 additions & 2 deletions web/client/utils/__tests__/GeoStoryUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,82 @@ describe("GeoStory Utils", () => {
}
};
const res = createMapObject(DEFAULT_MAP_OPTIONS, {
mapOptions: {
scrollWheelZoom: false,
interactions: {
mouseClick: false
}
}
});
expect(res).toEqual(merged);
});
it('test override layers in createMapObject', () => {
// initial baseMap layer is empty array
const merged1 = {
zoomControl: true,
mapInfoControl: false,
mapOptions: {
scrollWheelZoom: false,
interactions: {
mouseWheelZoom: false,
mouseClick: false,
dragPan: true
}
}
},
layers: [{
name: "layer01", center: {x: 1, y: 1, crs: 'EPSG:4326'}, zoom: 1
}, {
name: "layer02", center: {x: 2, y: 2, crs: 'EPSG:4326'}, zoom: 2
}]
};
const res1 = createMapObject({...DEFAULT_MAP_OPTIONS, layers: []}, {
mapOptions: {
scrollWheelZoom: false,
interactions: {
mouseClick: false
}
},
layers: [{
name: "layer01", center: {x: 1, y: 1, crs: 'EPSG:4326'}, zoom: 1
}, {
name: "layer02", center: {x: 2, y: 2, crs: 'EPSG:4326'}, zoom: 2
}]
});
expect(res1).toEqual(merged1);
// initial baseMap layer not empty array
const merged2 = {
zoomControl: true,
mapInfoControl: false,
mapOptions: {
scrollWheelZoom: false,
interactions: {
mouseWheelZoom: false,
mouseClick: false,
dragPan: true
}
},
layers: [{
name: "layer01", center: {x: 1.5, y: 1.5, crs: 'EPSG:4326'}, zoom: 1.5
}, {
name: "layer02", center: {x: 2, y: 2, crs: 'EPSG:4326'}, zoom: 2
}]
};
const res2 = createMapObject({...DEFAULT_MAP_OPTIONS, layers: [{
name: "layer01", center: {x: 1, y: 1, crs: 'EPSG:4326'}, zoom: 1
}]}, {
mapOptions: {
scrollWheelZoom: false,
interactions: {
mouseClick: false
}
},
layers: [{
name: "layer01", center: {x: 1.5, y: 1.5, crs: 'EPSG:4326'}, zoom: 1.5
}, {
name: "layer02", center: {x: 2, y: 2, crs: 'EPSG:4326'}, zoom: 2
}]
});
expect(res).toEqual(merged);
expect(res2).toEqual(merged2);
});
it('test testRegex', () => {
const title = "title";
Expand Down

0 comments on commit c575d40

Please sign in to comment.