Skip to content

Commit

Permalink
fix added unit test , localized the message for button
Browse files Browse the repository at this point in the history
  • Loading branch information
saidaipparla committed Oct 19, 2016
1 parent e6b6890 commit 3416488
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
7 changes: 5 additions & 2 deletions web/client/components/TOC/DefaultLayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var WMSLegend = require('./fragments/WMSLegend');
const ConfirmButton = require('../buttons/ConfirmButton');
const LayersTool = require('./fragments/LayersTool');
const SettingsModal = require('./fragments/SettingsModal');
const Message = require('../I18N/Message');
const {Glyphicon} = require('react-bootstrap');

var DefaultLayer = React.createClass({
Expand All @@ -37,6 +38,7 @@ var DefaultLayer = React.createClass({
opacityText: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element]),
saveText: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element]),
closeText: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element]),
confirmDeleteText: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.element]),
modalOptions: React.PropTypes.object,
settingsOptions: React.PropTypes.object,
visibilityCheckType: React.PropTypes.string,
Expand All @@ -49,11 +51,12 @@ var DefaultLayer = React.createClass({
propertiesChangeHandler: () => {},
onToggle: () => {},
onSettings: () => {},
activateRemoveLayer: true,
activateRemoveLayer: false,
activateLegendTool: false,
activateSettingsTool: false,
modalOptions: {},
settingsOptions: {},
confirmDeleteText: <Message msgId="layerProperties.confirmDelete" />,
visibilityCheckType: "glyph"
};
},
Expand All @@ -70,7 +73,7 @@ var DefaultLayer = React.createClass({
<ConfirmButton key="removelayer" className="clayer_removal_button"
text={(<Glyphicon glyph="1-close" />)}
style={{"float": "right", cursor: "pointer", backgroundColor: "transparent", marginRight: 3, padding: 0, outline: "none"}}
confirming={{text: "Sei sicuro",
confirming={{text: this.props.confirmDeleteText,
style: {"float": "right", cursor: "pointer", marginTop: -5}}}
onConfirm={() => {
this.props.removeNode(this.props.node.id, "layers");
Expand Down
42 changes: 34 additions & 8 deletions web/client/components/TOC/__tests__/DefaultLayer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var React = require('react/addons');
var ReactDOM = require('react-dom');
var Layer = require('../DefaultLayer');

// var ConfirmButton = require('../../buttons/ConfirmButton');
var expect = require('expect');

const TestUtils = React.addons.TestUtils;
Expand Down Expand Up @@ -133,7 +133,33 @@ describe('test DefaultLayer module component', () => {
const tool = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "glyphicon")[1]);
expect(tool).toExist();
tool.click();
expect(spy.calls.length).toBe(0);
expect(spy.calls.length).toBe(1);
});

it('tests removelayer tool', () => {
const l = {
name: 'layer000',
title: 'Layer001',
visibility: true,
storeIndex: 9,
type: 'wms'
};
const actions = {
removeNode: () => {}
};
let spy = expect.spyOn(actions, "removeNode");
const comp = ReactDOM.render(<Layer node={l} activateRemoveLayer={true} removeNode={actions.removeNode} />,
document.getElementById("container"));
expect(comp).toExist();
const domNode = ReactDOM.findDOMNode(comp);
expect(domNode).toExist();
const tool = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "clayer_removal_button")[0]);
expect(tool).toExist();
tool.click();
const confirmButton = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "btn-warning")[0]);
expect(confirmButton).toExist();
confirmButton.click();
expect(spy.calls.length).toBe(1);
});

it('tests settings tool', () => {
Expand All @@ -158,11 +184,11 @@ describe('test DefaultLayer module component', () => {
const tool = ReactDOM.findDOMNode(TestUtils.scryRenderedDOMComponentsWithClass(comp, "glyphicon")[1]);
expect(tool).toExist();
tool.click();
expect(spy.calls.length).toBe(0);
/* expect(spy.calls[0].arguments.length).toBe(3);
expect(spy.calls.length).toBe(1);
expect(spy.calls[0].arguments.length).toBe(3);
expect(spy.calls[0].arguments[0]).toBe("layerId1");
expect(spy.calls[0].arguments[1]).toBe("layers");
expect(spy.calls[0].arguments[2]).toEqual({opacity: 0.5});*/
expect(spy.calls[0].arguments[2]).toEqual({opacity: 0.5});
});

it('test that settings modal is present only if all the requirements are met', () => {
Expand Down Expand Up @@ -239,10 +265,10 @@ describe('test DefaultLayer module component', () => {
expect(tool).toExist();
tool.click();
// the onSettings method must have been invoked
expect(spy.calls.length).toBe(0);
/* expect(spy.calls[0].arguments.length).toBe(3);
expect(spy.calls.length).toBe(1);
expect(spy.calls[0].arguments.length).toBe(3);
expect(spy.calls[0].arguments[0]).toBe("layer1");
expect(spy.calls[0].arguments[1]).toBe("layers");
expect(spy.calls[0].arguments[2]).toEqual({opacity: 0.0}); */
expect(spy.calls[0].arguments[2]).toEqual({opacity: 0.0});
});
});
3 changes: 3 additions & 0 deletions web/client/plugins/TOC.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const LayerTree = React.createClass({
updateSettings: React.PropTypes.func,
updateNode: React.PropTypes.func,
removeNode: React.PropTypes.func,
activateRemoveLayer: React.PropTypes.bool,
activateLegendTool: React.PropTypes.bool,
activateSettingsTool: React.PropTypes.bool,
visibilityCheckType: React.PropTypes.string,
Expand All @@ -68,6 +69,7 @@ const LayerTree = React.createClass({
removeNode: () => {},
activateLegendTool: true,
activateSettingsTool: true,
activateRemoveLayer: true,
visibilityCheckType: "checkbox",
settingsOptions: {}
};
Expand Down Expand Up @@ -102,6 +104,7 @@ const LayerTree = React.createClass({
updateNode={this.props.updateNode}
removeNode={this.props.removeNode}
visibilityCheckType={this.props.visibilityCheckType}
activateRemoveLayer={this.props.activateRemoveLayer}
activateLegendTool={this.props.activateLegendTool}
activateSettingsTool={this.props.activateSettingsTool}
settingsText={<Message msgId="layerProperties.windowTitle"/>}
Expand Down

0 comments on commit 3416488

Please sign in to comment.