Skip to content

Commit

Permalink
development/#81 add unit tests for filtersReducer (#105)
Browse files Browse the repository at this point in the history
resolved #81
  • Loading branch information
Mirosław Bogacz authored Nov 27, 2017
1 parent b4b5187 commit 2ed6b12
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/app/worklogs/reducers/filters.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as filtersActions from '../actions/filters.actions';
import { filtersReducer } from './filters.reducer';

describe('filtersReducer', () => {

describe('when reducer doesnt get any params', () => {

it('shoud return default state', () => {

const emptyAction = { type: '' } as any;
expect(filtersReducer(undefined, emptyAction)).toEqual({ model: {} })

});

});

describe('when reducer get UPDATE action with out state', () => {

it('should return value with new element from payload', () => {

const state = { model: {} };
const actionPayload = { keywords: 'test keywords' };
const action = new filtersActions.Update(actionPayload);
const result = filtersReducer(state, action);
const expected = { model: actionPayload };

expect(result).toEqual(expected);

});

});

describe('when reducer get UPDATE action', () => {

it('should return value with new element from payload', () => {

const state = { model: {} };
const actionPayload = { keywords: 'test keywords' };
const action = new filtersActions.Update(actionPayload);
const result = filtersReducer(state, action);
const expected = { model: actionPayload };

expect(result).toEqual(expected);

});

});

describe('when reducer get UPDATE action', () => {

it('should return value with updated element from payload', () => {

const state = { model: { keywords: 'old value' } };
const actionPayload = { keywords: 'new value' };
const action = new filtersActions.Update(actionPayload);
const result = filtersReducer(state, action);
const expected = { model: actionPayload };

expect(result).toEqual(expected);

});

});

});


0 comments on commit 2ed6b12

Please sign in to comment.