Skip to content

Commit

Permalink
Add unit tests for removeLayer action
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 17, 2016
1 parent 54933ef commit 2f201fc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions web/client/actions/__tests__/layers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var {
LAYER_LOAD,
LAYER_ERROR,
ADD_LAYER,
REMOVE_LAYER,
SHOW_SETTINGS,
HIDE_SETTINGS,
UPDATE_SETTINGS,
Expand All @@ -29,6 +30,7 @@ var {
layerLoad,
layerError,
addLayer,
removeLayer,
showSettings,
hideSettings,
updateSettings
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 37 additions & 0 deletions web/client/reducers/__tests__/layers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2f201fc

Please sign in to comment.