-
Notifications
You must be signed in to change notification settings - Fork 409
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
3e1a10e
commit 47463ac
Showing
58 changed files
with
1,613 additions
and
125 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
46 changes: 46 additions & 0 deletions
46
web/client/components/map/enhancers/__tests__/onMapViewChanges-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,46 @@ | ||
/* | ||
* 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 onMapViewChanges = require('../onMapViewChanges'); | ||
|
||
describe('onMapViewChanges 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('onMapViewChanges rendering with defaults', () => { | ||
const Sink = onMapViewChanges(createSink( props => { | ||
expect(props.eventHandlers.onMapViewChanges).toExist(); | ||
setTimeout(props.eventHandlers.onMapViewChanges("CENTER", "ZOOM", { bbox: { x: 2 } }, "SIZE", "mapStateSource", "projection")); | ||
|
||
})); | ||
const actions = { | ||
onMapViewChanges: () => {} | ||
}; | ||
const spy = expect.spyOn(actions, 'onMapViewChanges'); | ||
ReactDOM.render(<Sink map={{ bbox: { x: 1, y: 1 }, test: "TEST" }} onMapViewChanges={actions.onMapViewChanges} />, document.getElementById("container")); | ||
expect(spy).toHaveBeenCalled(); | ||
const map = spy.calls[0].arguments[0]; | ||
expect(map).toExist(); | ||
expect(map.center).toExist(); | ||
expect(map.zoom).toExist(); | ||
expect(map.bbox).toExist(); | ||
expect(map.size).toExist(); | ||
expect(map.mapStateSource).toExist(); | ||
expect(map.projection).toExist(); | ||
}); | ||
|
||
}); |
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
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 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 {compose, withHandlers, withPropsOnChange} = require('recompose'); | ||
|
||
/** | ||
* Enhance map to add the `onMapViewChanges` handler passed as prop to the list of event handlers. | ||
* The handler is called with only one parameter (the map) that is the result of the merge of | ||
* original callback (where center, zoom, bbox, size, mapStateSource and projection are separated) with the current `map` prop | ||
*/ | ||
module.exports = compose( | ||
withHandlers({ | ||
onMapViewChanges: ({ map = {}, onMapViewChanges = () => {}}) => (center, zoom, bbox, size, mapStateSource, projection) => { | ||
onMapViewChanges({ | ||
...map, | ||
center, | ||
bbox: { | ||
...map.bbox, | ||
...bbox | ||
}, | ||
zoom, | ||
size, | ||
mapStateSource, | ||
projection | ||
}); | ||
} | ||
}), | ||
withPropsOnChange( | ||
['onMapViewChanges', 'eventHandlers'], | ||
({ onMapViewChanges = () => {}, eventHandlers ={} } = {}) => ({ | ||
eventHandlers: { | ||
...eventHandlers, | ||
onMapViewChanges | ||
} | ||
}) | ||
) | ||
); |
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
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 2016, 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 { createSink } = require('recompose'); | ||
/** | ||
* Dummy implementation of mapType for tests | ||
*/ | ||
module.exports = () => { | ||
return { | ||
Map: createSink(() => {}), | ||
Layer: createSink(() => {}), | ||
Feature: createSink(() => {}) | ||
}; | ||
}; |
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
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
50 changes: 50 additions & 0 deletions
50
web/client/components/widgets/builder/wizard/__tests__/MapWizard-test.jsx
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,50 @@ | ||
/* | ||
* 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 PropTypes = require('prop-types'); | ||
const { withContext } = require('recompose'); | ||
const expect = require('expect'); | ||
|
||
const mockStore = withContext({ | ||
store: PropTypes.any | ||
}, ({store = {}} = {}) => ({ | ||
store: { | ||
dispatch: () => { }, | ||
subscribe: () => { }, | ||
getState: () => ({}), | ||
...store | ||
} | ||
})); | ||
const MapWizard = mockStore(require('../MapWizard')); | ||
describe('MapWizard component', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('MapWizard rendering with map', () => { | ||
// mock the store for empty map type | ||
const store = { | ||
getState: () => ({ | ||
maptype: { | ||
mapType: 'sink' | ||
} | ||
}) | ||
}; | ||
const map = { groups: [{ id: 'GGG' }], layers: [{ id: "LAYER", name: "Layer", group: "GGG", options: {} }] }; | ||
ReactDOM.render(<MapWizard store={store} editorData={{ map }} />, document.getElementById("container")); | ||
const container = document.getElementById('container'); | ||
const el = container.querySelector('.ms-wizard'); | ||
expect(el).toExist(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.