diff options
-rw-r--r-- | web/src/js/__tests__/ducks/tutils.js | 6 | ||||
-rw-r--r-- | web/src/js/__tests__/ducks/ui/header.js (renamed from web/src/js/__tests__/ducks/ui.js) | 10 | ||||
-rw-r--r-- | web/src/js/__tests__/ducks/utils/view.js | 6 | ||||
-rwxr-xr-x | web/src/js/ducks/utils/view.js | 28 |
4 files changed, 37 insertions, 13 deletions
diff --git a/web/src/js/__tests__/ducks/tutils.js b/web/src/js/__tests__/ducks/tutils.js index 90a21b78..6a543434 100644 --- a/web/src/js/__tests__/ducks/tutils.js +++ b/web/src/js/__tests__/ducks/tutils.js @@ -10,3 +10,9 @@ export function createStore(parts) { applyMiddleware(...[thunk]) ) } + +describe('tutils', () => { + it('do nothing', () => { + return + }) +})
\ No newline at end of file diff --git a/web/src/js/__tests__/ducks/ui.js b/web/src/js/__tests__/ducks/ui/header.js index d3242815..8968e636 100644 --- a/web/src/js/__tests__/ducks/ui.js +++ b/web/src/js/__tests__/ducks/ui/header.js @@ -1,10 +1,10 @@ -jest.unmock('../../ducks/ui') -jest.unmock('../../ducks/flows') +jest.unmock('../../../ducks/ui/header') +jest.unmock('../../../ducks/flows') -import reducer, { setActiveMenu } from '../../ducks/ui' -import * as flowActions from '../../ducks/flows' +import reducer, { setActiveMenu } from '../../../ducks/ui/header' +import * as flowActions from '../../../ducks/flows' -describe('ui reducer', () => { +describe('header reducer', () => { it('should return the initial state', () => { expect(reducer(undefined, {}).activeMenu).toEqual('Start') }) diff --git a/web/src/js/__tests__/ducks/utils/view.js b/web/src/js/__tests__/ducks/utils/view.js index f0b147da..af3da173 100644 --- a/web/src/js/__tests__/ducks/utils/view.js +++ b/web/src/js/__tests__/ducks/utils/view.js @@ -66,11 +66,13 @@ describe('view reduce', () => { it('should update item', () => { const state = createState([ { id: 1, val: 1 }, - { id: 2, val: 2 } + { id: 2, val: 2 }, + { id: 3, val: 3 } ]) const result = createState([ { id: 1, val: 1 }, - { id: 2, val: 3 } + { id: 2, val: 3 }, + { id: 3, val: 3 } ]) expect(reduce(state, view.update({ id: 2, val: 3 }))).toEqual(result) }) diff --git a/web/src/js/ducks/utils/view.js b/web/src/js/ducks/utils/view.js index 2f1e03fa..fdddc391 100755 --- a/web/src/js/ducks/utils/view.js +++ b/web/src/js/ducks/utils/view.js @@ -54,14 +54,30 @@ export default function reduce(state = defaultState, action) { } case UPDATE: - if (state.indexOf[action.item.id] == null) { - return + let hasOldItem = state.indexOf[action.item.id] !== null && state.indexOf[action.item.id] !== undefined + let hasNewItem = action.filter(action.item) + if (!hasNewItem && !hasOldItem) { + return state } - return { - ...state, - ...sortedUpdate(state, action.item, action.sort), + if (hasNewItem && !hasOldItem) { + return { + ...state, + ...sortedInsert(state, action.item, action.sort) + } } - + if (!hasNewItem && hasOldItem) { + return { + ...state, + ...sortedRemove(state, action.item.id) + } + } + if (hasNewItem && hasOldItem) { + return { + ...state, + ...sortedUpdate(state, action.item, action.sort), + } + } + break; case RECEIVE: { const data = action.list.filter(action.filter).sort(action.sort) |