From 2f201fc5b5b2d889a8cfb3baa520a6626bb1e960 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Mon, 17 Oct 2016 19:27:51 +0200 Subject: [PATCH] Add unit tests for removeLayer action --- web/client/actions/__tests__/layers-test.js | 11 ++++++ web/client/reducers/__tests__/layers-test.js | 37 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/web/client/actions/__tests__/layers-test.js b/web/client/actions/__tests__/layers-test.js index f1c1c128c24..1e92923d4ef 100644 --- a/web/client/actions/__tests__/layers-test.js +++ b/web/client/actions/__tests__/layers-test.js @@ -17,6 +17,7 @@ var { LAYER_LOAD, LAYER_ERROR, ADD_LAYER, + REMOVE_LAYER, SHOW_SETTINGS, HIDE_SETTINGS, UPDATE_SETTINGS, @@ -29,6 +30,7 @@ var { layerLoad, layerError, addLayer, + removeLayer, showSettings, hideSettings, updateSettings @@ -127,6 +129,15 @@ describe('Test correctness of the layers actions', () => { expect(retval.layer).toBe(testVal); }); + it('remove layer', () => { + const testVal = 'layerid1'; + const retval = removeLayer(testVal); + + expect(retval).toExist(); + expect(retval.type).toBe(REMOVE_LAYER); + expect(retval.layerId).toBe(testVal); + }); + it('show settings', () => { const action = showSettings("node1", "layers", {opacity: 0.5}); expect(action).toExist(); diff --git a/web/client/reducers/__tests__/layers-test.js b/web/client/reducers/__tests__/layers-test.js index 32bf4ea89c7..e790125aa9d 100644 --- a/web/client/reducers/__tests__/layers-test.js +++ b/web/client/reducers/__tests__/layers-test.js @@ -309,6 +309,43 @@ describe('Test the layers reducer', () => { expect(state.groups[0].nodes[0]).toBe("test_id"); }); + it('remove layer', () => { + let addAction = { + type: "ADD_LAYER", + layer: {group: "group1", id: "test_id1"} + }; + let state = layers({}, addAction); + + addAction = { + type: "ADD_LAYER", + layer: {group: "group1", id: "test_id2"} + }; + state = layers(state, addAction); + addAction = { + type: "ADD_LAYER", + layer: {group: "group2", id: "test_id3"} + }; + state = layers(state, addAction); + + let removeAction = { + type: "REMOVE_LAYER", + layerId: "test_id1" + }; + + state = layers(state, removeAction); + expect(state).toExist(); + expect(state.flat).toExist(); + expect(state.flat).toExclude({group: "group1", id: "test_id1"}); + expect(state.flat).toInclude({group: "group1", id: "test_id2"}); + expect(state.flat).toInclude({group: "group2", id: "test_id3"}); + expect(state.groups).toExist(); + expect(state.groups[1].nodes).toExclude('test_id1'); + expect(state.groups[1].nodes).toInclude('test_id2'); + expect(state.groups[1].name).toBe('group1'); + expect(state.groups[0].nodes).toInclude('test_id3'); + expect(state.groups[0].name).toBe('group2'); + }); + it('show settings', () => { const action = { type: "SHOW_SETTINGS",