Introduce data explorer ui reducer

pull/10616/head
Andrew Watkins 2017-02-13 17:16:54 -06:00
parent e4cc9fc45d
commit 569c8a8218
2 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,40 @@
import reducer from 'src/data_explorer/reducers/ui';
import {
addQuery,
deleteQuery,
} from 'src/data_explorer/actions/view';
const noopAction = () => {
return {type: 'NOOP'};
}
let state = undefined;
describe('DataExplorer.Reducers.UI', () => {
it('it sets the default state for UI', () => {
const actual = reducer(state, noopAction());
const expected = {
queryIDs: [],
};
expect(actual).to.deep.equal(expected);
});
it('it can add a query', () => {
const actual = reducer(state, addQuery());
expect(actual.queryIDs.length).to.equal(1);
});
it('it can delete a query', () => {
const queryID = '123';
state = {queryIDs: ['456', queryID]};
const actual = reducer(state, deleteQuery(queryID));
const expected = {
queryIDs: ['456'],
};
expect(actual).to.deep.equal(expected);
});
});

View File

@ -0,0 +1,27 @@
const initialState = {
queryIDs: [],
};
export default function ui(state = initialState, action) {
switch (action.type) {
case 'ADD_QUERY': {
const {queryID} = action.payload;
const newState = {
queryIDs: state.queryIDs.concat(queryID),
};
return {...state, ...newState};
}
case 'DELETE_QUERY': {
const {queryID} = action.payload;
const newState = {
queryIDs: state.queryIDs.filter(id => id !== queryID),
};
return {...state, ...newState};
}
}
return state;
}