From 37c2b47c26dea9b143b2720761cdce21dafd3884 Mon Sep 17 00:00:00 2001 From: Jason Date: Mon, 27 Jun 2016 18:36:21 +0800 Subject: [web] add tests for utils --- web/src/js/ducks/ui.js | 4 ++-- web/src/js/ducks/utils/list.js | 18 +++++++++--------- web/src/js/ducks/utils/view.js | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'web/src/js/ducks') diff --git a/web/src/js/ducks/ui.js b/web/src/js/ducks/ui.js index c17e042b..f8234fdb 100644 --- a/web/src/js/ducks/ui.js +++ b/web/src/js/ducks/ui.js @@ -1,4 +1,4 @@ -import {SELECT_FLOW} from "./flows" +import {SELECT} from "./views/main" export const SET_ACTIVE_MENU = 'SET_ACTIVE_MENU'; @@ -12,7 +12,7 @@ export default function reducer(state = defaultState, action) { ...state, activeMenu: action.activeMenu } - case SELECT_FLOW: + case SELECT: let isNewSelect = (action.flowId && !action.currentSelection) let isDeselect = (!action.flowId && action.currentSelection) if(isNewSelect) { diff --git a/web/src/js/ducks/utils/list.js b/web/src/js/ducks/utils/list.js index 71042d91..4f631590 100644 --- a/web/src/js/ducks/utils/list.js +++ b/web/src/js/ducks/utils/list.js @@ -23,33 +23,33 @@ export default function reduce(state = defaultState, action) { } case UPDATE: { - const data = [...state.data] const index = state.indexOf[action.id] - // FIXME: We should just swallow this if (index == null) { - throw new Error('Item not found') + return state } + const data = [...state.data] + data[index] = action.item return { ...state, data, - byId: { ...state.byId, [action.item.id]: action.item }, + byId: { ...state.byId, [action.id]: action.item } } } case REMOVE: { - const data = [...state.data] - const indexOf = { ...state.indexOf } - const index = indexOf[action.id] + const index = state.indexOf[action.id] - // FIXME: We should just swallow this if (index == null) { - throw new Error('Item not found') + return state } + const data = [...state.data] + const indexOf = { ...state.indexOf, [action.id]: null } + data.splice(index, 1) for (let i = data.length - 1; i >= index; i--) { indexOf[data[i].id] = i diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js index 2296e454..0349a398 100755 --- a/web/src/js/ducks/utils/view.js +++ b/web/src/js/ducks/utils/view.js @@ -29,7 +29,7 @@ export default function reduce(state = defaultState, action) { return { ...state, data, - indexOf: _.fromPairs(data.map((item, index) => [item.id, index])) + indexOf: _.fromPairs(data.map((item, index) => [item.id, index])), } } @@ -43,7 +43,7 @@ export default function reduce(state = defaultState, action) { } case REMOVE: - if (state.indexOf[action.item.id] == null) { + if (state.indexOf[action.id] == null) { return state } return { @@ -52,7 +52,7 @@ export default function reduce(state = defaultState, action) { } case UPDATE: { - if (state.indexOf[action.item.id] == null) { + if (state.indexOf[action.id] == null) { return } const nextState = { -- cgit v1.2.3