aboutsummaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorMatthew Shao <me@matshao.com>2017-05-26 17:27:36 +0800
committerMatthew Shao <me@matshao.com>2017-05-26 17:27:36 +0800
commit04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3 (patch)
tree0e718105623acced61130769062df62f080b7214 /web
parent1d7e5544876b111e96358247435ba6dfb674b861 (diff)
downloadmitmproxy-04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3.tar.gz
mitmproxy-04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3.tar.bz2
mitmproxy-04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3.zip
[web] Add tests for js/components/Header/FileMenu.jsx
Diffstat (limited to 'web')
-rw-r--r--web/src/js/__tests__/components/Header/FileMenuSpec.js45
-rw-r--r--web/src/js/components/Header/FileMenu.jsx2
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)}>