add new epoch reducer action

This commit is contained in:
Sorrel Bri 2019-12-04 21:11:17 -08:00
parent faec991cd0
commit a29d7177dd
2 changed files with 28 additions and 2 deletions

View file

@ -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]})
})
});

View file

@ -52,6 +52,11 @@ const stateReducer = (state, action) => {
return {...state, lexicon: newLexicon} return {...state, lexicon: newLexicon}
} }
case 'ADD_EPOCH': {
let newEpoch = action.value;
return {...state, epochs: [...state.epochs, newEpoch]}
}
case 'ADD_FEATURE': { case 'ADD_FEATURE': {
let positivePhones = action.value.positivePhones || []; let positivePhones = action.value.positivePhones || [];
let negativePhones = action.value.negativePhones || []; let negativePhones = action.value.negativePhones || [];
@ -69,7 +74,6 @@ const stateReducer = (state, action) => {
); );
positivePhones = positivePhones.map( positivePhone => findPhone(newPhoneObject, positivePhone) ) positivePhones = positivePhones.map( positivePhone => findPhone(newPhoneObject, positivePhone) )
// console.log(positivePhones)
} }
if (negativePhones) { if (negativePhones) {
@ -80,7 +84,6 @@ const stateReducer = (state, action) => {
); );
negativePhones = negativePhones.map( negativePhone => findPhone(newPhoneObject, negativePhone) ) negativePhones = negativePhones.map( negativePhone => findPhone(newPhoneObject, negativePhone) )
// console.log(negativePhones)
} }
let newFeature = {[action.value.feature]: {positive: positivePhones, negative: negativePhones}}; let newFeature = {[action.value.feature]: {positive: positivePhones, negative: negativePhones}};