diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-12-14 09:31:05 +0100 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-12-14 09:31:05 +0100 |
| commit | c544d50488a0c44498f23912a43137ab44705456 (patch) | |
| tree | 8f4d0474eadcf7a7916786acb16a5a8d4a3da328 /test | |
| parent | b74910f21f720741a6b7e3e537ee637200e6a449 (diff) | |
| parent | d73225de48ccb45455c08bedb18405f187821c32 (diff) | |
| download | mullvadvpn-c544d50488a0c44498f23912a43137ab44705456.tar.xz mullvadvpn-c544d50488a0c44498f23912a43137ab44705456.zip | |
Merge branch 'reactxp-rebased'
Diffstat (limited to 'test')
| -rw-r--r-- | test/components/HeaderBar.spec.js | 73 | ||||
| -rw-r--r-- | test/setup/enzyme.js | 4 |
2 files changed, 52 insertions, 25 deletions
diff --git a/test/components/HeaderBar.spec.js b/test/components/HeaderBar.spec.js index f739ed9ab0..e4ebb09429 100644 --- a/test/components/HeaderBar.spec.js +++ b/test/components/HeaderBar.spec.js @@ -2,47 +2,70 @@ import { expect } from 'chai'; import React from 'react'; -import ReactTestUtils, { Simulate } from 'react-dom/test-utils'; +import { shallow } from 'enzyme'; import HeaderBar from '../../app/components/HeaderBar'; +require('../setup/enzyme'); + describe('components/HeaderBar', () => { it('should display headerbar', () => { - const component = ReactTestUtils.renderIntoDocument( - <HeaderBar hidden={ false } /> - ); - ReactTestUtils.findRenderedDOMComponentWithClass(component, 'headerbar__container'); + const component = render({ + hidden: false, + }); + const hasChildMatching = hasChild(component, 'headerbar__container'); + expect(hasChildMatching).to.be.true; }); it('should not display headerbar', () => { - const component = ReactTestUtils.renderIntoDocument( - <HeaderBar hidden={ true } /> - ); - const domNodes = ReactTestUtils.scryRenderedDOMComponentsWithClass(component, 'headerbar__container'); - expect(domNodes.length).to.be.equal(0); + const component = render({ + hidden: true, + }); + const hasChildMatching = hasChild(component, 'headerbar__container'); + expect(hasChildMatching).to.be.false; }); it('should display settings button', () => { - const component = ReactTestUtils.renderIntoDocument( - <HeaderBar showSettings={ true } /> - ); - ReactTestUtils.findRenderedDOMComponentWithClass(component, 'headerbar__settings'); + const component = render({ + showSettings: true, + }); + const hasChildMatching = hasChild(component, 'headerbar__settings'); + expect(hasChildMatching).to.be.true; }); it('should not display settings button', () => { - const component = ReactTestUtils.renderIntoDocument( - <HeaderBar showSettings={ false } /> - ); - const domNodes = ReactTestUtils.scryRenderedDOMComponentsWithClass(component, 'headerbar__settings'); - expect(domNodes.length).to.be.equal(0); + const component = render({ + showSettings: false, + }); + const hasChildMatching = hasChild(component, 'headerbar__settings'); + expect(hasChildMatching).to.be.false; }); it('should call settings callback', (done) => { - const component = ReactTestUtils.renderIntoDocument( - <HeaderBar showSettings={ true } onSettings={ () => done() } /> - ); - const domNode = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'headerbar__settings'); - Simulate.click(domNode); + const component = render({ + showSettings: true, + onSettings: () => done(), + }); + const settingsButton = getComponent(component, 'headerbar__settings'); + click(settingsButton); }); -});
\ No newline at end of file +}); + +function render(props) { + return shallow( + <HeaderBar {...props} /> + ); +} + +function getComponent(container, testName) { + return container.findWhere( n => n.prop('testName') === testName); +} + +function hasChild(container, testName) { + return getComponent(container, testName).length > 0; +} + +function click(component) { + component.prop('onPress')(); +} diff --git a/test/setup/enzyme.js b/test/setup/enzyme.js new file mode 100644 index 0000000000..135148a7c4 --- /dev/null +++ b/test/setup/enzyme.js @@ -0,0 +1,4 @@ +const Enzyme = require('enzyme'); +const Adapter = require('enzyme-adapter-react-16'); + +Enzyme.configure({ adapter: new Adapter() }); |
