Skip to content

Commit

Permalink
added tests for actions and reducers for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
MV88 committed Oct 24, 2016
1 parent 222f785 commit 1678c7e
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 3 deletions.
52 changes: 52 additions & 0 deletions web/client/actions/__tests__/tasks-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2015, 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.
*/

var expect = require('expect');
var {
taskSuccess,
taskStarted,
taskError,
TASK_STARTED,
TASK_SUCCESS,
TASK_ERROR
} = require('../tasks');

describe('Test correctness of the tasks actions', () => {
it('test taskSuccess action', () => {
let result = {value: "true"};
let name = "myName";
let actionPayload = null;
const retVal = taskSuccess(result, name, actionPayload);
expect(retVal).toExist();
expect(retVal.type).toBe(TASK_SUCCESS);
expect(retVal.result).toBe(result);
expect(retVal.name).toBe(name);
expect(retVal.actionPayload).toBe(null);
});

it('test taskError action', () => {
let error = {value: "true"};
let name = "myName";
let actionPayload = null;
const retVal = taskError(error, name, actionPayload);
expect(retVal).toExist();
expect(retVal.type).toBe(TASK_ERROR);
expect(retVal.error).toBe(error);
expect(retVal.name).toBe(name);
expect(retVal.actionPayload).toBe(null);
});


it('test taskStarted action', () => {
let name = "myName";
const retVal = taskStarted(name);
expect(retVal).toExist();
expect(retVal.type).toBe(TASK_STARTED);
expect(retVal.name).toBe(name);
});
});
7 changes: 4 additions & 3 deletions web/client/actions/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ function taskStarted(name) {
};
}

function taskError(error, name) {
function taskError(error, name, actionPayload) {
return {
type: TASK_ERROR,
error,
name
name,
actionPayload
};
}

Expand All @@ -45,4 +46,4 @@ function startTask(task, taskPayload, name, actionPayload) {
}


module.exports = {TASK_STARTED, TASK_SUCCESS, TASK_ERROR, startTask};
module.exports = {TASK_STARTED, TASK_SUCCESS, TASK_ERROR, startTask, taskSuccess, taskError, taskStarted};
62 changes: 62 additions & 0 deletions web/client/reducers/__tests__/tasks-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright 2016, 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.
*/
var expect = require('expect');

var {TASK_STARTED, TASK_SUCCESS, TASK_ERROR } = require('../../actions/tasks');
var tasks = require('../tasks');

describe('Test the tasks reducer', () => {

it('test tasks started', () => {
let name = 'started';
let testAction = {
type: TASK_STARTED,
name: name
};
let state = tasks({}, testAction);
expect(state).toExist();

expect(state[name].running).toBe(true);
});

it('test tasks success', () => {
let result = {value: "true"};
let actionPayload = null;

let name = 'started';
let testAction = {
type: TASK_SUCCESS,
name,
result,
actionPayload
};
let state = tasks({}, testAction);
expect(state[name].name).toBe(name);
expect(state[name].actionPayload).toBe(actionPayload);
expect(state[name].result).toBe(result);
});

it('test task error', () => {
let name = 'started';
let error = {value: "true"};
let actionPayload = null;

let testAction = {
type: TASK_ERROR,
name: name,
error,
actionPayload
};

let state = tasks({}, testAction);
expect(state[name].name).toBe(name);
expect(state[name].actionPayload).toBe(actionPayload);
expect(state[name].error).toBe(error);
});

});

0 comments on commit 1678c7e

Please sign in to comment.