Skip to content

Commit

Permalink
geosolutions-it#9216: resolve review comments by handling required un…
Browse files Browse the repository at this point in the history
…it tests
  • Loading branch information
mahmoudadel54 committed Nov 10, 2023
1 parent 3f1d471 commit 5a37128
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 2 deletions.
40 changes: 39 additions & 1 deletion web/client/actions/__tests__/wfsquery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import expect from 'expect';
import {
LAYER_SELECTED_FOR_SEARCH,
FEATURE_TYPE_SELECTED,
FEATURE_TYPE_LOADED,
FEATURE_TYPE_ERROR,
FEATURE_LOADING,
FEATURE_LOADED,
Expand All @@ -25,6 +26,7 @@ import {
initQueryPanel,
layerSelectedForSearch,
featureTypeSelected,
featureTypeLoaded,
featureTypeError,
featureLoading,
featureLoaded,
Expand All @@ -47,13 +49,36 @@ describe('wfsquery actions', () => {
let {type} = initQueryPanel();
expect(type).toBe(INIT_QUERY_PANEL);
});
it('featureTypeSelected', () => {
it('featureTypeSelected without owner', () => {
let {type, url, typeName, fields} = featureTypeSelected("/geoserver/", "topp:states", [{name: "name", alias: "alias"}]);
expect(type).toBe(FEATURE_TYPE_SELECTED);
expect(url).toBe("/geoserver/");
expect(typeName).toBe("topp:states");
expect(fields).toEqual([{name: "name", alias: "alias"}]);
});

it('featureTypeSelected with owner as parameter', () => {
let {type, url, typeName, fields, owner} = featureTypeSelected("/geoserver/", "topp:states", [{name: "name", alias: "alias"}], "owner");
expect(type).toBe(FEATURE_TYPE_SELECTED);
expect(url).toBe("/geoserver/");
expect(typeName).toBe("topp:states");
expect(fields).toEqual([{name: "name", alias: "alias"}]);
expect(owner).toBe("owner");
});
it('featureTypeLoaded without owner', () => {
let {type, typeName, featureType} = featureTypeLoaded("topp:states", "featureType");
expect(type).toBe(FEATURE_TYPE_LOADED);
expect(typeName).toBe("topp:states");
expect(featureType).toBe("featureType");
});

it('featureTypeLoaded with owner as parameter', () => {
let {type, typeName, featureType, owner} = featureTypeLoaded("topp:states", "featureType", "owner");
expect(type).toBe(FEATURE_TYPE_LOADED);
expect(typeName).toBe("topp:states");
expect(featureType).toBe("featureType");
expect(owner).toBe("owner");
});
it('featureTypeError', () => {
let {type, error, typeName} = featureTypeError("topp:states", "ERROR");
expect(type).toBe(FEATURE_TYPE_ERROR);
Expand All @@ -71,6 +96,12 @@ describe('wfsquery actions', () => {
expect(typeName).toBe("topp:states");
expect(feature).toBe(feature);
});
it('featureLoaded with owner as parameter', () => {
let {type, typeName, feature} = featureLoaded("topp:states", "feature");
expect(type).toBe(FEATURE_LOADED);
expect(typeName).toBe("topp:states");
expect(feature).toBe(feature);
});
it('featureError', () => {
let {type, typeName, error} = featureError("topp:states", "ERROR");
expect(type).toBe(FEATURE_ERROR);
Expand All @@ -95,6 +126,13 @@ describe('wfsquery actions', () => {
expect(searchUrl).toBe("searchUrl");
expect(filterObj).toBe("filterObj");
});
it('createQuery with owner param', () => {
let {type, searchUrl, filterObj, owner} = createQuery("searchUrl", "filterObj", "owner");
expect(type).toBe(QUERY_CREATE);
expect(searchUrl).toBe("searchUrl");
expect(filterObj).toBe("filterObj");
expect(owner).toBe("owner");
});
it('query', () => {
let {type, searchUrl, filterObj} = query("searchUrl", "filterObj");
expect(type).toBe(QUERY);
Expand Down
148 changes: 148 additions & 0 deletions web/client/epics/__tests__/wfsquery-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,152 @@ describe('wfsquery Epics', () => {
}, mockState);
});
});


describe('featureTypeSelectedEpic with owner', () => {
const expectedResult = require('../../test-resources/vector/feature-collection-vector.json');
const flatLayers = [{
id: 'layer1',
name: 'layer1 name',
title: 'layer1 title',
description: 'layer1 description',
type: 'vector',
features: expectedResult
}];
const wmsLayer = [{
id: 'layer2',
name: 'poi',
title: 'layer2 title',
description: 'layer2 description',
type: 'wms',
fields: [{
name: "NAME",
alias: "Name Alias",
type: "string"
}]
}];
it('vector layer', (done) => {
const mockState = {
query: {
data: {},
featureTypes: [],
typeName: 'layer1',
url: '/dummy'},
featuregrid: {
timeSync: true,
pagination: {
size: 10
},
open: true,
selectedLayer: "layer1",
changes: [],
mode: 'VIEW'
},
layers: {
flat: flatLayers,
layerMetadata: {
expanded: false,
maskLoading: false
},
settings: {
expanded: false,
node: null,
nodeType: null,
options: {}
}
}
};
mockAxios.onPost().reply(() => {return [200, expectedResult];});
testEpic(addTimeoutEpic(wfsQueryEpic, 500), 4, [
query("base/web/client/test-resources/vector/feature-collection-vector.json", {pagination: {} }),
featureTypeSelected('/dummy', 'layer1', [], "widgets")
], actions => {
expect(actions.length).toBe(4);
actions.map((action) => {
switch (action.type) {
case QUERY_RESULT:
expect(action.result.features).toEqual(expectedResult);
expect(action.result.totalFeatures).toEqual(expectedResult.length);
expect(action.result.numberMatched).toEqual(expectedResult.length);
expect(action.result.numberReturned).toEqual(expectedResult.length);
break;
case FEATURE_LOADING:
break;
case LAYER_LOAD:
break;
default:
expect(false).toBe(true);
}
});
done();
},
mockState
);
});

it('wms layer', (done) => {
const mockState = {
query: {
data: {},
featureTypes: [],
typeName: 'layer1',
url: '/dummy'},
featuregrid: {
timeSync: true,
pagination: {
size: 10
},
open: true,
selectedLayer: "layer1",
changes: [],
mode: 'VIEW'
},
layers: {
flat: wmsLayer,
layerMetadata: {
expanded: false,
maskLoading: false
},
settings: {
expanded: false,
node: null,
nodeType: null,
options: {}
}
}
};
const wfsResults = require('../../test-resources/wfs/describe-pois.json');
mockAxios.onGet().reply(() => [200, wfsResults]);
testEpic(featureTypeSelectedEpic, 2,
featureTypeSelected('/dummy', 'poi', wmsLayer[0].fields), ([changeSpatialAttribute, featureTypeLoaded]) => {
try {
expect(featureTypeLoaded.type).toBe(FEATURE_TYPE_LOADED);
expect(changeSpatialAttribute.type).toBe(CHANGE_SPATIAL_ATTRIBUTE);
expect(featureTypeLoaded.featureType.attributes).toEqual([{
label: "Name Alias",
attribute: "NAME",
type: "string",
valueId: "id",
valueLabel: "name",
values: []
},
{
label: "THUMBNAIL",
attribute: "THUMBNAIL",
type: "string",
valueId: "id",
valueLabel: "name",
values: []
},
{
label: "MAINPAGE", attribute: "MAINPAGE", type: "string", valueId: "id", valueLabel: "name", values: []
}]);

} catch (error) {
done(error);
}
done();
}, mockState);
});
});
});
1 change: 1 addition & 0 deletions web/client/epics/__tests__/widgetsbuilder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ describe('widgetsbuilder epic', () => {
type: "string",
alias: "X alias"
}]);
expect(action.owner).toEqual("widgets");
break;
case LOAD_FILTER:
break;
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/widgetsbuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const handleWidgetsFilterPanel = (action$, {getState = () => {}} = {}) =>
.switchMap(() =>
// open and setup query form
Rx.Observable.of(
featureTypeSelected(...getFTSelectedArgs(getState())),
featureTypeSelected(...getFTSelectedArgs(getState()).concat(["widgets"])),
loadFilter(getEditingWidgetFilter(getState())),
setControlProperty("widgetBuilder", "enabled", false),
setControlProperty('queryPanel', "enabled", true)
Expand Down

0 comments on commit 5a37128

Please sign in to comment.