summaryrefslogtreecommitdiffhomepage
path: root/test/components/Account.spec.js
blob: 2c0979bb502f385b83821e43a0c818067e3734cd (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
72
73
// @flow

import * as React from 'react';
import { shallow } from 'enzyme';
import Account from '../../app/components/Account';
import type { AccountProps } from '../../app/components/Account';

describe('components/Account', () => {
  const makeProps = (mergeProps: $Shape<AccountProps>): AccountProps => {
    const defaultProps: AccountProps = {
      accountToken: '1234',
      accountExpiry: new Date('2038-01-01').toISOString(),
      updateAccountExpiry: () => Promise.resolve(),
      onClose: () => {},
      onLogout: () => {},
      onBuyMore: () => {},
    };
    return {
      ...defaultProps,
      ...mergeProps,
    };
  };

  it('should call close callback', (done) => {
    const props = makeProps({
      onClose: () => done(),
    });
    const component = getComponent(render(props), 'account__close');
    click(component);
  });

  it('should call logout callback', (done) => {
    const props = makeProps({
      onLogout: () => done(),
    });
    const component = getComponent(render(props), 'account__logout');
    click(component);
  });

  it('should call "buy more" callback', (done) => {
    const props = makeProps({
      onBuyMore: () => done(),
    });
    const component = getComponent(render(props), 'account__buymore');
    click(component);
  });

  it('should display "out of time" message when account expired', () => {
    const props = makeProps({
      accountExpiry: new Date('2001-01-01').toISOString(),
    });
    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({});
    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')();
}