Skip to content

Commit

Permalink
added tests and fixed wfsquery epic
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed May 15, 2017
1 parent aa4b54b commit 8869c0b
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 24 deletions.
29 changes: 29 additions & 0 deletions web/client/actions/__tests__/queryform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
EXPAND_ATTRIBUTE_PANEL,
EXPAND_SPATIAL_PANEL,
SELECT_SPATIAL_METHOD,
UPDATE_GEOMETRY,
SELECT_SPATIAL_OPERATION,
REMOVE_SPATIAL_SELECT,
SHOW_SPATIAL_DETAILS,
Expand All @@ -35,6 +36,8 @@ const {
ADD_SIMPLE_FILTER_FIELD,
REMOVE_SIMPLE_FILTER_FIELD,
REMOVE_ALL_SIMPLE_FILTER_FIELDS,
SELECT_VIEWPORT_SPATIAL_METHOD,
CHANGE_SPATIAL_ATTRIBUTE,
changeDwithinValue,
resetZones,
zoneChange,
Expand All @@ -56,8 +59,11 @@ const {
expandAttributeFilterPanel,
expandSpatialFilterPanel,
selectSpatialMethod,
updateGeometrySpatialField,
selectViewportSpatialMethod,
selectSpatialOperation,
removeSpatialSelection,
changeSpatialAttribute,
showSpatialSelectionDetails,
simpleFilterFieldUpdate,
addSimpleFilterField,
Expand Down Expand Up @@ -89,6 +95,29 @@ describe('Test correctness of the queryform actions', () => {
expect(retval.index).toBe(0);
});

it('updateGeometrySpatialField', () => {
const geometry = {center: [0, 1], coordinates: []};
const retval = updateGeometrySpatialField(geometry);

expect(retval).toExist();
expect(retval.type).toBe(UPDATE_GEOMETRY);
expect(retval.geometry).toBe(geometry);
});

it('selectViewportSpatialMethod', () => {
const retval = selectViewportSpatialMethod();
expect(retval).toExist();
expect(retval.type).toBe(SELECT_VIEWPORT_SPATIAL_METHOD);
});

it('changeSpatialAttribute', () => {
const attribute = "some value";
const retval = changeSpatialAttribute(attribute);
expect(retval).toExist();
expect(retval.type).toBe(CHANGE_SPATIAL_ATTRIBUTE);
expect(retval.attribute).toBe(attribute);
});

it('removeFilterField', () => {
let rowId = 100;

Expand Down
4 changes: 2 additions & 2 deletions web/client/actions/queryform.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function selectSpatialMethod(method, fieldName) {
};
}

function selectViewportSM() {
function selectViewportSpatialMethod() {
return {
type: SELECT_VIEWPORT_SPATIAL_METHOD
};
Expand Down Expand Up @@ -339,7 +339,7 @@ module.exports = {
SELECT_VIEWPORT_SPATIAL_METHOD,
UPDATE_GEOMETRY,
updateGeometrySpatialField,
selectViewportSM,
selectViewportSpatialMethod,
resetZones,
zoneChange,
// openMenu,
Expand Down
2 changes: 1 addition & 1 deletion web/client/components/data/query/QueryBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const QueryBuilder = React.createClass({
onChangeDrawingStatus: () => {},
onRemoveSpatialSelection: () => {},
onShowSpatialSelectionDetails: () => {},
onSelectViewportSM: () => {},
onSelectViewportSpatialMethod: () => {},
onEndDrawing: () => {},
onChangeDwithinValue: () => {}
},
Expand Down
6 changes: 3 additions & 3 deletions web/client/components/data/query/SpatialFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const SpatialFilter = React.createClass({
onRemoveSpatialSelection: () => {},
onShowSpatialSelectionDetails: () => {},
onEndDrawing: () => {},
onSelectViewportSM: () => {},
onSelectViewportSpatialMethod: () => {},
onChangeDwithinValue: () => {},
zoneFilter: () => {},
zoneSearch: () => {},
Expand Down Expand Up @@ -213,7 +213,7 @@ const SpatialFilter = React.createClass({
const selectedOperation = this.props.spatialOperations.filter((opt) => this.props.spatialField.operation === opt.id)[0];

let drawLabel = (<span/>);
if (this.props.spatialField.method && this.props.spatialField.method !== "ZONE") {
if (this.props.spatialField.method && this.props.spatialField.method !== "ZONE" && this.props.spatialField.method !== "Viewport") {
drawLabel = !this.props.spatialField.geometry ? (
<span>
<hr width="100%"/>
Expand Down Expand Up @@ -322,7 +322,7 @@ const SpatialFilter = React.createClass({
}
case "Viewport": {
this.changeDrawingStatus('clean', null, "queryform", []);
this.props.actions.onSelectViewportSM();
this.props.actions.onSelectViewportSpatialMethod();
break;
}
default: {
Expand Down
35 changes: 21 additions & 14 deletions web/client/epics/wfsquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,28 @@ function validateExtent(extent) {
const viewportSelectedEpic = (action$, store) =>
action$.ofType(SELECT_VIEWPORT_SPATIAL_METHOD, CHANGE_MAP_VIEW)
.switchMap((action) => {
// calculate new geometry from map properties
// calculate new geometry from map properties only for viewport
const map = action.type === CHANGE_MAP_VIEW ? action : store.getState().map.present;
const bounds = Object.keys(map.bbox.bounds).reduce((p, c) => {
return assign({}, p, {[c]: parseFloat(map.bbox.bounds[c])});
}, {});
const extent = validateExtent([bounds.minx, bounds.miny, bounds.maxx, bounds.maxy]);
const center = [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
const start = [extent[0], extent[1]];
const end = [extent[2], extent[3]];
const coordinates = [[start, [start[0], end[1]], end, [end[0], start[1]], start]];
let geometry = {
type: "Polygon", radius: 0, projection: "EPSG:4326",
extent, center, coordinates
};
return Rx.Observable.of(updateGeometrySpatialField(geometry));
if (action.type === SELECT_VIEWPORT_SPATIAL_METHOD ||
action.type === CHANGE_MAP_VIEW &&
store.getState().queryform &&
store.getState().queryform.spatialField &&
store.getState().queryform.spatialField.method === "viewport") {
const bounds = Object.keys(map.bbox.bounds).reduce((p, c) => {
return assign({}, p, {[c]: parseFloat(map.bbox.bounds[c])});
}, {});
const extent = validateExtent([bounds.minx, bounds.miny, bounds.maxx, bounds.maxy]);
const center = [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
const start = [extent[0], extent[1]];
const end = [extent[2], extent[3]];
const coordinates = [[start, [start[0], end[1]], end, [end[0], start[1]], start]];
let geometry = {
type: "Polygon", radius: 0, projection: "EPSG:4326",
extent, center, coordinates
};
return Rx.Observable.of(updateGeometrySpatialField(geometry));
}
return Rx.Observable.empty();
});

/**
Expand Down
4 changes: 2 additions & 2 deletions web/client/plugins/QueryPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const {
expandAttributeFilterPanel,
expandSpatialFilterPanel,
selectSpatialMethod,
selectViewportSM,
selectViewportSpatialMethod,
selectSpatialOperation,
removeSpatialSelection,
showSpatialSelectionDetails,
Expand Down Expand Up @@ -96,7 +96,7 @@ const SmartQueryForm = connect((state) => {
spatialFilterActions: bindActionCreators({
onExpandSpatialFilterPanel: expandSpatialFilterPanel,
onSelectSpatialMethod: selectSpatialMethod,
onSelectViewportSM: selectViewportSM,
onSelectViewportSpatialMethod: selectViewportSpatialMethod,
onSelectSpatialOperation: selectSpatialOperation,
onChangeDrawingStatus: changeDrawingStatus,
onRemoveSpatialSelection: removeSpatialSelection,
Expand Down
4 changes: 2 additions & 2 deletions web/client/plugins/TOC.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const {
expandAttributeFilterPanel,
expandSpatialFilterPanel,
selectSpatialMethod,
selectViewportSM,
selectViewportSpatialMethod,
selectSpatialOperation,
removeSpatialSelection,
showSpatialSelectionDetails,
Expand Down Expand Up @@ -106,7 +106,7 @@ const SmartQueryForm = connect((state) => {
spatialFilterActions: bindActionCreators({
onExpandSpatialFilterPanel: expandSpatialFilterPanel,
onSelectSpatialMethod: selectSpatialMethod,
onSelectViewportSM: selectViewportSM,
onSelectViewportSpatialMethod: selectViewportSpatialMethod,
onSelectSpatialOperation: selectSpatialOperation,
onChangeDrawingStatus: changeDrawingStatus,
onRemoveSpatialSelection: removeSpatialSelection,
Expand Down
79 changes: 79 additions & 0 deletions web/client/reducers/__tests__/queryform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,85 @@ describe('Test the queryform reducer', () => {
expect(state.showDetailsPanel).toEqual(true);
});

it('test UPDATE_GEOMETRY', () => {
const geometry = {center: [0, 1], coordinates: []};
let testAction = {
type: "UPDATE_GEOMETRY",
geometry
};
const initialState = { spatialField: {geometry: {}} };
let state = queryform(initialState, testAction);
expect(state).toExist();
expect(state.spatialField.geometry).toEqual(geometry);
});

it('test CHANGE_SPATIAL_ATTRIBUTE', () => {
const attribute = "some value";
let testAction = {
type: "CHANGE_SPATIAL_ATTRIBUTE",
attribute
};
const initialState = { spatialField: {attribute: {}} };
let state = queryform(initialState, testAction);
expect(state).toExist();
expect(state.spatialField.attribute).toEqual(attribute);
});

it('test CHANGE_DRAWING_STATUS', () => {
const initialState = { toolbarEnabled: true };
const testAction1 = {
type: "CHANGE_DRAWING_STATUS",
owner: "queryform",
status: "start"
};
const state = queryform(initialState, testAction1);
expect(state).toExist();
expect(state.toolbarEnabled).toBeFalsy();
const testAction2 = {
type: "CHANGE_DRAWING_STATUS",
owner: "measure",
status: "start"
};
const state2 = queryform(initialState, testAction2);
expect(state2).toExist();
expect(state2.toolbarEnabled).toBeTruthy();
});

it('test END_DRAWING', () => {
const geometry = {center: [0, 1], coordinates: []};
const initialState = { toolbarEnabled: false, spatialField: {geometry: {}} };
const testAction1 = {
type: "END_DRAWING",
owner: "queryform",
geometry
};
const state = queryform(initialState, testAction1);
expect(state).toExist();
expect(state.toolbarEnabled).toBeTruthy();
expect(state.spatialField.geometry).toBe(geometry);
const testAction2 = {
type: "END_DRAWING",
owner: "measure",
status: "start"
};
const state2 = queryform(initialState, testAction2);
expect(state2).toExist();
expect(state2.toolbarEnabled).toBeFalsy();
expect(state2.spatialField.geometry).toEqual({});
});

it('test CHANGE_DWITHIN_VALUE', () => {
const initialState = { spatialField: {geometry: { distance: {}}} };
const distance = 123;
const testAction1 = {
type: "CHANGE_DWITHIN_VALUE",
distance
};
const state = queryform(initialState, testAction1);
expect(state).toExist();
expect(state.spatialField.geometry.distance).toBe(distance);
});

it('Query Form Reset', () => {
let testAction = {
type: "QUERY_FORM_RESET"
Expand Down

0 comments on commit 8869c0b

Please sign in to comment.