mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +00:00
[web] bug fix and add test
This commit is contained in:
parent
3a3305b9ac
commit
7b51f12813
@ -10,3 +10,9 @@ export function createStore(parts) {
|
||||
applyMiddleware(...[thunk])
|
||||
)
|
||||
}
|
||||
|
||||
describe('tutils', () => {
|
||||
it('do nothing', () => {
|
||||
return
|
||||
})
|
||||
})
|
@ -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')
|
||||
})
|
@ -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)
|
||||
})
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user