Skip to content

Commit

Permalink
added more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Nov 16, 2017
1 parent 752ee92 commit fd1bac3
Show file tree
Hide file tree
Showing 33 changed files with 883 additions and 66 deletions.
2 changes: 1 addition & 1 deletion web/client/components/charts/Gauge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const GaugeChart = ({data, xAxis = {}, colorGenerator, series = [], width=500, h
key={`pie-${i}`}
isAnimationActive={isAnimationActive}
activeIndex={activeSectorIndex}
activeShape={useActive && ActiveSectorMark}
activeShape={useActive ? ActiveSectorMark : undefined}
data={colorData.map( cd => ({realValue: chartValue, name: d.name, ...cd}))}
fill="#8884d8"
{ ...pieRadius }
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/misc/EmptyView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ module.exports = ({
iconFit,
title,
tooltip,
tooltipId,
description,
content
} = {}) =>
(<div className="empty-state-container" style={{height: iconFit ? "100%" : undefined, ...style}}>
<div key="main-view" className="empty-state-main-view" style={{height: iconFit ? "100%" : undefined, ...mainViewStyle}} >
{glyph
? <div key="glyph" className="empty-state-image" style={{height: iconFit ? "100%" : undefined}}>
<FitIcon iconFit={iconFit} tooltip={tooltip} glyph={glyph} />
<FitIcon iconFit={iconFit} tooltip={tooltip} tooltipId={tooltipId} glyph={glyph} />
</div>
: null}
{title ? <h1 key="title" >{title}</h1> : null}
Expand Down
4 changes: 2 additions & 2 deletions web/client/components/misc/FitIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ const Glyph = enhanceTooltip(Glyphicon);
* @prop {tooltip} [tooltip] tooltip
* @prop {iconfit} [iconfit] if true, the icon will fit min height or width.
*/
module.exports = ({glyph = "info-sign", tooltip, iconFit}) => (<ContainerDimensions>
{ ({ width, height }) => (<Glyph glyph={glyph} tooltip={tooltip} style={{fontSize: iconFit ? Math.min(width, height) : width}} />)}
module.exports = ({glyph = "info-sign", tooltip, tooltipId, iconFit}) => (<ContainerDimensions>
{ ({ width, height }) => (<Glyph glyph={glyph} tooltip={tooltip} tooltipId={tooltipId} style={{fontSize: iconFit ? Math.min(width, height) : width}} />)}
</ContainerDimensions>);
11 changes: 6 additions & 5 deletions web/client/components/misc/wizard/WizardContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class WizardComponent extends React.Component {
const childrenLenght = children.length >= 0 ? children.length : 1;
if (this.props.hideButtons) return null;
if (this.props.step > 0) {
buttons.push(<Button className="ms-wizard-prev" onClick={() => this.props.onPrevPage()} ><Message msgId="wizard.prev" /></Button>);
buttons.push(<Button key="prev" className="ms-wizard-prev" onClick={() => this.props.onPrevPage()} ><Message msgId="wizard.prev" /></Button>);
}
if ( this.props.step >= childrenLenght - 1) {
buttons.push(<Button className="ms-wizard-finish" onClick={() => this.props.onFinish()} ><Message msgId="wizard.finish" /></Button>);
buttons.push(<Button key="finish" className="ms-wizard-finish" onClick={() => this.props.onFinish()} ><Message msgId="wizard.finish" /></Button>);
} else if (this.props.step < childrenLenght - 1 && childrenLenght > 1) {
buttons.push(<Button className="ms-wizard-next" disabled={!isStepValid(this.props.step)} onClick={() => this.props.onNextPage()} ><Message msgId="wizard.next" /></Button>);
buttons.push(<Button key="next" className="ms-wizard-next" disabled={!isStepValid(this.props.step)} onClick={() => this.props.onNextPage()} ><Message msgId="wizard.next" /></Button>);
}
return buttons;

Expand All @@ -65,16 +65,17 @@ class WizardComponent extends React.Component {
const children = this.props.children || [];
const childrenLenght = children.length >= 0 ? children.length : 1;
return (
<div className="ms-wizard">
<div key="wizard-pages" className="ms-wizard">
{React.Children.map(children, (child, i) => {
if (i === this.props.step) {
return React.cloneElement(child, {
key: `wizard-component-${i}`,
onNextPage: this.props.step === childrenLenght - 1 ? this.props.onFinish : this.props.onNextPage,
onPrevPage: this.props.onPrevPage
});
}
})}
<Row className="ms-wizard-buttons">
<Row key="wizard-buttons" className="ms-wizard-buttons">
{this.renderButtons()}
</Row>
</div>
Expand Down
5 changes: 2 additions & 3 deletions web/client/components/style/ColorRangeSelector.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const React = require('react');
const PropTypes = require('prop-types');
const {head} = require('lodash');
const ColorUtils = require('../../utils/ColorUtils');
const ColorRampItem = require('./EqualIntervalComponents/ColorRampItem');
const DropdownList = require('react-widgets').DropdownList;
Expand All @@ -9,7 +8,7 @@ class ColorRangeSelector extends React.Component {
static propTypes = {
value: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
samples: PropTypes.number,
onChange: PropTypes.funct,
onChange: PropTypes.func,
items: PropTypes.array
};
static contextTypes = {
Expand Down Expand Up @@ -51,7 +50,7 @@ class ColorRangeSelector extends React.Component {
});
}
getValue = () => {
head(this.getItems().filter( (i = {}) => i === this.props.value || i.name === (this.props.value && this.props.value.name)));
this.getItems().filter( (i = {}) => i === this.props.value || i.name === (this.props.value && this.props.value.name));
}
getItems = () => {
return this.props.items.map(({options = {}, ...item}) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const colors = require("./ExtendColorBrewer");
const Message = require('../../I18N/Message');
class ColorRampItem extends React.Component {
static propTypes = {
item: PropTypes.object
item: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/widgets/builder/BuilderHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Toolbar = require('../../misc/toolbar/Toolbar');
module.exports = ({onClose = () => {}, openFilterEditor = () => {}} = {}) =>
(<div className="mapstore-flex-container">
<div className="m-header">
<Row fluid>
<Row>
<Col md={12} className="text-center" style={{overflow: 'hidden', lineHeight: '52px'}}>
<Button onClick={() => onClose()} className="pull-left square-button no-border ">
<Glyphicon glyph="1-close"/>
Expand Down
31 changes: 17 additions & 14 deletions web/client/components/widgets/builder/ChartWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,25 @@ module.exports = ({onChange = () => {}, onFinish = () => {}, setPage= () => {},
}}
isStepValid={ n => n === 1 ? isChartOptionsValid(data.options) : true} skipButtonsOnSteps={[0]}>
<ChartType
key="type"
type={data.type}
onSelect={ i => {
onChange("type", i);
}}/>
<ChartOptions
featureTypeProperties={featureTypeProperties}
types={types}
data={data}
onChange={onChange}
layer={data.layer || layer}
sampleChart={renderPreview({data, layer: data.layer || layer, dependencies})}
/>
<WidgetOptions
data={data}
onChange={onChange}
layer={data.layer || layer}
sampleChart={renderPreview({data, layer: data.layer || layer})}
/>
<ChartOptions
key="chart-options"
featureTypeProperties={featureTypeProperties}
types={types}
data={data}
onChange={onChange}
layer={data.layer || layer}
sampleChart={renderPreview({data, layer: data.layer || layer, dependencies})}
/>
<WidgetOptions
key="widget-options"
data={data}
onChange={onChange}
layer={data.layer || layer}
sampleChart={renderPreview({data, layer: data.layer || layer})}
/>
</Wizard>);
2 changes: 1 addition & 1 deletion web/client/components/widgets/builder/WidgetsBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const React = require('react');

const ChartWizard = require('./ChartWizard');
module.exports = ({
settings = {},
settings = {step: 0},
insertWidget = () => {},
onEditorChange = () => {},
setPage = () => {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 ReactDOM = require('react-dom');

const expect = require('expect');
const WidgetsBuilder = require('../WidgetsBuilder');
describe('WidgetsBuilder 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('WidgetsBuilder rendering with defaults', () => {
ReactDOM.render(<WidgetsBuilder />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.ms-wizard');
expect(el).toExist();
expect(container.querySelector('.chart-options-form')).toNotExist();
});
it('WidgetsBuilder rendering chart options', () => {
ReactDOM.render(<WidgetsBuilder settings={{step: 1}} />, document.getElementById("container"));
const container = document.getElementById('container');
const el = container.querySelector('.chart-options-form');
expect(el).toExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree.
*/
const React = require('react');
const {head} = require('lodash');
const {Row, Col, Form, FormGroup, ControlLabel} = require('react-bootstrap');
const Message = require('../../../../I18N/Message');
const Select = require('react-select');
Expand Down Expand Up @@ -108,7 +109,7 @@ module.exports = ({data = {options: {}}, onChange = () => {}, options=[], aggreg
<Col sm={6}>
<ColorRangeSelector
items={getColorRangeItems(data.type)}
value={getColorRangeItems(data.type).filter(c => c.name === data.colorRangeName)}
value={head(getColorRangeItems(data.type).filter(c => c.name === data.colorRangeName))}
samples={data.type === "pie" ? 5 : 1}
onChange={v => {onChange("autoColorOptions", v.options); onChange("colorRangeName", v.name); }}/>
</Col>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 ReactDOM = require('react-dom');
const expect = require('expect');
const builderConfiguration = require('../builderConfiguration');
const WidgetBuilder = builderConfiguration(require('../../builder/WidgetsBuilder'));
describe('widgets builderConfiguration 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('test builder describeFeatureType and describeProcess calls', (done) => {
const actions = {
onEditorChange: (key, value) => {
expect(key).toBe("geomProp");
expect(value).toBe("the_geom");
done();
}
};
ReactDOM.render(
(<WidgetBuilder
layer={{url: 'base/web/client/test-resources/widgetbuilder/wms', search: {url: 'base/web/client/test-resources/widgetbuilder/wfs'}}}
onEditorChange={actions.onEditorChange} />),
document.getElementById("container"));
});
it('error management', (done) => {
const actions = {
onConfigurationError: () => {
setTimeout(() => {
expect(document.querySelector('.empty-state-container')).toExist();
done();
}, 100);

}
};
ReactDOM.render(
(<WidgetBuilder
layer={{url: 'base/web/client/test-resources/widgetbuilder/wms', search: {url: 'base/web/client/test-resources/widgetbuilder/no-data'}}}
onConfigurationError={actions.onConfigurationError} />),
document.getElementById("container"));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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 ReactDOM = require('react-dom');
const {createSink} = require('recompose');
const expect = require('expect');
const dependenciesToFilter = require('../dependenciesToFilter');
const filterObj = {
spatialField: {
"operation": "INTERSECTS",
"attribute": "geometry",
"geometry": {
"type": "Polygon",
"projection": "EPSG:4326",
"coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]]
}
}
};
const filterObjRes1 =
"<ogc:Filter><ogc:And><ogc:Intersects>"
+ "<ogc:PropertyName>geometry</ogc:PropertyName>"
+ "<gml:Polygon srsName=\"EPSG:4326\"><gml:exterior><gml:LinearRing><gml:posList>1 1 1 2 2 2 2 1 1 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>"
+ "</ogc:Intersects></ogc:And></ogc:Filter>";
const mergeFilterRes =
'<ogc:Filter><ogc:And>'
+ '<ogc:Intersects>'
+ '<ogc:PropertyName>geometry</ogc:PropertyName><gml:Polygon srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>1 1 1 2 2 2 2 1 1 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>'
+ '</ogc:Intersects>'
+ '<ogc:Intersects>'
+ '<ogc:PropertyName>geometry</ogc:PropertyName><gml:Polygon srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>-1 -1 -1 1 1 1 1 -1 -1 -1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon>'
+ '</ogc:Intersects>'
+ '</ogc:And></ogc:Filter>';
describe('widgets dependenciesToFilter 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('dependenciesToFilter default', (done) => {
const Sink = dependenciesToFilter(createSink( props => {
expect(props).toExist();
expect(props.filter).toBe(undefined);
done();
}));
ReactDOM.render(<Sink />, document.getElementById("container"));
});
it('dependenciesToFilter spatial filter', (done) => {
const Sink = dependenciesToFilter(createSink( props => {
expect(props).toExist();
expect(props.filter).toBe(filterObjRes1);
done();
}));
ReactDOM.render(<Sink filter={filterObj}/>, document.getElementById("container"));
});
it('dependenciesToFilter with mapsync and spatial filter', (done) => {
const Sink = dependenciesToFilter(createSink( props => {
expect(props).toExist();
expect(props.filter).toBe(mergeFilterRes);
done();
}));
ReactDOM.render(<Sink
mapSync
geomProp={"geometry"}
dependencies={ {
viewport: {"bounds": {"minx": "-1", "miny": "-1", "maxx": "1", "maxy": "1"}, "crs": "EPSG:4326", "rotation": 0}
} } filter={filterObj}/>, document.getElementById("container"));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 ReactDOM = require('react-dom');

const expect = require('expect');
const emptyChartState = require('../emptyChartState');

describe('widgets emptyChartState 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('emptyChartState rendering with defaults', () => {
const Dummy = emptyChartState(() => <div id="dummy"></div>);
ReactDOM.render(<Dummy data={[]}/>, document.getElementById("container"));
expect(document.getElementById("dummy")).toNotExist();
});
it('emptyChartState rendering with data', () => {
const Dummy = emptyChartState(() => <div id="dummy"></div>);
ReactDOM.render(<Dummy data={["a"]}/>, document.getElementById("container"));
expect(document.getElementById("dummy")).toExist();
});
});
Loading

0 comments on commit fd1bac3

Please sign in to comment.