|
| 1 | +import React from 'react'; |
| 2 | +import test from 'ava'; |
| 3 | +import sinon from 'sinon'; |
| 4 | +import { shallow, mount } from 'enzyme'; |
| 5 | +import { App } from '../App'; |
| 6 | +import styles from '../App.css'; |
| 7 | +import { toggleAddPost } from '../AppActions'; |
| 8 | + |
| 9 | +const children = <h1>Test</h1>; |
| 10 | +const dispatch = sinon.spy(); |
| 11 | +const props = { |
| 12 | + children, |
| 13 | + dispatch, |
| 14 | +}; |
| 15 | + |
| 16 | +test('renders properly', t => { |
| 17 | + const wrapper = shallow( |
| 18 | + <App {...props} /> |
| 19 | + ); |
| 20 | + |
| 21 | + // t.is(wrapper.find('Helmet').length, 1); |
| 22 | + t.is(wrapper.find('Header').length, 1); |
| 23 | + t.is(wrapper.find('Footer').length, 1); |
| 24 | + t.is(wrapper.find('Header').prop('toggleAddPost'), wrapper.instance().toggleAddPostSection); |
| 25 | + t.truthy(wrapper.find('Header + div').hasClass(styles.container)); |
| 26 | + t.truthy(wrapper.find('Header + div').children(), children); |
| 27 | +}); |
| 28 | + |
| 29 | +test('calls componentDidMount', t => { |
| 30 | + sinon.spy(App.prototype, 'componentDidMount'); |
| 31 | + mount( |
| 32 | + <App {...props} />, |
| 33 | + { |
| 34 | + context: { |
| 35 | + router: { |
| 36 | + isActive: sinon.stub().returns(true), |
| 37 | + push: sinon.stub(), |
| 38 | + replace: sinon.stub(), |
| 39 | + go: sinon.stub(), |
| 40 | + goBack: sinon.stub(), |
| 41 | + goForward: sinon.stub(), |
| 42 | + setRouteLeaveHook: sinon.stub(), |
| 43 | + createHref: sinon.stub(), |
| 44 | + }, |
| 45 | + }, |
| 46 | + childContextTypes: { |
| 47 | + router: React.PropTypes.object, |
| 48 | + }, |
| 49 | + }, |
| 50 | + ); |
| 51 | + |
| 52 | + t.truthy(App.prototype.componentDidMount.calledOnce); |
| 53 | + App.prototype.componentDidMount.restore(); |
| 54 | +}); |
| 55 | + |
| 56 | +test('calling toggleAddPostSection dispatches toggleAddPost', t => { |
| 57 | + const wrapper = shallow( |
| 58 | + <App {...props} /> |
| 59 | + ); |
| 60 | + |
| 61 | + wrapper.instance().toggleAddPostSection(); |
| 62 | + t.truthy(dispatch.calledOnce); |
| 63 | + t.truthy(dispatch.calledWith(toggleAddPost())); |
| 64 | +}); |
0 commit comments