diff options
author | Matthew Shao <me@matshao.com> | 2017-05-26 17:27:36 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-05-26 17:27:36 +0800 |
commit | 04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3 (patch) | |
tree | 0e718105623acced61130769062df62f080b7214 | |
parent | 1d7e5544876b111e96358247435ba6dfb674b861 (diff) | |
download | mitmproxy-04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3.tar.gz mitmproxy-04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3.tar.bz2 mitmproxy-04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3.zip |
[web] Add tests for js/components/Header/FileMenu.jsx
-rw-r--r-- | web/src/js/__tests__/components/Header/FileMenuSpec.js | 45 | ||||
-rw-r--r-- | web/src/js/components/Header/FileMenu.jsx | 2 |
2 files changed, 46 insertions, 1 deletions
diff --git a/web/src/js/__tests__/components/Header/FileMenuSpec.js b/web/src/js/__tests__/components/Header/FileMenuSpec.js new file mode 100644 index 00000000..65b4647a --- /dev/null +++ b/web/src/js/__tests__/components/Header/FileMenuSpec.js @@ -0,0 +1,45 @@ +import React from 'react' +import renderer from 'react-test-renderer' +import { FileMenu } from '../../../components/Header/FileMenu' + +global.confirm = jest.fn( s => true ) + +describe('FileMenu Component', () => { + let clearFn = jest.fn(), + loadFn = jest.fn(), + saveFn = jest.fn(), + mockEvent = { + preventDefault: jest.fn(), + target: { files: ["foo", "bar "] } + }, + createNodeMock = () => { return { click: jest.fn() }}, + fileMenu = renderer.create( + <FileMenu clearFlows={clearFn} loadFlows={loadFn} saveFlows={saveFn}/>, { createNodeMock }), + tree = fileMenu.toJSON() + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + let ul = tree.children[1] + + it('should clear flows', () => { + let a = ul.children[0].children[1] + a.props.onClick(mockEvent) + expect(mockEvent.preventDefault).toBeCalled() + expect(clearFn).toBeCalled() + }) + + it('should load flows', () => { + let fileChooser = ul.children[1].children[1], + input = fileChooser.children[2] + input.props.onChange(mockEvent) + expect(loadFn).toBeCalledWith("foo") + }) + + it('should save flows', () => { + let a = ul.children[2].children[1] + a.props.onClick(mockEvent) + expect(saveFn).toBeCalled() + }) +}) diff --git a/web/src/js/components/Header/FileMenu.jsx b/web/src/js/components/Header/FileMenu.jsx index 1975d1cb..70fbb2c3 100644 --- a/web/src/js/components/Header/FileMenu.jsx +++ b/web/src/js/components/Header/FileMenu.jsx @@ -17,7 +17,7 @@ FileMenu.onNewClick = (e, clearFlows) => { clearFlows() } -function FileMenu ({clearFlows, loadFlows, saveFlows}) { +export function FileMenu ({clearFlows, loadFlows, saveFlows}) { return ( <Dropdown className="pull-left" btnClass="special" text="mitmproxy"> <a href="#" onClick={e => FileMenu.onNewClick(e, clearFlows)}> |