From 5a371284742f6b167de11d936fa6a662c5cef07f Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Fri, 10 Nov 2023 16:47:51 +0200 Subject: [PATCH] #9216: resolve review comments by handling required unit tests --- web/client/actions/__tests__/wfsquery-test.js | 40 ++++- web/client/epics/__tests__/wfsquery-test.js | 148 ++++++++++++++++++ .../epics/__tests__/widgetsbuilder-test.js | 1 + web/client/epics/widgetsbuilder.js | 2 +- 4 files changed, 189 insertions(+), 2 deletions(-) diff --git a/web/client/actions/__tests__/wfsquery-test.js b/web/client/actions/__tests__/wfsquery-test.js index b4c65be7e6..3fa2f53473 100644 --- a/web/client/actions/__tests__/wfsquery-test.js +++ b/web/client/actions/__tests__/wfsquery-test.js @@ -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, @@ -25,6 +26,7 @@ import { initQueryPanel, layerSelectedForSearch, featureTypeSelected, + featureTypeLoaded, featureTypeError, featureLoading, featureLoaded, @@ -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); @@ -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); @@ -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); diff --git a/web/client/epics/__tests__/wfsquery-test.js b/web/client/epics/__tests__/wfsquery-test.js index 06939c7d5b..56c5c73a1f 100644 --- a/web/client/epics/__tests__/wfsquery-test.js +++ b/web/client/epics/__tests__/wfsquery-test.js @@ -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); + }); + }); }); diff --git a/web/client/epics/__tests__/widgetsbuilder-test.js b/web/client/epics/__tests__/widgetsbuilder-test.js index fbe6f60980..e7a259f70b 100644 --- a/web/client/epics/__tests__/widgetsbuilder-test.js +++ b/web/client/epics/__tests__/widgetsbuilder-test.js @@ -236,6 +236,7 @@ describe('widgetsbuilder epic', () => { type: "string", alias: "X alias" }]); + expect(action.owner).toEqual("widgets"); break; case LOAD_FILTER: break; diff --git a/web/client/epics/widgetsbuilder.js b/web/client/epics/widgetsbuilder.js index e917bc0e67..3ca15f8bbc 100644 --- a/web/client/epics/widgetsbuilder.js +++ b/web/client/epics/widgetsbuilder.js @@ -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)