summaryrefslogtreecommitdiffhomepage
path: root/test/components/Login.spec.js
blob: 2767d3706866b6d6a27f3b4c1b3cce050c49183b (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
74
75
76
77
78
79
80
81
82
// @flow

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

describe('components/Login', () => {
  it('does not show the footer when logging in', () => {
    const component = shallow(
      <Login
        {...{
          ...defaultProps,
          loginState: 'logging in',
        }}
      />,
    );
    const visibleFooters = getComponent(component, 'footerVisibility true');
    const invisibleFooters = getComponent(component, 'footerVisibility false');
    expect(visibleFooters.length).to.equal(0);
    expect(invisibleFooters.length).to.equal(1);
  });

  it('shows the footer and account input when not logged in', () => {
    const component = shallow(<Login {...defaultProps} />);
    const visibleFooters = getComponent(component, 'footerVisibility true');
    const invisibleFooters = getComponent(component, 'footerVisibility false');
    expect(visibleFooters.length).to.equal(1);
    expect(invisibleFooters.length).to.equal(0);
    expect(getComponent(component, 'AccountInput').length).to.be.above(0);
  });

  it('does not show the footer nor account input when logged in', () => {
    const component = shallow(
      <Login
        {...{
          ...defaultProps,
          loginState: 'ok',
        }}
      />,
    );
    const visibleFooters = getComponent(component, 'footerVisibility true');
    const invisibleFooters = getComponent(component, 'footerVisibility false');
    expect(visibleFooters.length).to.equal(0);
    expect(invisibleFooters.length).to.equal(1);
    expect(getComponent(component, 'AccountInput').length).to.equal(0);
  });

  it('logs in with the entered account number when clicking the login icon', (done) => {
    const component = shallow(<Login {...defaultProps} />);
    component.setProps({
      accountToken: '1234567890',
      login: (accountToken) => {
        try {
          expect(accountToken).to.equal('1234567890');
          done();
        } catch (e) {
          done(e);
        }
      },
    });

    const accountInputButton = getComponent(component, 'account-input-button');
    accountInputButton.simulate('press');
  });
});

const defaultProps = {
  accountToken: null,
  accountHistory: [],
  loginError: null,
  loginState: 'none',
  openSettings: () => {},
  openExternalLink: (_type) => {},
  login: (_accountToken) => {},
  resetLoginError: () => {},
  updateAccountToken: (_accountToken) => {},
  removeAccountTokenFromHistory: (_accountToken) => Promise.resolve(),
};

function getComponent(container, testName) {
  return container.findWhere((n) => n.prop('testName') === testName);
}