summaryrefslogtreecommitdiffhomepage
path: root/test/components/HeaderBar.spec.js
blob: e4ebb0942977c03b65fa1eafe8ccdc4e1f8d8f35 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// @flow

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

require('../setup/enzyme');

describe('components/HeaderBar', () => {

  it('should display headerbar', () => {
    const component = render({
      hidden: false,
    });
    const hasChildMatching = hasChild(component, 'headerbar__container');
    expect(hasChildMatching).to.be.true;
  });

  it('should not display headerbar', () => {
    const component = render({
      hidden: true,
    });
    const hasChildMatching = hasChild(component, 'headerbar__container');
    expect(hasChildMatching).to.be.false;
  });

  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');
    click(settingsButton);
  });

});

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')();
}