-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
e82ea72
commit b6d66a2
Showing
3 changed files
with
54 additions
and
8 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
42 changes: 42 additions & 0 deletions
42
web/client/components/widgets/builder/wizard/map/enhancers/__tests__/previewMap-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,42 @@ | ||
/* | ||
* Copyright 2018, 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 React = require('react'); | ||
const ReactDOM = require('react-dom'); | ||
const {createSink} = require('recompose'); | ||
const expect = require('expect'); | ||
const previewMap = require('../previewMap'); | ||
|
||
describe('previewMap enhancer', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('previewMap enhancer callbacks', (done) => { | ||
const actions = { | ||
callback: () => { } | ||
}; | ||
const spyCallback = expect.spyOn(actions, 'callback'); | ||
const Sink = previewMap(createSink( props => { | ||
props.onMapViewChanges({mapStateSource: "TEST"}); | ||
expect(spyCallback).toHaveBeenCalled(); | ||
expect(spyCallback.calls.length).toBe(2); | ||
expect(spyCallback.calls[0].arguments[0]).toBe("map"); | ||
expect(spyCallback.calls[1].arguments[0]).toBe("mapStateSource"); | ||
expect(spyCallback.calls[1].arguments[1]).toBe("TEST"); | ||
done(); | ||
|
||
})); | ||
ReactDOM.render(<Sink onChange={actions.callback}/>, document.getElementById("container")); | ||
}); | ||
|
||
}); |
10 changes: 10 additions & 0 deletions
10
web/client/components/widgets/builder/wizard/map/enhancers/previewMap.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,10 @@ | ||
const { compose, withHandlers } = require('recompose'); | ||
|
||
module.exports = compose( | ||
withHandlers({ | ||
onMapViewChanges: ({ onChange = () => { } }) => map => { | ||
onChange('map', map); | ||
onChange('mapStateSource', map.mapStateSource); | ||
} | ||
}) | ||
); |