aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/ducks/views/main.js
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-07-18 20:59:17 -0700
committerMaximilian Hils <git@maximilianhils.com>2016-07-18 20:59:17 -0700
commit859bb8c99fbe285f839373c66028910eb5595604 (patch)
treea319a55af7289aa006e32909fca92c24a436c19e /web/src/js/__tests__/ducks/views/main.js
parent00b0d47db6961849c8a00af3d7805f5d9a9e5e2d (diff)
parent92026d26ea6d8d9134b2725cf83753ba9e5c3579 (diff)
downloadmitmproxy-859bb8c99fbe285f839373c66028910eb5595604.tar.gz
mitmproxy-859bb8c99fbe285f839373c66028910eb5595604.tar.bz2
mitmproxy-859bb8c99fbe285f839373c66028910eb5595604.zip
Merge remote-tracking branch 'jason/ui'
Diffstat (limited to 'web/src/js/__tests__/ducks/views/main.js')
-rw-r--r--web/src/js/__tests__/ducks/views/main.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/web/src/js/__tests__/ducks/views/main.js b/web/src/js/__tests__/ducks/views/main.js
new file mode 100644
index 00000000..0edbf68f
--- /dev/null
+++ b/web/src/js/__tests__/ducks/views/main.js
@@ -0,0 +1,82 @@
+jest.unmock('../../../ducks/views/main');
+jest.unmock('../../../ducks/utils/view');
+jest.unmock('redux-thunk')
+jest.unmock('redux')
+
+import reduce, { selectRelative } from '../../../ducks/views/main';
+import thunk from 'redux-thunk'
+import { applyMiddleware, createStore, combineReducers } from 'redux'
+
+describe('main reduce', () => {
+
+ describe('select previous', () => {
+
+ it('should not changed when first flow is selected', () => {
+ const flows = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
+ const store = createTestStore(makeState(flows, 1))
+ store.dispatch(selectRelative(-1))
+ expect(store.getState().flows.views.main.selected).toEqual([1])
+ })
+
+ it('should select last flow if no flow is selected', () => {
+ const flows = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
+ const store = createTestStore(makeState(flows))
+ store.dispatch(selectRelative(-1))
+ expect(store.getState().flows.views.main.selected).toEqual([4])
+ })
+
+ })
+
+ describe('select next', () => {
+
+ it('should not change when last flow is selected', () => {
+ const flows = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
+ const store = createTestStore(makeState(flows, 4))
+ store.dispatch(selectRelative(1))
+ expect(store.getState().flows.views.main.selected).toEqual([4])
+ })
+
+ it('should select first flow if no flow is selected', () => {
+ const flows = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }]
+ const store = createTestStore(makeState(flows, 1))
+ store.dispatch(selectRelative(1))
+ expect(store.getState().flows.views.main.selected).toEqual([2])
+ })
+
+ })
+})
+
+function createTestStore(defaultState) {
+ return createStore(
+ (state = defaultState, action) => ({
+ flows: {
+ ...state.flows,
+ views: {
+ main: reduce(state.flows.views.main, action)
+ }
+ }
+ }),
+ defaultState,
+ applyMiddleware(thunk)
+ )
+}
+
+function makeState(flows, selected) {
+ const list = {
+ data: flows,
+ byId: _.fromPairs(flows.map(flow => [flow.id, flow])),
+ indexOf: _.fromPairs(flows.map((flow, index) => [flow.id, index])),
+ }
+
+ return {
+ flows: {
+ list,
+ views: {
+ main: {
+ selected: [selected],
+ view: list,
+ }
+ }
+ }
+ }
+}