[web] Add tests for js/components/FlowView/ToggleEdit.jsx

This commit is contained in:
Matthew Shao 2017-05-30 21:47:50 +08:00
parent f840d018e5
commit 366d0d6280
2 changed files with 57 additions and 0 deletions

View File

@ -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(
<Provider store={store}>
<ToggleEdit/>
</Provider>),
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(
<Provider store={store}>
<ToggleEdit/>
</Provider>),
tree = provider.toJSON()
tree.children[0].props.onClick()
expect(store.getActions()).toEqual([startEdit(tflow)])
})
})

View File

@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ToggleEdit Component should render correctly 1`] = `
<div
className="edit-flow-container"
>
<a
className="edit-flow"
onClick={[Function]}
title="Finish Edit"
>
<i
className="fa fa-check"
/>
</a>
</div>
`;