From 5d38f3104ba6be404a55d7a6596e5544bab3a354 Mon Sep 17 00:00:00 2001 From: Lorenzo Natali Date: Wed, 11 Apr 2018 10:04:44 +0200 Subject: [PATCH] Fix #2794 Force update of map widget position on save (#2814) --- .../widgets/builder/wizard/map/PreviewMap.jsx | 10 +---- .../enhancers/__tests__/previewMap-test.js | 42 +++++++++++++++++++ .../wizard/map/enhancers/previewMap.js | 10 +++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 web/client/components/widgets/builder/wizard/map/enhancers/__tests__/previewMap-test.js create mode 100644 web/client/components/widgets/builder/wizard/map/enhancers/previewMap.js diff --git a/web/client/components/widgets/builder/wizard/map/PreviewMap.jsx b/web/client/components/widgets/builder/wizard/map/PreviewMap.jsx index f36221728a..1056e6b62d 100644 --- a/web/client/components/widgets/builder/wizard/map/PreviewMap.jsx +++ b/web/client/components/widgets/builder/wizard/map/PreviewMap.jsx @@ -6,11 +6,5 @@ * LICENSE file in the root directory of this source tree. */ - -const { compose, withHandlers} = require('recompose'); - -module.exports = compose( - withHandlers({ - onMapViewChanges: ({onChange = () => {}}) => map => onChange('map', map) - }) -)(require('../../../widget/MapView')); +const previewMap = require('./enhancers/previewMap'); +module.exports = previewMap(require('../../../widget/MapView')); diff --git a/web/client/components/widgets/builder/wizard/map/enhancers/__tests__/previewMap-test.js b/web/client/components/widgets/builder/wizard/map/enhancers/__tests__/previewMap-test.js new file mode 100644 index 0000000000..567814f0e4 --- /dev/null +++ b/web/client/components/widgets/builder/wizard/map/enhancers/__tests__/previewMap-test.js @@ -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 = '
'; + 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(, document.getElementById("container")); + }); + +}); diff --git a/web/client/components/widgets/builder/wizard/map/enhancers/previewMap.js b/web/client/components/widgets/builder/wizard/map/enhancers/previewMap.js new file mode 100644 index 0000000000..510f7961fb --- /dev/null +++ b/web/client/components/widgets/builder/wizard/map/enhancers/previewMap.js @@ -0,0 +1,10 @@ +const { compose, withHandlers } = require('recompose'); + +module.exports = compose( + withHandlers({ + onMapViewChanges: ({ onChange = () => { } }) => map => { + onChange('map', map); + onChange('mapStateSource', map.mapStateSource); + } + }) +);