diff options
| author | anderklander <anderklander@gmail.com> | 2018-02-08 11:46:58 +0100 |
|---|---|---|
| committer | anderklander <anderklander@gmail.com> | 2018-02-15 16:02:02 +0100 |
| commit | 7c84d7ba36a74a2d1a9a627ee050b982d6bf2dab (patch) | |
| tree | fa7d69d71260a9e63c68599e9a7104e6b5c86bde /test/components | |
| parent | f6beef965e3e33d9cd1d9fa306f6212db79395c5 (diff) | |
| download | mullvadvpn-7c84d7ba36a74a2d1a9a627ee050b982d6bf2dab.tar.xz mullvadvpn-7c84d7ba36a74a2d1a9a627ee050b982d6bf2dab.zip | |
Account tests
and remove unused import in settings
Diffstat (limited to 'test/components')
| -rw-r--r-- | test/components/Account.spec.js | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/test/components/Account.spec.js b/test/components/Account.spec.js index a8b8e3d501..ccdb1d2117 100644 --- a/test/components/Account.spec.js +++ b/test/components/Account.spec.js @@ -2,7 +2,8 @@ import { expect } from 'chai'; import React from 'react'; -import ReactTestUtils, { Simulate } from 'react-dom/test-utils'; +import { shallow } from 'enzyme'; +require('../setup/enzyme'); import Account from '../../app/components/Account'; import type { AccountReduxState } from '../../app/redux/account/reducers'; @@ -27,34 +28,28 @@ describe('components/Account', () => { return Object.assign({}, defaultProps, mergeProps); }; - const render = (props: AccountProps): Account => { - return ReactTestUtils.renderIntoDocument( - <Account { ...props } /> - ); - }; - it('should call close callback', (done) => { const props = makeProps(state, { onClose: () => done() }); - const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'account__close'); - Simulate.click(domNode); + const component = getComponent(render(props), 'account__close'); + click(component); }); it('should call logout callback', (done) => { const props = makeProps(state, { onLogout: () => done() }); - const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'account__logout'); - Simulate.click(domNode); + const component = getComponent(render(props), 'account__logout'); + click(component); }); it('should call "buy more" callback', (done) => { const props = makeProps(state, { onBuyMore: () => done() }); - const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'account__buymore'); - Simulate.click(domNode); + const component = getComponent(render(props), 'account__buymore'); + click(component); }); it('should display "out of time" message when account expired', () => { @@ -66,13 +61,28 @@ describe('components/Account', () => { error: null }; const props = makeProps(expiredState, {}); - ReactTestUtils.findRenderedDOMComponentWithClass(render(props), 'account__out-of-time'); + const component = getComponent(render(props), 'account__out_of_time'); + expect(component).to.have.length(1); }); it('should not display "out of time" message when account is active', () => { const props = makeProps(state, {}); - const domNodes = ReactTestUtils.scryRenderedDOMComponentsWithClass(render(props), 'account__out-of-time'); - expect(domNodes.length).to.be.equal(0); + const component = getComponent(render(props), 'account__out_of_time'); + expect(component).to.have.length(0); }); }); + +function render(props) { + return shallow( + <Account {...props} /> + ); +} + +function getComponent(container, testName) { + return container.findWhere( n => n.prop('testName') === testName); +} + +function click(component) { + component.prop('onPress')(); +} |
