diff options
author | Matthew Shao <me@matshao.com> | 2017-05-27 21:22:49 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-05-27 21:22:49 +0800 |
commit | ddc03df4f6cafec98b2009978451760694020af3 (patch) | |
tree | 9083e7a062f6048a3d311abb36062ef13f6abe9e /web/src/js | |
parent | cdb256682ecbd6a76a44dbfb53bfe22eb5665a9c (diff) | |
download | mitmproxy-ddc03df4f6cafec98b2009978451760694020af3.tar.gz mitmproxy-ddc03df4f6cafec98b2009978451760694020af3.tar.bz2 mitmproxy-ddc03df4f6cafec98b2009978451760694020af3.zip |
[web] Add tests for js/components/Header/FlowMenu.jsx
Diffstat (limited to 'web/src/js')
-rw-r--r-- | web/src/js/__tests__/components/Header/FlowMenuSpec.js | 102 | ||||
-rw-r--r-- | web/src/js/__tests__/components/Header/__snapshots__/FlowMenuSpec.js.snap | 245 |
2 files changed, 347 insertions, 0 deletions
diff --git a/web/src/js/__tests__/components/Header/FlowMenuSpec.js b/web/src/js/__tests__/components/Header/FlowMenuSpec.js new file mode 100644 index 00000000..1278d8ee --- /dev/null +++ b/web/src/js/__tests__/components/Header/FlowMenuSpec.js @@ -0,0 +1,102 @@ +jest.mock('../../../flow/utils') + +import React from 'react' +import renderer from 'react-test-renderer' +import ConnectedFlowMenu, { FlowMenu } from '../../../components/Header/FlowMenu' +import { TFlow, TStore }from '../../ducks/tutils' +import { MessageUtils } from "../../../flow/utils" +import { Provider } from 'react-redux' + + +describe('FlowMenu Component', () => { + let actions = { + resumeFlow: jest.fn(), + killFlow: jest.fn(), + replayFlow: jest.fn(), + duplicateFlow: jest.fn(), + removeFlow: jest.fn(), + revertFlow: jest.fn() + }, + tflow = new TFlow() + tflow.modified = true + tflow.intercepted = true + + it('should render correctly without flow', () => { + let flowMenu = renderer.create( + <FlowMenu removeFlow={actions.removeFlow} + killFlow={actions.killFlow} + replayFlow={actions.replayFlow} + duplicateFlow={actions.duplicateFlow} + resumeFlow={actions.resumeFlow} + revertFlow={actions.revertFlow}/>), + tree = flowMenu.toJSON() + expect(tree).toMatchSnapshot() + }) + + let flowMenu = renderer.create(<FlowMenu + flow={tflow} + removeFlow={actions.removeFlow} + killFlow={actions.killFlow} + replayFlow={actions.replayFlow} + duplicateFlow={actions.duplicateFlow} + resumeFlow={actions.resumeFlow} + revertFlow={actions.revertFlow}/>), + tree = flowMenu.toJSON() + + it('should render correctly with flow', () => { + expect(tree).toMatchSnapshot() + }) + + let menu_content_1 = tree.children[0].children[0] + it('should handle replayFlow', () => { + let button = menu_content_1.children[0] + button.props.onClick() + expect(actions.replayFlow).toBeCalledWith(tflow) + }) + + it('should handle duplicateFlow', () => { + let button = menu_content_1.children[1] + button.props.onClick() + expect(actions.duplicateFlow).toBeCalledWith(tflow) + }) + + it('should handle revertFlow', () => { + let button = menu_content_1.children[2] + button.props.onClick() + expect(actions.revertFlow).toBeCalledWith(tflow) + }) + + it('should handle removeFlow', () => { + let button = menu_content_1.children[3] + button.props.onClick() + expect(actions.removeFlow).toBeCalledWith(tflow) + }) + + let menu_content_2 = tree.children[1].children[0] + it('should handle download', () => { + let button = menu_content_2.children[0] + button.props.onClick() + expect(MessageUtils.getContentURL).toBeCalledWith(tflow, tflow.response) + }) + + let menu_content_3 = tree.children[2].children[0] + it('should handle resumeFlow', () => { + let button = menu_content_3.children[0] + button.props.onClick() + expect(actions.resumeFlow).toBeCalledWith(tflow) + }) + + it('should handle killFlow', () => { + let button = menu_content_3.children[1] + button.props.onClick() + expect(actions.killFlow).toBeCalledWith(tflow) + }) + + it('should connect to state', () => { + let store = TStore(), + provider = renderer.create(<Provider store={store}><ConnectedFlowMenu/></Provider>), + tree = provider.toJSON() + expect(tree).toMatchSnapshot() + }) + +}) diff --git a/web/src/js/__tests__/components/Header/__snapshots__/FlowMenuSpec.js.snap b/web/src/js/__tests__/components/Header/__snapshots__/FlowMenuSpec.js.snap new file mode 100644 index 00000000..b0b28f1b --- /dev/null +++ b/web/src/js/__tests__/components/Header/__snapshots__/FlowMenuSpec.js.snap @@ -0,0 +1,245 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FlowMenu Component should connect to state 1`] = ` +<div> + <div + className="menu-group" + > + <div + className="menu-content" + > + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="[r]eplay flow" + > + <i + className="fa fa-fw fa-repeat text-primary" + /> + Replay + </div> + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="[D]uplicate flow" + > + <i + className="fa fa-fw fa-copy text-info" + /> + Duplicate + </div> + <div + className="btn btn-default" + disabled={true} + onClick={false} + title="revert changes to flow [V]" + > + <i + className="fa fa-fw fa-history text-warning" + /> + Revert + </div> + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="[d]elete flow" + > + <i + className="fa fa-fw fa-trash text-danger" + /> + Delete + </div> + </div> + <div + className="menu-legend" + > + Flow Modification + </div> + </div> + <div + className="menu-group" + > + <div + className="menu-content" + > + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="download" + > + <i + className="fa fa-fw fa-download" + /> + Download + </div> + </div> + <div + className="menu-legend" + > + Export + </div> + </div> + <div + className="menu-group" + > + <div + className="menu-content" + > + <div + className="btn btn-default" + disabled={true} + onClick={false} + title="[a]ccept intercepted flow" + > + <i + className="fa fa-fw fa-play text-success" + /> + Resume + </div> + <div + className="btn btn-default" + disabled={true} + onClick={false} + title="kill intercepted flow [x]" + > + <i + className="fa fa-fw fa-times text-danger" + /> + Abort + </div> + </div> + <div + className="menu-legend" + > + Interception + </div> + </div> +</div> +`; + +exports[`FlowMenu Component should render correctly with flow 1`] = ` +<div> + <div + className="menu-group" + > + <div + className="menu-content" + > + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="[r]eplay flow" + > + <i + className="fa fa-fw fa-repeat text-primary" + /> + Replay + </div> + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="[D]uplicate flow" + > + <i + className="fa fa-fw fa-copy text-info" + /> + Duplicate + </div> + <div + className="btn btn-default" + disabled={false} + onClick={[Function]} + title="revert changes to flow [V]" + > + <i + className="fa fa-fw fa-history text-warning" + /> + Revert + </div> + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="[d]elete flow" + > + <i + className="fa fa-fw fa-trash text-danger" + /> + Delete + </div> + </div> + <div + className="menu-legend" + > + Flow Modification + </div> + </div> + <div + className="menu-group" + > + <div + className="menu-content" + > + <div + className="btn btn-default" + disabled={undefined} + onClick={[Function]} + title="download" + > + <i + className="fa fa-fw fa-download" + /> + Download + </div> + </div> + <div + className="menu-legend" + > + Export + </div> + </div> + <div + className="menu-group" + > + <div + className="menu-content" + > + <div + className="btn btn-default" + disabled={false} + onClick={[Function]} + title="[a]ccept intercepted flow" + > + <i + className="fa fa-fw fa-play text-success" + /> + Resume + </div> + <div + className="btn btn-default" + disabled={false} + onClick={[Function]} + title="kill intercepted flow [x]" + > + <i + className="fa fa-fw fa-times text-danger" + /> + Abort + </div> + </div> + <div + className="menu-legend" + > + Interception + </div> + </div> +</div> +`; + +exports[`FlowMenu Component should render correctly without flow 1`] = `<div />`; |