-
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
109f5bc
commit 7ac597b
Showing
26 changed files
with
442 additions
and
18 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
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,25 @@ | ||
/** | ||
* Copyright 2017, 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 expect = require('expect'); | ||
const { | ||
TOGGLE_FULLSCREEN, | ||
toggleFullscreen | ||
} = require('../fullscreen'); | ||
|
||
describe('Test correctness of the fullscreen actions', () => { | ||
it('toggleFullscreen', () => { | ||
const testControl = 'test'; | ||
var retval = toggleFullscreen(true, testControl); | ||
|
||
expect(retval).toExist(); | ||
expect(retval.type).toBe(TOGGLE_FULLSCREEN); | ||
expect(retval.enable).toBe(true); | ||
expect(retval.elementSelector).toBe(testControl); | ||
}); | ||
}); |
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,28 @@ | ||
/* | ||
* 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 TOGGLE_FULLSCREEN = "TOGGLE_FULLSCREEN"; | ||
/** | ||
* when fullscreen have to be toggled | ||
* @param {boolean} enable true for enable, false for disable | ||
* @param {string} elementSelector querySelector string to use to get the element to fullscreen. | ||
* @return {action} the action of type `TOGGLE_FULLSCREEN` with enable flag and element selector. | ||
*/ | ||
function toggleFullscreen(enable, elementSelector) { | ||
return { | ||
type: TOGGLE_FULLSCREEN, | ||
enable, | ||
elementSelector | ||
}; | ||
} | ||
|
||
module.exports = { | ||
toggleFullscreen, | ||
TOGGLE_FULLSCREEN | ||
}; |
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,89 @@ | ||
/** | ||
* Copyright 2017, 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 ToggleButton = require('./ToggleButton'); | ||
const {Tooltip} = require('react-bootstrap'); | ||
const Message = require('../I18N/Message'); | ||
/** | ||
* Toggle button for fullscreen. Wraps {@link #components.buttons.ToggleButton} with some defaults | ||
* @memberof components.buttons | ||
* @class | ||
* @prop {string} [id] an id for the html component | ||
* @prop {object} [btnConfig] the configuration to pass to the bootstrap button | ||
* @prop {object} [options] the options to send when toggle is clicked | ||
* @prop {string|element} [text] the text to disaplay | ||
* @prop {string|element} [help] the help text | ||
* @prop {string} glyphicon the icon name | ||
* @prop {bool} active the status of the button | ||
* @prop {function} onClick. The method to call when clicked. the method will return as parameter the toggled `pressed` prop and the `options` object | ||
* @prop {node} [activeTooltip] the tooltip to use on mouse hover | ||
* @prop {node} [notActiveTooltip] the tooltip to use on mouse hover when the button is active | ||
* @prop {string} [tooltipPlace] positon of the tooltip, one of: 'top', 'right', 'bottom', 'left' | ||
* @prop {object} css style object for the component | ||
* @prop {btnType} [btnType] one of 'normal', 'image' | ||
* @prop {string} image if type is 'image', the src of the image | ||
* @prop {string} pressedStyle the bootstrap style for pressedStyle | ||
* @prop {string} defaultStyle the bootstrap style when not pressed | ||
* | ||
*/ | ||
const FullScreenButton = React.createClass({ | ||
propTypes: { | ||
id: React.PropTypes.string, | ||
btnConfig: React.PropTypes.object, | ||
options: React.PropTypes.options, | ||
text: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element]), | ||
help: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element]), | ||
glyphicon: React.PropTypes.string, | ||
active: React.PropTypes.bool, | ||
onClick: React.PropTypes.func, | ||
activeTooltip: React.PropTypes.string, | ||
notActiveTooltip: React.PropTypes.string, | ||
tooltipPlace: React.PropTypes.string, | ||
style: React.PropTypes.object, | ||
btnType: React.PropTypes.oneOf(['normal', 'image']), | ||
image: React.PropTypes.string, | ||
pressedStyle: React.PropTypes.string, | ||
defaultStyle: React.PropTypes.string | ||
}, | ||
getDefaultProps() { | ||
return { | ||
id: 'fullscreen-btn', | ||
activeTooltip: 'fullscreen.tooltipDeactivate', | ||
notActiveTooltip: 'fullscreen.tooltipActivate', | ||
tooltipPlace: 'left', | ||
defaultStyle: 'primary', | ||
pressedStyle: 'success', | ||
glyphicon: '1-full-screen', | ||
btnConfig: { | ||
className: "square-button" | ||
} | ||
}; | ||
}, | ||
getButtonProperties() { | ||
return ['id', | ||
'btnConfig', | ||
'options', | ||
'text', | ||
'glyphicon', | ||
'onClick', | ||
'tooltipPlace', | ||
'style', | ||
'btnType', | ||
'image', | ||
'pressedStyle', | ||
'defaultStyle' | ||
].reduce((result, key) => { result[key] = this.props[key]; return result; }, {}); | ||
}, | ||
render() { | ||
return <ToggleButton {...this.getButtonProperties()} pressed={this.props.active} tooltip={<Tooltip><Message msgId={this.props.active ? this.props.activeTooltip : this.props.notActiveTooltip}/></Tooltip>} />; | ||
} | ||
}); | ||
|
||
module.exports = FullScreenButton; |
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
36 changes: 36 additions & 0 deletions
36
web/client/components/buttons/__tests__/FullScreenButton-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,36 @@ | ||
/** | ||
* Copyright 2017, 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. | ||
*/ | ||
var expect = require('expect'); | ||
|
||
var React = require('react'); | ||
var ReactDOM = require('react-dom'); | ||
var FullScreenButton = require('../FullScreenButton'); | ||
|
||
describe("test the FullScreenButton", () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('test default properties', () => { | ||
const tb = ReactDOM.render(<FullScreenButton/>, document.getElementById("container")); | ||
expect(tb).toExist(); | ||
|
||
const tbNode = ReactDOM.findDOMNode(tb); | ||
expect(tbNode).toExist(); | ||
expect(tbNode.id).toBe('fullscreen-btn'); | ||
expect(tbNode).toExist(); | ||
expect(tbNode.className.indexOf('primary') >= 0).toBe(true); | ||
}); | ||
}); |
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
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,64 @@ | ||
|
||
/** | ||
* Copyright 2017, 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. | ||
*/ | ||
|
||
var expect = require('expect'); | ||
|
||
const configureMockStore = require('redux-mock-store').default; | ||
const { createEpicMiddleware, combineEpics } = require('redux-observable'); | ||
const {toggleFullscreen} = require('../../actions/fullscreen'); | ||
const {SET_CONTROL_PROPERTY} = require('../../actions/controls'); | ||
const screenfull = require('screenfull'); | ||
|
||
const {toggleFullscreenEpic } = require('../fullscreen'); | ||
const rootEpic = combineEpics(toggleFullscreenEpic); | ||
const epicMiddleware = createEpicMiddleware(rootEpic); | ||
const mockStore = configureMockStore([epicMiddleware]); | ||
|
||
describe('search Epics', () => { | ||
let store; | ||
beforeEach(() => { | ||
store = mockStore(); | ||
}); | ||
|
||
afterEach(() => { | ||
epicMiddleware.replaceEpic(rootEpic); | ||
screenfull.exit(); | ||
}); | ||
|
||
it('produces the search epic', (done) => { | ||
let changed = false; | ||
let action = toggleFullscreen(true, "html"); | ||
if ( screenfull.enabled ) { | ||
screenfull.onchange( () => {changed = true; }); | ||
} | ||
store.dispatch( action ); | ||
|
||
const actions = store.getActions(); | ||
expect(actions.length).toBe(2); | ||
expect(actions[1].type).toBe(SET_CONTROL_PROPERTY); | ||
|
||
setTimeout( () => { | ||
// emulate user exit by hitting esc | ||
if ( screenfull.enabled ) { | ||
screenfull.exit(); | ||
} | ||
setTimeout( () => { | ||
const newActions = store.getActions(); | ||
if ( screenfull.enabled ) { | ||
expect(newActions.length).toBe(3); | ||
expect(actions[2].type).toBe(SET_CONTROL_PROPERTY); | ||
expect(changed).toBe(true); | ||
} | ||
done(); | ||
}, 10); | ||
|
||
}, 10); | ||
|
||
}); | ||
}); |
Oops, something went wrong.