summaryrefslogtreecommitdiffhomepage
path: root/test/components/HeaderBar.spec.js
blob: 09eab134ad1bacc59ea07198b40523534b678ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// @flow

import React from 'react';
import { shallow } from 'enzyme';
import HeaderBar from '../../app/components/HeaderBar';

describe('components/HeaderBar', () => {
  it('should display settings button', () => {
    const component = render({
      showSettings: true,
    });
    const hasChildMatching = hasChild(component, 'headerbar__settings');
    expect(hasChildMatching).to.be.true;
  });

  it('should not display settings button', () => {
    const component = render({
      showSettings: false,
    });
    const hasChildMatching = hasChild(component, 'headerbar__settings');
    expect(hasChildMatching).to.be.false;
  });

  it('should call settings callback', (done) => {
    const component = render({
      showSettings: true,
      onSettings: () => done(),
    });
    const settingsButton = getComponent(component, 'headerbar__settings');
    settingsButton.simulate('press');
  });
});

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;
}