diff options
author | Aldo Cortesi <aldo@corte.si> | 2016-07-19 23:35:42 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-19 23:35:42 +1200 |
commit | 6000136b01fe16fc2747c739db878b51e0313006 (patch) | |
tree | ec794b33494e1ffd9b8f1c00d3ca275f8fd411d1 /web/src/js/__tests__/ducks/ui.js | |
parent | 09fbebf42a88115ac98ad9bc86947fd1b6771a5d (diff) | |
parent | 18dd84b9081fb5552d5b5b2560405496445e2110 (diff) | |
download | mitmproxy-6000136b01fe16fc2747c739db878b51e0313006.tar.gz mitmproxy-6000136b01fe16fc2747c739db878b51e0313006.tar.bz2 mitmproxy-6000136b01fe16fc2747c739db878b51e0313006.zip |
Merge branch 'master' into cleanup
Diffstat (limited to 'web/src/js/__tests__/ducks/ui.js')
-rw-r--r-- | web/src/js/__tests__/ducks/ui.js | 82 |
1 files changed, 15 insertions, 67 deletions
diff --git a/web/src/js/__tests__/ducks/ui.js b/web/src/js/__tests__/ducks/ui.js index ae2b75b9..d3242815 100644 --- a/web/src/js/__tests__/ducks/ui.js +++ b/web/src/js/__tests__/ducks/ui.js @@ -1,14 +1,8 @@ -jest.unmock('lodash') -jest.unmock('redux') -jest.unmock('redux-thunk') jest.unmock('../../ducks/ui') -jest.unmock('../../ducks/views/main') +jest.unmock('../../ducks/flows') -import _ from 'lodash' -import thunk from 'redux-thunk' -import { applyMiddleware, createStore, combineReducers } from 'redux' -import reducer, { setActiveMenu, selectTabRelative } from '../../ducks/ui' -import { SELECT } from '../../ducks/views/main' +import reducer, { setActiveMenu } from '../../ducks/ui' +import * as flowActions from '../../ducks/flows' describe('ui reducer', () => { it('should return the initial state', () => { @@ -20,69 +14,23 @@ describe('ui reducer', () => { }) it('should change the state to Start when deselecting a flow and we a currently at the flow tab', () => { - expect(reducer({ activeMenu: 'Flow' }, { - type: SELECT, - currentSelection: 1, - flowId : undefined, - }).activeMenu).toEqual('Start') + expect(reducer( + { activeMenu: 'Flow', isFlowSelected: true }, + flowActions.select(undefined)).activeMenu + ).toEqual('Start') }) it('should change the state to Flow when we selected a flow and no flow was selected before', () => { - expect(reducer({ activeMenu: 'Start' }, { - type: SELECT, - currentSelection: undefined, - flowId : 1, - }).activeMenu).toEqual('Flow') + expect(reducer( + { activeMenu: 'Start', isFlowSelected: false }, + flowActions.select(1)).activeMenu + ).toEqual('Flow') }) it('should not change the state to Flow when OPTIONS tab is selected and we selected a flow and a flow as selected before', () => { - expect(reducer({activeMenu: 'Options'}, { - type: SELECT, - currentSelection: 1, - flowId : '2', - }).activeMenu).toEqual('Options') - }) - - describe('select tab relative', () => { - - it('should select tab according to flow properties', () => { - const store = createTestStore(makeState([{ id: 1 }], 1)) - store.dispatch(selectTabRelative(1)) - expect(store.getState().ui.panel).toEqual('details') - }) - - it('should select last tab when first tab is selected', () => { - const store = createTestStore(makeState([{ id: 1, request: true, response: true, error: true }], 1)) - store.dispatch(selectTabRelative(-1)) - expect(store.getState().ui.panel).toEqual('details') - }) - + expect(reducer( + { activeMenu: 'Options', isFlowSelected: true }, + flowActions.select(1) + ).activeMenu).toEqual('Options') }) }) - -function createTestStore(state) { - return createStore( - combineReducers({ ui: reducer, flows: (state = {}) => state }), - state, - applyMiddleware(thunk) - ) -} - - -// TODO: We should not duplicate our reducer logic here. -function makeState(flows, selected) { - return { - flows: { - list: { - data: flows, - byId: _.fromPairs(flows.map(flow => [flow.id, flow])), - indexOf: _.fromPairs(flows.map((flow, index) => [flow.id, index])), - }, - views: { - main: { - selected: [selected], - }, - }, - }, - } -} |