From 366d0d62807f702b2d0f5bf5eb5ce562d9c2de8a Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Tue, 30 May 2017 21:47:50 +0800 Subject: [web] Add tests for js/components/FlowView/ToggleEdit.jsx --- .../components/FlowView/ToggleEditSpec.js | 40 ++++++++++++++++++++++ .../FlowView/__snapshots__/ToggleEditSpec.js.snap | 17 +++++++++ 2 files changed, 57 insertions(+) create mode 100644 web/src/js/__tests__/components/FlowView/ToggleEditSpec.js create mode 100644 web/src/js/__tests__/components/FlowView/__snapshots__/ToggleEditSpec.js.snap diff --git a/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js b/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js new file mode 100644 index 00000000..4578fdc8 --- /dev/null +++ b/web/src/js/__tests__/components/FlowView/ToggleEditSpec.js @@ -0,0 +1,40 @@ +// jest.mock('../../../ducks/ui/flow') +import React from 'react' +import renderer from 'react-test-renderer' +import ToggleEdit from '../../../components/FlowView/ToggleEdit' +import { Provider } from 'react-redux' +import { startEdit, stopEdit } from '../../../ducks/ui/flow' +import { TFlow, TStore } from '../../ducks/tutils' + +let tflow = new TFlow() + +describe('ToggleEdit Component', () => { + let store = TStore(), + provider = renderer.create( + + + ), + tree = provider.toJSON() + + afterEach(() => { store.clearActions() }) + + it('should render correctly', () => { + expect(tree).toMatchSnapshot() + }) + + it('should handle click on stopEdit', () => { + tree.children[0].props.onClick() + expect(store.getActions()).toEqual([stopEdit(tflow, true)]) + }) + + it('should handle click on startEdit', () => { + store.getState().ui.flow.modifiedFlow = false + let provider = renderer.create( + + + ), + tree = provider.toJSON() + tree.children[0].props.onClick() + expect(store.getActions()).toEqual([startEdit(tflow)]) + }) +}) diff --git a/web/src/js/__tests__/components/FlowView/__snapshots__/ToggleEditSpec.js.snap b/web/src/js/__tests__/components/FlowView/__snapshots__/ToggleEditSpec.js.snap new file mode 100644 index 00000000..5a4243a2 --- /dev/null +++ b/web/src/js/__tests__/components/FlowView/__snapshots__/ToggleEditSpec.js.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ToggleEdit Component should render correctly 1`] = ` +
+ + + +
+`; -- cgit v1.2.3