From ea3234fa7230a9e97aba700da92ffaa8eee24134 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Fri, 13 Jan 2017 21:39:26 -0800 Subject: [PATCH] Start testing reducers --- js/__tests__/reducers-test.js | 25 +++++++++++++++++++++++++ js/reducers.js | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 js/__tests__/reducers-test.js diff --git a/js/__tests__/reducers-test.js b/js/__tests__/reducers-test.js new file mode 100644 index 00000000..d0965f80 --- /dev/null +++ b/js/__tests__/reducers-test.js @@ -0,0 +1,25 @@ +import {userInput} from '../reducers'; +import { + SET_FOCUS, + SET_SCRUB_POSITION, + UNSET_FOCUS +} from '../actionTypes'; + +describe('userInput reducer', () => { + const state = userInput(); + it('has sensible defaults', () => { + expect(state).toEqual({focus: null, scrubPosition: 0}); + }); + it('can set focus', () => { + const newState = userInput(state, {type: SET_FOCUS, input: 'foo'}); + expect(newState).toEqual({focus: 'foo', scrubPosition: 0}); + }); + it('can unset focus', () => { + const newState = userInput({...state, focus: 'foo'}, {type: UNSET_FOCUS}); + expect(newState).toEqual({focus: null, scrubPosition: 0}); + }); + it('can set scrub position', () => { + const newState = userInput(state, {type: SET_SCRUB_POSITION, position: 5}); + expect(newState).toEqual({focus: null, scrubPosition: 5}); + }); +}); diff --git a/js/reducers.js b/js/reducers.js index d0bb7269..ee5f7c2c 100644 --- a/js/reducers.js +++ b/js/reducers.js @@ -30,7 +30,7 @@ import { UPDATE_TIME_ELAPSED } from './actionTypes'; -const userInput = (state, action) => { +export const userInput = (state, action) => { if (!state) { return { focus: null,