-
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
…gets (#2868)
- Loading branch information
1 parent
76f30b9
commit 6a54f5a
Showing
5 changed files
with
125 additions
and
12 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
47 changes: 47 additions & 0 deletions
47
web/client/components/layout/enhancers/__tests__/gridLayout-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,47 @@ | ||
/* | ||
* 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 {widthProvider, heightProvider} = require('../gridLayout'); | ||
|
||
describe('gridLayout enhancers', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
it('widthProvider rendering with defaults', (done) => { | ||
const Sink = widthProvider()(createSink( props => { | ||
expect(props).toExist(); | ||
expect(props.useDefaultWidthProvider).toBe(true); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink />, document.getElementById("container")); | ||
}); | ||
it('widthProvider rendering override defaults', (done) => { | ||
const Sink = widthProvider({overrideWidthProvider: true})(createSink(props => { | ||
expect(props).toExist(); | ||
expect(props.useDefaultWidthProvider).toBe(false); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink />, document.getElementById("container")); | ||
}); | ||
it('heightProvider rendering with defaults', (done) => { | ||
const Sink = heightProvider()(createSink(props => { | ||
expect(props).toExist(); | ||
done(); | ||
})); | ||
ReactDOM.render(<Sink />, document.getElementById("container")); | ||
}); | ||
}); |
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,39 @@ | ||
/* | ||
* 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 withResizeSpy = require('../../misc/enhancers/withResizeSpy'); | ||
const { compose, defaultProps, withStateHandlers} = require('recompose'); | ||
const ContainerDimensions = require('react-container-dimensions').default; | ||
|
||
/** | ||
* Width and height providers for react-grid-layout. Replace default. | ||
*/ | ||
module.exports = { | ||
/** | ||
* widthProvider that checks the container size | ||
* Useful in widgets container for dashboard and map context. | ||
* Can optionally override default widthProvider in WidgetView, for instance | ||
*/ | ||
widthProvider: ({overrideWidthProvider} = {}) => compose( | ||
defaultProps({ | ||
useDefaultWidthProvider: !overrideWidthProvider | ||
}), | ||
C => props => <ContainerDimensions>{({ width } = {}) => <C width={width} {...props} />}</ContainerDimensions> | ||
|
||
), | ||
/** | ||
* heightProvider that checks the fill div by default. | ||
* Useful in widgets container for map context | ||
*/ | ||
heightProvider: (opts) => compose( | ||
withStateHandlers(() => ({}), { | ||
onResize: () => ({ height }) => ({ height }) | ||
}), | ||
withResizeSpy(opts) | ||
) | ||
}; |
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