diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-08-21 00:25:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-21 00:25:47 -0700 |
commit | 62ab2f2fd5188f31e99560dce788ba85c2933a1a (patch) | |
tree | 8ea119430389e7f220e224b912c26203fc4e8d0c /web/src/js/__tests__ | |
parent | cacee3871c6a9f0be7127f3c790e09a1daaf8490 (diff) | |
parent | bbe6556bfc1b6c9cc6e2f24abf3228d101ad0398 (diff) | |
download | mitmproxy-62ab2f2fd5188f31e99560dce788ba85c2933a1a.tar.gz mitmproxy-62ab2f2fd5188f31e99560dce788ba85c2933a1a.tar.bz2 mitmproxy-62ab2f2fd5188f31e99560dce788ba85c2933a1a.zip |
Merge pull request #1490 from mitmproxy/web_write_tests
[web] add tests
Diffstat (limited to 'web/src/js/__tests__')
-rw-r--r-- | web/src/js/__tests__/ducks/ui/flowSpec.js | 76 | ||||
-rw-r--r-- | web/src/js/__tests__/ducks/utils/listSpec.js | 1 |
2 files changed, 77 insertions, 0 deletions
diff --git a/web/src/js/__tests__/ducks/ui/flowSpec.js b/web/src/js/__tests__/ducks/ui/flowSpec.js new file mode 100644 index 00000000..f838fbaa --- /dev/null +++ b/web/src/js/__tests__/ducks/ui/flowSpec.js @@ -0,0 +1,76 @@ +jest.unmock('../../../ducks/ui/flow') +jest.unmock('../../../ducks/flows') +jest.unmock('lodash') + +import _ from 'lodash' +import reducer, { + startEdit, + setContentViewDescription, + setShowFullContent, + setContent, + updateEdit + } from '../../../ducks/ui/flow' + +import { select, updateFlow } from '../../../ducks/flows' + +describe('flow reducer', () => { + it('should change to edit mode', () => { + let testFlow = {flow : 'foo'} + const newState = reducer(undefined, startEdit({ flow: 'foo' })) + expect(newState.contentView).toEqual('Edit') + expect(newState.modifiedFlow).toEqual(testFlow) + expect(newState.showFullContent).toEqual(true) + }) + it('should set the view description', () => { + expect(reducer(undefined, setContentViewDescription('description')).viewDescription) + .toEqual('description') + }) + + it('should set show full content', () => { + expect(reducer({showFullContent: false}, setShowFullContent()).showFullContent) + .toBeTruthy() + }) + + it('should set showFullContent to true', () => { + let maxLines = 10 + let content = _.range(maxLines) + const newState = reducer({maxContentLines: maxLines}, setContent(content) ) + expect(newState.showFullContent).toBeTruthy() + expect(newState.content).toEqual(content) + }) + + it('should set showFullContent to false', () => { + let maxLines = 5 + let content = _.range(maxLines+1); + const newState = reducer({maxContentLines: maxLines}, setContent(_.range(maxLines+1))) + expect(newState.showFullContent).toBeFalsy() + expect(newState.content).toEqual(content) + }) + + it('should not change the contentview mode', () => { + expect(reducer({contentView: 'foo'}, select(1)).contentView).toEqual('foo') + }) + + it('should change the contentview mode to auto after editing when a new flow will be selected', () => { + expect(reducer({contentView: 'foo', modifiedFlow : 'test_flow'}, select(1)).contentView).toEqual('Auto') + }) + + it('should set update and merge the modifiedflow with the update values', () => { + let modifiedFlow = {headers: []} + let updateValues = {content: 'bar'} + let result = {headers: [], content: 'bar'} + expect(reducer({modifiedFlow}, updateEdit(updateValues)).modifiedFlow).toEqual(result) + }) + + it('should not change the state when a flow is updated which is not selected', () => { + let modifiedFlow = {id: 1} + let updatedFlow = {id: 0} + expect(reducer({modifiedFlow}, updateFlow(updatedFlow)).modifiedFlow).toEqual(modifiedFlow) + }) + + it('should stop editing when the selected flow is updated', () => { + let modifiedFlow = {id: 1} + let updatedFlow = {id: 1} + expect(reducer({modifiedFlow}, updateFlow(updatedFlow)).modifiedFlow).toBeFalsy() + }) +}) diff --git a/web/src/js/__tests__/ducks/utils/listSpec.js b/web/src/js/__tests__/ducks/utils/listSpec.js index 72d162f2..0f5d0f34 100644 --- a/web/src/js/__tests__/ducks/utils/listSpec.js +++ b/web/src/js/__tests__/ducks/utils/listSpec.js @@ -2,6 +2,7 @@ jest.unmock('lodash') jest.unmock('../../../ducks/utils/list') import reduce, * as list from '../../../ducks/utils/list' +import _ from 'lodash' describe('list reduce', () => { |