This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
login.test.js
128 lines (117 loc) · 4.49 KB
/
login.test.js
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { mount, shallow } from 'enzyme';
import { BrowserRouter as Router } from 'react-router-dom';
import configureMockStore from 'redux-mock-store';
import Lisk from 'lisk-elements';
import PropTypes from 'prop-types';
import i18n from '../../i18n';
import Login from './login';
describe('Login', () => {
let wrapper;
const address = 'http:localhost:8080';
const passphrase = 'recipe bomb asset salon coil symbol tiger engine assist pact pumpkin';
// Mocking store
const account = {
isDelegate: false,
address: '16313739661670634666L',
username: 'lisk-nano',
};
const peers = { data: {} };
const store = configureMockStore([])({
peers,
account,
activePeerSet: () => {},
});
const history = {
location: {
pathname: '',
search: '',
},
replace: spy(),
};
const props = {
peers,
account,
history,
accountsRetrieved: spy(),
t: data => data,
onAccountUpdated: () => {},
setActiveDialog: spy(),
activePeerSet: () => {
props.peers.data = new Lisk.APIClient(['http://localhost:4000'], {});
},
};
const options = {
context: { store, history, i18n },
childContextTypes: {
store: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
i18n: PropTypes.object.isRequired,
},
lifecycleExperimental: true,
};
describe('Generals', () => {
beforeEach(() => {
wrapper = mount(<Router><Login {...props}/></Router>, options);
});
it('should show error about passphrase length if passphrase is have wrong length', () => {
const expectedError = 'Passphrase should have 12 words, entered passphrase has 11';
wrapper.find('.passphrase input').simulate('change', { target: { value: ' ' } });
wrapper.find('.passphrase input').simulate('change', { target: { value: passphrase } });
expect(wrapper.find('.passphrase')).to.contain(expectedError);
});
});
describe('History management', () => {
props.account = { address: 'dummy' };
it('calls this.props.history.replace(\'/main/transactions\')', () => {
wrapper = shallow(<Login {...props}/>, options);
wrapper.setProps(props);
expect(props.history.replace).to.have.been.calledWith('/main/transactions');
});
it('calls this.props.history.replace with referrer address', () => {
wrapper = shallow(<Login {...props}/>, options);
props.history.replace.reset();
history.location.search = '?referrer=/main/voting';
wrapper.setProps({ history });
expect(props.history.replace).to.have.been.calledWith('/main/voting');
});
it('call this.props.history.replace with "/main/transaction" if referrer address is "/main/forging" and account.isDelegate === false', () => {
history.location.search = '';
wrapper = shallow(<Login {...props}/>, options);
history.location.search = '?referrer=/main/forging';
account.isDelegate = false;
props.history.replace.reset();
wrapper.setProps({ history, account });
expect(props.history.replace).to.have.been.calledWith('/main/transactions');
});
it('calls localStorage.setItem(\'address\', address) if this.state.address', () => {
const spyFn = spy(localStorage, 'setItem');
wrapper = mount(<Router><Login {...props}/></Router>, options);
// set the network dropdown
wrapper.find('div.network').simulate('click');
// select custom node
wrapper.find('div.network ul li').at(2).simulate('click');
// fill the address
wrapper.find('Input.address input').simulate('change', { target: { value: address } });
wrapper.setProps(props);
expect(spyFn).to.have.been.calledWith('address', address);
spyFn.restore();
localStorage.removeItem('address');
});
});
describe('After submission', () => {
it('it should call activePeerSet', () => {
const spyActivePeerSet = spy(props, 'activePeerSet');
wrapper = mount(<Router><Login {...props}/></Router>, options);
// Filling the login form
wrapper.find('div.network').simulate('click');
wrapper.find('div.network ul li').at(2).simulate('click');
wrapper.find('Input.address input').simulate('change', { target: { value: address } });
wrapper.find('Input.passphrase input').simulate('change', { target: { value: passphrase } });
wrapper.find('form').simulate('submit');
expect(spyActivePeerSet).to.have.been.calledWith();
});
});
});