-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3958 hide layer related buttons when removing a layer from the m…
…ap (#3980)
- Loading branch information
1 parent
c31db91
commit d28f792
Showing
4 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
web/client/plugins/widgetbuilder/enhancers/__tests__/handleMapRemoveLayer-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
|
||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// dependencies | ||
const React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
const expect = require('expect'); | ||
const ReactTestUtils = require('react-dom/test-utils'); | ||
const handleMapRemoveLayer = require('../handleMapRemoveLayer'); | ||
const CMP = handleMapRemoveLayer((props) => <button id="CMP" onClick={() => props.onRemoveSelected()} />); | ||
|
||
describe('handleMapRemoveLayer enhancer', function() { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('layer remove must also unselect the layers by triggering onNodeSelect', () => { | ||
const lib = { | ||
onNodeSelect() { } | ||
}; | ||
const spyReset = expect.spyOn(lib, 'onNodeSelect'); | ||
ReactDOM.render(<CMP selectedLayers={['layer 1']} onNodeSelect={lib.onNodeSelect} />, document.getElementById("container")); | ||
const el = document.querySelector('#CMP'); | ||
ReactTestUtils.Simulate.click(el); | ||
expect(spyReset).toHaveBeenCalled(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
web/client/plugins/widgetbuilder/enhancers/handleMapRemoveLayer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2019, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const { withHandlers } = require('recompose'); | ||
|
||
const enhancer = withHandlers({ | ||
onRemoveSelected: ({ selectedLayers = [], removeLayersById = () => { }, onNodeSelect = () => { } }) => () => { | ||
removeLayersById(selectedLayers); | ||
selectedLayers.forEach(layer => onNodeSelect(layer, 'layer', false)); | ||
} | ||
}); | ||
|
||
module.exports = enhancer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters