From a29d7177dd82d47cf280df627adf1bdd45c1cab5 Mon Sep 17 00:00:00 2001 From: Sorrel Bri Date: Wed, 4 Dec 2019 21:11:17 -0800 Subject: [PATCH] add new epoch reducer action --- src/reducers/stateReducer.epochs.test.js | 23 +++++++++++++++++++++++ src/reducers/stateReducer.js | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/reducers/stateReducer.epochs.test.js diff --git a/src/reducers/stateReducer.epochs.test.js b/src/reducers/stateReducer.epochs.test.js new file mode 100644 index 0000000..5fc01da --- /dev/null +++ b/src/reducers/stateReducer.epochs.test.js @@ -0,0 +1,23 @@ +import {stateReducer} from './stateReducer'; + +describe('Epochs', () => { + const state = {}; + beforeEach(()=> { + state.epochs = [ + { + name: 'epoch 1', + changes: [] + } + ] + }) + + it('epochs returned unaltered', () => { + const action = {type: ''}; + expect(stateReducer(state, action)).toBe(state); + }); + + it('epochs addition returns new epochs list', () => { + const action = {type: 'ADD_EPOCH', value: { name: 'epoch 2', changes: []}}; + expect(stateReducer(state, action)).toEqual({...state, epochs: [...state.epochs, action.value]}) + }) +}); \ No newline at end of file diff --git a/src/reducers/stateReducer.js b/src/reducers/stateReducer.js index 1987b4d..da57b23 100644 --- a/src/reducers/stateReducer.js +++ b/src/reducers/stateReducer.js @@ -52,6 +52,11 @@ const stateReducer = (state, action) => { return {...state, lexicon: newLexicon} } + case 'ADD_EPOCH': { + let newEpoch = action.value; + return {...state, epochs: [...state.epochs, newEpoch]} + } + case 'ADD_FEATURE': { let positivePhones = action.value.positivePhones || []; let negativePhones = action.value.negativePhones || []; @@ -69,7 +74,6 @@ const stateReducer = (state, action) => { ); positivePhones = positivePhones.map( positivePhone => findPhone(newPhoneObject, positivePhone) ) - // console.log(positivePhones) } if (negativePhones) { @@ -80,7 +84,6 @@ const stateReducer = (state, action) => { ); negativePhones = negativePhones.map( negativePhone => findPhone(newPhoneObject, negativePhone) ) - // console.log(negativePhones) } let newFeature = {[action.value.feature]: {positive: positivePhones, negative: negativePhones}};