Add spec for timeRange reducer

pull/10616/head
Andrew Watkins 2017-02-13 15:29:17 -06:00
parent b794ade83b
commit d1252cf90b
2 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,31 @@
import reducer from 'src/data_explorer/reducers/timeRange';
import {
setTimeRange,
} from 'src/data_explorer/actions/view';
const noopAction = () => {
return {type: 'NOOP'};
}
describe('DataExplorer.Reducers.TimeRange', () => {
it('it sets the default timeRange', () => {
const state = reducer(undefined, noopAction());
const expected = {
lower: 'now() - 15m',
upper: null,
};
expect(state).to.deep.equal(expected);
});
it('it can set the time range', () => {
const timeRange = {
lower: 'now() - 5m',
upper: null,
};
const expected = reducer(undefined, setTimeRange(timeRange));
expect(timeRange).to.deep.equal(expected);
});
});

View File

@ -1,6 +1,11 @@
import update from 'react-addons-update';
export default function timeRange(state = {}, action) {
const initialState = {
upper: null,
lower: 'now() - 15m',
};
export default function timeRange(state = initialState, action) {
switch (action.type) {
case 'SET_TIME_RANGE': {
const {upper, lower} = action.payload;