Skip to content

Commit

Permalink
Adding tests for increasing coverage on c125_annotations branch and o…
Browse files Browse the repository at this point in the history
…ther fixes (#3628)

* wip increasing tests and coverage
* add epic test
* add test ol measurement support
* add test ol measure support
* add ol drawsupport tests
* add test ol draw support circle click
* add more tests for drawsupport and measuresupport (ol)
* add tests drawsupport ol
* add more tests drawSupport ol
* add tests for openlayers components
* Fix #3601 problems on area and bearing
* update ol Feature lifecycle
* fix invalid area problem
* removed comment
* add tests for measurement and coordinate editor fixes
* reafctor the way coords are handled for measure coord editor, add related tests
* this has been done in order to avoid to make validation
* inside MeasurementSupport. validation before drawing is done
* via a selector
  • Loading branch information
MV88 authored Mar 21, 2019
1 parent 6f31e00 commit d14aae5
Show file tree
Hide file tree
Showing 52 changed files with 3,127 additions and 844 deletions.
9 changes: 8 additions & 1 deletion web/client/actions/__tests__/measurement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const {
init, INIT,
changeGeometry, CHANGED_GEOMETRY,
changeCoordinates, CHANGE_COORDINATES,
addAnnotation, ADD_MEASURE_AS_ANNOTATION
addAnnotation, ADD_MEASURE_AS_ANNOTATION,
updateMeasures, UPDATE_MEASURES
} = require('../measurement');
const feature = {type: "Feature", geometry: {
coordinates: [],
Expand Down Expand Up @@ -113,4 +114,10 @@ describe('Test correctness of measurement actions', () => {
expect(retval.type).toBe(CHANGE_COORDINATES);
expect(retval.coordinates).toEqual(coordinates);
});
it('Test updateMeasures action creator', () => {
const retval = updateMeasures({len: 0});
expect(retval).toExist();
expect(retval.type).toBe(UPDATE_MEASURES);
expect(retval.measures).toEqual({len: 0});
});
});
8 changes: 8 additions & 0 deletions web/client/actions/measurement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const RESET_GEOMETRY = 'MEASUREMENT:RESET_GEOMETRY';
const CHANGE_FORMAT = 'MEASUREMENT:CHANGE_FORMAT';
const CHANGE_COORDINATES = 'MEASUREMENT:CHANGE_COORDINATES';
const ADD_MEASURE_AS_ANNOTATION = 'MEASUREMENT:ADD_MEASURE_AS_ANNOTATION';
const UPDATE_MEASURES = 'MEASUREMENT:UPDATE_MEASURES';
const INIT = 'MEASUREMENT:INIT';

/**
Expand Down Expand Up @@ -79,6 +80,12 @@ function resetGeometry() {
type: RESET_GEOMETRY
};
}
function updateMeasures(measures) {
return {
type: UPDATE_MEASURES,
measures
};
}
function changeMeasurementState(measureState) {
return {
type: CHANGE_MEASUREMENT_STATE,
Expand Down Expand Up @@ -109,6 +116,7 @@ module.exports = {
changeUom, CHANGE_UOM,
changeGeometry, CHANGED_GEOMETRY,
changeFormatMeasurement, CHANGE_FORMAT,
updateMeasures, UPDATE_MEASURES,
changeCoordinates, CHANGE_COORDINATES,
resetGeometry, RESET_GEOMETRY,
addAnnotation, ADD_MEASURE_AS_ANNOTATION,
Expand Down
32 changes: 16 additions & 16 deletions web/client/components/map/openlayers/DrawSupport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class DrawSupport extends React.Component {
this.drawInteraction.on('drawend', function(evt) {
this.sketchFeature = evt.feature;
this.sketchFeature.set('id', uuid.v1());
let drawnGeom = evt.feature.getGeometry();
let drawnGeom = this.sketchFeature.getGeometry();
let drawnFeatures = this.drawLayer.getSource().getFeatures();
let previousGeometries;
let features = this.props.features;
Expand All @@ -395,7 +395,7 @@ class DrawSupport extends React.Component {
newFeature = this.getNewFeature(newDrawMethod, coordinates);
// TODO verify center is projected in 4326 and is an array
center = reproject(center, this.getMapCrs(), "EPSG:4326", false);
const originalId = newProps && newProps.features && newProps.features.length && newProps.features[0].features && newProps.features[0].features.length && newProps.features[0].features.filter(f => f.properties.isDrawing)[0].properties.id || this.sketchFeature.get("id");
const originalId = newProps && newProps.features && newProps.features.length && newProps.features[0] && newProps.features[0].features && newProps.features[0].features.length && newProps.features[0].features.filter(f => f.properties.isDrawing)[0].properties.id || this.sketchFeature.get("id");
// this.sketchFeature.set('id', originalId);
newFeature.setProperties({isCircle: true, radius, center: [center.x, center.y], id: originalId});
} else if (drawMethod === "Polygon") {
Expand Down Expand Up @@ -435,7 +435,7 @@ class DrawSupport extends React.Component {
const center = drawnGeom.getCenter();
const coordinates = this.polygonCoordsFromCircle(center, radius);
const newMultiGeom = this.toMulti(this.createOLGeometry({type: newDrawMethod, coordinates}));
if (features.length === 1 && !features[0].geometry) {
if (features.length === 1 && features[0] && !features[0].geometry) {
previousGeometries = [];
geomCollection = new ol.geom.GeometryCollection([newMultiGeom]);
} else {
Expand Down Expand Up @@ -730,8 +730,8 @@ class DrawSupport extends React.Component {
this.addFeatures(newProps);
}
};
addSingleClickListener = (singleclickCallback) => {
let evtKey = this.props.map.on('singleclick', singleclickCallback);
addSingleClickListener = (singleclickCallback, props) => {
let evtKey = props.map.on('singleclick', singleclickCallback);
return evtKey;
};

Expand All @@ -740,7 +740,7 @@ class DrawSupport extends React.Component {
if (this.state && this.state.keySingleClickCallback) {
ol.Observable.unByKey(this.state.keySingleClickCallback);
}
const singleClickCallback = (e) => {
const singleClickCallback = (event) => {
if (this.drawSource && newProps.options) {
let previousFeatures = this.drawSource.getFeatures();
let previousFtIndex = 0;
Expand All @@ -761,30 +761,30 @@ class DrawSupport extends React.Component {
if (isCompletePolygon(previousCoords)) {
// insert at penultimate position
actualCoords = slice(previousCoords[0], 0, previousCoords[0].length - 1);
actualCoords = actualCoords.concat([e.coordinate]);
actualCoords = actualCoords.concat([event.coordinate]);
actualCoords = [actualCoords.concat([previousCoords[0][0]])];
} else {
// insert at ultimate position if more than 2 point
actualCoords = previousCoords[0].length > 1 ? [[...previousCoords[0], e.coordinate, previousCoords[0][0] ]] : [[...previousCoords[0], e.coordinate ]];
actualCoords = previousCoords[0].length > 1 ? [[...previousCoords[0], event.coordinate, previousCoords[0][0] ]] : [[...previousCoords[0], event.coordinate ]];
}
} else {
// insert at first position
actualCoords = [[e.coordinate]];
actualCoords = [[event.coordinate]];
}
olFt = this.getNewFeature(newDrawMethod, actualCoords);
olFt.setProperties(omit(previousFt && previousFt.getProperties() || {}, "geometry"));
break;
}
case "LineString": case "MultiPoint": {
actualCoords = previousCoords.length ? [...previousCoords, e.coordinate] : [e.coordinate];
actualCoords = previousCoords.length ? [...previousCoords, event.coordinate] : [event.coordinate];
olFt = this.getNewFeature(newDrawMethod, actualCoords);
olFt.setProperties(omit(previousFt && previousFt.getProperties() || {}, "geometry"));
}
break;
case "Circle": {
newDrawMethod = "Polygon";
const radius = previousFt && previousFt.getProperties() && previousFt.getProperties().radius || 10000;
let center = e.coordinate;
let center = event.coordinate;
const coords = this.polygonCoordsFromCircle(center, 100);
olFt = this.getNewFeature(newDrawMethod, coords);
// TODO verify center is projected in 4326 and is an array
Expand All @@ -795,14 +795,14 @@ class DrawSupport extends React.Component {
}
case "Text": {
newDrawMethod = "Point";
olFt = this.getNewFeature(newDrawMethod, e.coordinate);
olFt = this.getNewFeature(newDrawMethod, event.coordinate);
olFt.setProperties(omit(previousFt && previousFt.getProperties() || {}, "geometry"));
olFt.setProperties({isText: true, valueText: previousFt && previousFt.getProperties() && previousFt.getProperties().valueText || newProps.options.defaultTextAnnotation || "New" });
break;
}
// point
default: {
actualCoords = e.coordinate;
actualCoords = event.coordinate;
olFt = this.getNewFeature(newDrawMethod, actualCoords);
olFt.setProperties(omit(previousFt && previousFt.getProperties() || {}, "geometry"));
}
Expand Down Expand Up @@ -835,7 +835,7 @@ class DrawSupport extends React.Component {
};
this.clean();

let newFeature = reprojectGeoJson(head(newProps.features), newProps.options.featureProjection, this.getMapCrs());
let newFeature = reprojectGeoJson(head(newProps.features), newProps.options.featureProjection, this.getMapCrs()) || {};
let props;
if (newFeature && newFeature.features && newFeature.features.length) {
// filtering circles features only when drawing
Expand Down Expand Up @@ -864,7 +864,7 @@ class DrawSupport extends React.Component {
this.addTranslateInteraction();
}
if (newProps.options.addClickCallback) {
this.setState({keySingleClickCallback: this.addSingleClickListener(singleClickCallback)});
this.setState({keySingleClickCallback: this.addSingleClickListener(singleClickCallback, newProps)});
}
}
if (newProps.options && newProps.options.selectEnabled) {
Expand Down Expand Up @@ -999,7 +999,7 @@ class DrawSupport extends React.Component {
// retrieve geodesic center from properties
// it's different from extent center
let center = geometryProperties && geometryProperties.geodesicCenter || ol.extent.getCenter(extent);
let coordinates = geometry.getCoordinates();
let coordinates;
let projection = this.props.map.getView().getProjection().getCode();
let radius;
let type = geometry.getType();
Expand Down
14 changes: 4 additions & 10 deletions web/client/components/map/openlayers/Feature.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,13 @@ class Feature extends React.Component {
// TODO check if shallow comparison is enough properties and geometry
return !isEqual(nextProps.properties, this.props.properties) ||
!isEqual(nextProps.geometry, this.props.geometry) ||
(nextProps.features !== this.props.features) ||
(nextProps.style !== this.props.style);
!isEqual(nextProps.features, this.props.features) ||
!isEqual(nextProps.style, this.props.style);
}

componentWillUpdate(nextProps) {
// TODO check if shallow comparison is enough properties and geometry
if (!isEqual(nextProps.properties, this.props.properties) ||
!isEqual(nextProps.geometry, this.props.geometry) ||
(nextProps.features !== this.props.features) ||
(nextProps.style !== this.props.style)) {
this.removeFromContainer();
this.addFeatures(nextProps);
}
this.removeFromContainer();
this.addFeatures(nextProps);
}

componentWillUnmount() {
Expand Down
8 changes: 6 additions & 2 deletions web/client/components/map/openlayers/LegacyVectorStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var ol = require('openlayers');
const {last, head} = require('lodash');
const blue = [0, 153, 255, 1];
const assign = require('object-assign');
const {trim, isString} = require('lodash');
const {trim, isString, isArray} = require('lodash');
const {colorToRgbaStr} = require('../../../utils/ColorUtils');
const {set} = require('../../../utils/ImmutableUtils');
const selectedStyleConfiguration = {
Expand Down Expand Up @@ -485,7 +485,11 @@ function getStyle(options, isDrawing = false, textValues = []) {
}));
}
let gStyle = getValidStyle(type, options, isDrawing, textValues);
gStyle.setGeometry(c);
if (isArray(gStyle)) {
gStyle.forEach(s => s.setGeometry(c));
} else {
gStyle.setGeometry(c);
}
return p.concat([gStyle]);
}, []);
return styles;
Expand Down
Loading

0 comments on commit d14aae5

Please sign in to comment.