aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/__tests__/ducks/ui/optionEditorSpec.js
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-07-20 15:39:43 +0800
committerMatthew Shao <me@matshao.com>2017-07-20 15:39:43 +0800
commitf465f08c9ac302007b3aec6709a8e82d63c7ad65 (patch)
treef50a0700ba88ac91f1e82fafeb96c65a0e7f4fb4 /web/src/js/__tests__/ducks/ui/optionEditorSpec.js
parentcbf5db9a4ff77440276ca6bb4d395cc5bdee30ad (diff)
downloadmitmproxy-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/optionEditorSpec.js')
-rw-r--r--web/src/js/__tests__/ducks/ui/optionEditorSpec.js32
1 files changed, 32 insertions, 0 deletions
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({})
+ })
+})