summaryrefslogtreecommitdiffhomepage
path: root/test/components
diff options
context:
space:
mode:
Diffstat (limited to 'test/components')
-rw-r--r--test/components/HeaderBar.spec.js73
1 files changed, 48 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')();
+}