diff options
| author | Matthew Shao <me@matshao.com> | 2017-07-20 15:39:43 +0800 |
|---|---|---|
| committer | Matthew Shao <me@matshao.com> | 2017-07-20 15:39:43 +0800 |
| commit | f465f08c9ac302007b3aec6709a8e82d63c7ad65 (patch) | |
| tree | f50a0700ba88ac91f1e82fafeb96c65a0e7f4fb4 /web/src/js/__tests__/ducks/ui | |
| parent | cbf5db9a4ff77440276ca6bb4d395cc5bdee30ad (diff) | |
| download | mitmproxy-f465f08c9ac302007b3aec6709a8e82d63c7ad65.tar.gz mitmproxy-f465f08c9ac302007b3aec6709a8e82d63c7ad65.tar.bz2 mitmproxy-f465f08c9ac302007b3aec6709a8e82d63c7ad65.zip | |
[web] Minor fix and update tests.
Diffstat (limited to 'web/src/js/__tests__/ducks/ui')
| -rw-r--r-- | web/src/js/__tests__/ducks/ui/keyboardSpec.js | 7 | ||||
| -rw-r--r-- | web/src/js/__tests__/ducks/ui/optionEditorSpec.js | 32 | ||||
| -rw-r--r-- | web/src/js/__tests__/ducks/ui/optionSpec.js | 39 |
3 files changed, 78 insertions, 0 deletions
diff --git a/web/src/js/__tests__/ducks/ui/keyboardSpec.js b/web/src/js/__tests__/ducks/ui/keyboardSpec.js index 500733cb..cf17943f 100644 --- a/web/src/js/__tests__/ducks/ui/keyboardSpec.js +++ b/web/src/js/__tests__/ducks/ui/keyboardSpec.js @@ -6,6 +6,7 @@ import reduceFlows from '../../../ducks/flows' import reduceUI from '../../../ducks/ui/index' import * as flowsActions from '../../../ducks/flows' import * as UIActions from '../../../ducks/ui/flow' +import * as modalActions from '../../../ducks/ui/modal' import configureStore from 'redux-mock-store' import thunk from 'redux-thunk' import { fetchApi } from '../../../utils' @@ -154,4 +155,10 @@ describe('onKeyDown', () => { expect(fetchApi).not.toBeCalled() }) + it('should close modal', () => { + store.getState().ui.modal.activeModal = true + store.dispatch(createKeyEvent(Key.ESC)) + expect(store.getActions()).toEqual([ {type: modalActions.HIDE_MODAL} ]) + }) + }) diff --git a/web/src/js/__tests__/ducks/ui/optionEditorSpec.js b/web/src/js/__tests__/ducks/ui/optionEditorSpec.js new file mode 100644 index 00000000..df9161a4 --- /dev/null +++ b/web/src/js/__tests__/ducks/ui/optionEditorSpec.js @@ -0,0 +1,32 @@ +import reduceOptionsEditor, * as optionsEditorActions from '../../../ducks/ui/optionsEditor' +import { HIDE_MODAL } from '../../../ducks/ui/modal' + +describe('optionsEditor reducer', () => { + + it('should return initial state', () => { + expect(reduceOptionsEditor(undefined, {})).toEqual({}) + }) + + let state = undefined + it('should handle option update start', () => { + state = reduceOptionsEditor(undefined, optionsEditorActions.startUpdate('foo', 'bar')) + expect(state).toEqual({ foo: {error: false, isUpdating: true, value: 'bar'}}) + }) + + it('should handle option update success', () => { + expect(reduceOptionsEditor(state, optionsEditorActions.updateSuccess('foo'))).toEqual({foo: undefined}) + }) + + it('should handle option update error', () => { + state = reduceOptionsEditor(state, optionsEditorActions.updateError('foo', 'errorMsg')) + expect(state).toEqual({ foo: {error: 'errorMsg', isUpdating: false, value: 'bar'}}) + // boolean type + state = reduceOptionsEditor(undefined, optionsEditorActions.startUpdate('foo', true)) + state = reduceOptionsEditor(state, optionsEditorActions.updateError('foo', 'errorMsg')) + expect(state).toEqual({ foo: {error: 'errorMsg', isUpdating: false, value: false}}) + }) + + it('should handle hide modal', () => { + expect(reduceOptionsEditor(undefined, {type: HIDE_MODAL})).toEqual({}) + }) +}) diff --git a/web/src/js/__tests__/ducks/ui/optionSpec.js b/web/src/js/__tests__/ducks/ui/optionSpec.js new file mode 100644 index 00000000..4b6b43cc --- /dev/null +++ b/web/src/js/__tests__/ducks/ui/optionSpec.js @@ -0,0 +1,39 @@ +import reduceOption, * as optionActions from '../../../ducks/ui/option' + +describe('option reducer', () => { + + it('should return the initial state', () => { + expect(reduceOption(undefined, {})).toEqual({}) + }) + + let state = undefined + it('should handle option update start', () => { + state = reduceOption(undefined, { + type: optionActions.OPTION_UPDATE_START, option: 'foo', value: 'bar' + }) + expect(state).toEqual({ + foo: { + error: false, + isUpdating: true, + value: 'bar' + } + }) + }) + + it('should handle option update success', () => { + expect(reduceOption(state, { + type: optionActions.OPTION_UPDATE_SUCCESS, option: 'foo' + })).toEqual({}) + }) + + it('should handle option update error', () => { + expect(reduceOption(undefined, { + type: optionActions.OPTION_UPDATE_ERROR, option: 'foo', error: 'errorMsg' + })).toEqual({ + foo: { + error: 'errorMsg', + isUpdating: false, + } + }) + }) +}) |
