From 04e2f7e14cc145aa7e98aa1f70fe6b1854c538d3 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Fri, 26 May 2017 17:27:36 +0800 Subject: [web] Add tests for js/components/Header/FileMenu.jsx --- .../js/__tests__/components/Header/FileMenuSpec.js | 45 ++++++++++++++++++++++ web/src/js/components/Header/FileMenu.jsx | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 web/src/js/__tests__/components/Header/FileMenuSpec.js 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( + , { 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 ( FileMenu.onNewClick(e, clearFlows)}> -- cgit v1.2.3