mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +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])
|
applyMiddleware(...[thunk])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
describe('tutils', () => {
|
||||||
|
it('do nothing', () => {
|
||||||
|
return
|
||||||
|
})
|
||||||
|
})
|
@ -1,10 +1,10 @@
|
|||||||
jest.unmock('../../ducks/ui')
|
jest.unmock('../../../ducks/ui/header')
|
||||||
jest.unmock('../../ducks/flows')
|
jest.unmock('../../../ducks/flows')
|
||||||
|
|
||||||
import reducer, { setActiveMenu } from '../../ducks/ui'
|
import reducer, { setActiveMenu } from '../../../ducks/ui/header'
|
||||||
import * as flowActions from '../../ducks/flows'
|
import * as flowActions from '../../../ducks/flows'
|
||||||
|
|
||||||
describe('ui reducer', () => {
|
describe('header reducer', () => {
|
||||||
it('should return the initial state', () => {
|
it('should return the initial state', () => {
|
||||||
expect(reducer(undefined, {}).activeMenu).toEqual('Start')
|
expect(reducer(undefined, {}).activeMenu).toEqual('Start')
|
||||||
})
|
})
|
@ -66,11 +66,13 @@ describe('view reduce', () => {
|
|||||||
it('should update item', () => {
|
it('should update item', () => {
|
||||||
const state = createState([
|
const state = createState([
|
||||||
{ id: 1, val: 1 },
|
{ id: 1, val: 1 },
|
||||||
{ id: 2, val: 2 }
|
{ id: 2, val: 2 },
|
||||||
|
{ id: 3, val: 3 }
|
||||||
])
|
])
|
||||||
const result = createState([
|
const result = createState([
|
||||||
{ id: 1, val: 1 },
|
{ 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)
|
expect(reduce(state, view.update({ id: 2, val: 3 }))).toEqual(result)
|
||||||
})
|
})
|
||||||
|
@ -54,14 +54,30 @@ export default function reduce(state = defaultState, action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case UPDATE:
|
case UPDATE:
|
||||||
if (state.indexOf[action.item.id] == null) {
|
let hasOldItem = state.indexOf[action.item.id] !== null && state.indexOf[action.item.id] !== undefined
|
||||||
return
|
let hasNewItem = action.filter(action.item)
|
||||||
|
if (!hasNewItem && !hasOldItem) {
|
||||||
|
return state
|
||||||
}
|
}
|
||||||
return {
|
if (hasNewItem && !hasOldItem) {
|
||||||
...state,
|
return {
|
||||||
...sortedUpdate(state, action.item, action.sort),
|
...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:
|
case RECEIVE:
|
||||||
{
|
{
|
||||||
const data = action.list.filter(action.filter).sort(action.sort)
|
const data = action.list.filter(action.filter).sort(action.sort)
|
||||||
|
Loading…
Reference in New Issue
Block a user