diff --git a/web/client/actions/__tests__/maps-test.js b/web/client/actions/__tests__/maps-test.js index 9be9e41880..284ee44cf2 100644 --- a/web/client/actions/__tests__/maps-test.js +++ b/web/client/actions/__tests__/maps-test.js @@ -15,7 +15,12 @@ var { SAVE_MAP, saveMap, DISPLAY_METADATA_EDIT, onDisplayMetadataEdit, RESET_UPDATING, resetUpdating, - THUMBNAIL_ERROR, thumbnailError + THUMBNAIL_ERROR, thumbnailError, + RESET_CURRENT_MAP, resetCurrentMap, + MAPS_SEARCH_TEXT_CHANGED, mapsSearchTextChanged, + MAPS_LIST_LOAD_ERROR, loadError, + MAP_ERROR, mapError, + MAP_METADATA_UPDATED, mapMetadataUpdated } = require('../maps'); describe('Test correctness of the maps actions', () => { @@ -89,4 +94,31 @@ describe('Test correctness of the maps actions', () => { expect(retval.resourceId).toBe(resourceId); expect(retval.map).toBe(map); }); + it('resetCurrentMap', () => { + const a = resetCurrentMap(); + expect(a.type).toBe(RESET_CURRENT_MAP); + }); + it('mapsSearchTextChanged', () => { + const a = mapsSearchTextChanged("TEXT"); + expect(a.type).toBe(MAPS_SEARCH_TEXT_CHANGED); + expect(a.text).toBe("TEXT"); + }); + it('loadError', () => { + const a = loadError(); + expect(a.type).toBe(MAPS_LIST_LOAD_ERROR); + }); + it('mapError', () => { + const a = mapError("error"); + expect(a.type).toBe(MAP_ERROR); + expect(a.error).toBe("error"); + }); + it('mapMetadataUpdated', () => { + const a = mapMetadataUpdated("resourceId", "newName", "newDescription", "result", "error"); + expect(a.type).toBe(MAP_METADATA_UPDATED); + expect(a.resourceId).toBe("resourceId"); + expect(a.newName).toBe("newName"); + expect(a.newDescription).toBe("newDescription"); + expect(a.result).toBe("result"); + expect(a.error).toBe("error"); + }); }); diff --git a/web/client/actions/__tests__/tasks-test.js b/web/client/actions/__tests__/tasks-test.js index bab4882614..7615cefd40 100644 --- a/web/client/actions/__tests__/tasks-test.js +++ b/web/client/actions/__tests__/tasks-test.js @@ -11,6 +11,7 @@ var { taskSuccess, taskStarted, taskError, + startTask, TASK_STARTED, TASK_SUCCESS, TASK_ERROR @@ -49,4 +50,22 @@ describe('Test correctness of the tasks actions', () => { expect(retVal.type).toBe(TASK_STARTED); expect(retVal.name).toBe(name); }); + + it('startTask', done => { + let started = false; + let executed = false; + let dispatchable = startTask((payload, callback) => {executed = true; expect(payload).toBe("payload"); callback(); }, "payload", "task", "actionPayload"); + dispatchable((action) => { + if (action.type === TASK_STARTED) { + expect(action.name).toBe("task"); + started = true; + } + if (action.type === TASK_SUCCESS) { + expect(action.actionPayload).toBe("actionPayload"); + expect(started).toBe(true); + expect(executed).toBe(true); + done(); + } + }); + }); }); diff --git a/web/client/utils/PluginsUtils.js b/web/client/utils/PluginsUtils.js index 09e87849df..3a8dddc0e7 100644 --- a/web/client/utils/PluginsUtils.js +++ b/web/client/utils/PluginsUtils.js @@ -122,6 +122,12 @@ const getReducers = (plugins) => Object.keys(plugins).map((name) => plugins[name const getEpics = (plugins) => Object.keys(plugins).map((name) => plugins[name].epics) .reduce((previous, current) => assign({}, previous, current), {}); const PluginsUtils = { + /** + * Produces the reducers from the plugins, combined with other plugins + * @param {array} plugins the plugins + * @param {array} reducers other plugins + * @returns {function} a reducer made from the plugins' reducers and the reducers passed as 2nd parameter + */ combineReducers: (plugins, reducers) => { const pluginsReducers = getReducers(plugins); return combineReducers(assign({}, reducers, pluginsReducers)); diff --git a/web/client/utils/__tests__/PluginUtils-test.js b/web/client/utils/__tests__/PluginUtils-test.js new file mode 100644 index 0000000000..6a61940c3a --- /dev/null +++ b/web/client/utils/__tests__/PluginUtils-test.js @@ -0,0 +1,76 @@ +/** + * 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 expect = require('expect'); +const PluginsUtils = require('../PluginsUtils'); +const assign = require('object-assign'); + +describe('PluginsUtils', () => { + beforeEach( () => { + + }); + afterEach((done) => { + document.body.innerHTML = ''; + + setTimeout(done); + }); + it('combineReducers', () => { + const P1 = { + reducers: { + reducer1: () => {} + } + }; + + const P2 = { + reducers: { + reducer1: (state = {}) => assign({}, state, { A: "A"}), + reducer2: (state = {}) => state + } + }; + const reducers = { + reducer3: (state = {}) => state + }; + const spyNo = expect.spyOn(P1.reducers, "reducer1"); + const finalReducer = PluginsUtils.combineReducers([P1, P2], reducers); + const state = finalReducer(); + expect(state.reducer1).toExist(); + expect(state.reducer1.A).toBe("A"); + + // test overriding + expect(spyNo.calls.length).toBe(0); + }); + it('getPluginDescriptor', () => { + const P1 = assign( () => {}, { + reducers: { + reducer1: () => {} + } + }); + const item = { + test: "TEST" + }; + const P2 = assign( () => {}, { + P1: item, + reducers: { + reducer1: () => ({ A: "A"}), + reducer2: () => {} + } + }); + const cfg = { + test: "TEST" + }; + let desc1 = PluginsUtils.getPluginDescriptor({}, {P1Plugin: P1, P2Plugin: P2}, [{name: "P1", cfg}, "P2"], "P1" ); + expect(desc1).toExist(); + expect(desc1.id).toBe("P1"); + expect(desc1.name).toBe("P1"); + expect(desc1.cfg).toExist(cfg); + expect(desc1.items.length).toBe(1); + expect(desc1.items[0].test).toBe(item.test); + expect(desc1.items[0].cfg).toExist(); + + }); + +});