diff options
Diffstat (limited to 'web/src/js/__tests__/ducks/optionsSpec.js')
-rw-r--r-- | web/src/js/__tests__/ducks/optionsSpec.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/web/src/js/__tests__/ducks/optionsSpec.js b/web/src/js/__tests__/ducks/optionsSpec.js index 62019715..0925fcc1 100644 --- a/web/src/js/__tests__/ducks/optionsSpec.js +++ b/web/src/js/__tests__/ducks/optionsSpec.js @@ -1,6 +1,9 @@ -jest.mock('../../utils') - import reduceOptions, * as OptionsActions from '../../ducks/options' +import configureStore from 'redux-mock-store' +import thunk from 'redux-thunk' +import * as OptionsEditorActions from '../../ducks/ui/optionsEditor' + +const mockStore = configureStore([ thunk ]) describe('option reducer', () => { it('should return initial state', () => { @@ -18,8 +21,31 @@ describe('option reducer', () => { }) }) +let store = mockStore() + describe('option actions', () => { + it('should be possible to update option', () => { - expect(reduceOptions(undefined, OptionsActions.update())).toEqual({}) + let mockResponse = { status: 200 }, + promise = Promise.resolve(mockResponse) + global.fetch = r => { return promise } + store.dispatch(OptionsActions.update('foo', 'bar')) + expect(store.getActions()).toEqual([ + { type: OptionsEditorActions.OPTION_UPDATE_START, option: 'foo', value: 'bar'} + ]) + store.clearActions() + }) +}) + +describe('sendUpdate', () => { + + it('should handle error', () => { + let mockResponse = { status: 400, text: p => Promise.resolve('error') }, + promise = Promise.resolve(mockResponse) + global.fetch = r => { return promise } + OptionsActions.pureSendUpdate('bar', 'error') + expect(store.getActions()).toEqual([ + { type: OptionsEditorActions.OPTION_UPDATE_SUCCESS, option: 'foo'} + ]) }) }) |