add reducer action SET_OPTIONS
This commit is contained in:
parent
77ebc5e1b9
commit
4ffeab701a
3 changed files with 62 additions and 0 deletions
|
@ -5,6 +5,8 @@ import { addEpoch, setEpoch, removeEpoch } from './stateReducer.epochs';
|
||||||
import type { epochAction } from './stateReducer.epochs';
|
import type { epochAction } from './stateReducer.epochs';
|
||||||
import { addFeature } from './stateReducer.features';
|
import { addFeature } from './stateReducer.features';
|
||||||
import type { featureAction } from './stateReducer.features';
|
import type { featureAction } from './stateReducer.features';
|
||||||
|
import type { optionsAction } from './stateReducer.options';
|
||||||
|
import { setOptions } from './stateReducer.options';
|
||||||
import { run } from './stateReducer.results';
|
import { run } from './stateReducer.results';
|
||||||
import type { resultsAction } from './stateReducer.results'
|
import type { resultsAction } from './stateReducer.results'
|
||||||
import { initState } from './stateReducer.init';
|
import { initState } from './stateReducer.init';
|
||||||
|
@ -53,6 +55,8 @@ export const stateReducer = (state: stateType, action: actionType): stateType =>
|
||||||
|
|
||||||
case 'ADD_FEATURE': return addFeature(state, action);
|
case 'ADD_FEATURE': return addFeature(state, action);
|
||||||
|
|
||||||
|
case 'SET_OPTIONS': return setOptions(state, action);
|
||||||
|
|
||||||
case 'RUN': return run(state, action);
|
case 'RUN': return run(state, action);
|
||||||
|
|
||||||
default: return state;
|
default: return state;
|
||||||
|
|
20
src/reducers/stateReducer.options.js
Normal file
20
src/reducers/stateReducer.options.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
// @flow
|
||||||
|
import type { stateType } from './stateReducer';
|
||||||
|
|
||||||
|
export type optionAction = {
|
||||||
|
type: 'SET_OPTIONS',
|
||||||
|
value: {
|
||||||
|
option: string,
|
||||||
|
setValue: string
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setOptions = (state: stateType, action: optionAction): stateType => {
|
||||||
|
const option = action.value.option;
|
||||||
|
let value = action.value.setValue;
|
||||||
|
if (value === 'true') value = true;
|
||||||
|
if (value === 'false') value = false;
|
||||||
|
const mutatedState = {...state};
|
||||||
|
mutatedState.options[option] = value;
|
||||||
|
return mutatedState;
|
||||||
|
}
|
38
src/reducers/stateReducer.options.test.js
Normal file
38
src/reducers/stateReducer.options.test.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { stateReducer } from './stateReducer';
|
||||||
|
import { initState } from './stateReducer.init';
|
||||||
|
|
||||||
|
describe('Options', () => {
|
||||||
|
let state = {}
|
||||||
|
beforeEach(() => {
|
||||||
|
state = initState();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Options returned unaltered', () => {
|
||||||
|
const action = {type: ''};
|
||||||
|
expect(stateReducer(state, action)).toBe(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
// output: 'default', save: false
|
||||||
|
it('Options change to output returns with changed value', () => {
|
||||||
|
const action = {type: 'SET_OPTIONS', value: {option: 'output', setValue: 'proto'}};
|
||||||
|
expect(stateReducer(state, action)).toEqual(
|
||||||
|
{...state,
|
||||||
|
options: {...state.options,
|
||||||
|
output: 'proto'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Options change to save returns with changed value', () => {
|
||||||
|
const action = {type: 'SET_OPTIONS', value: {option: 'save', setValue: 'true'}};
|
||||||
|
expect(stateReducer(state, action)).toEqual(
|
||||||
|
{...state,
|
||||||
|
options: {...state.options,
|
||||||
|
save: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in a new issue