[web] bug fix and add test

This commit is contained in:
Jason 2016-07-26 02:09:54 +08:00
parent 3a3305b9ac
commit 7b51f12813
4 changed files with 37 additions and 13 deletions

View File

@ -10,3 +10,9 @@ export function createStore(parts) {
applyMiddleware(...[thunk])
)
}
describe('tutils', () => {
it('do nothing', () => {
return
})
})

View File

@ -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')
})

View File

@ -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)
})

View File

@ -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)