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
|
// @flow
import { expect } from 'chai';
import React from 'react';
import { shallow } from 'enzyme';
require('../setup/enzyme');
import Account from '../../app/components/Account';
import type { AccountReduxState } from '../../app/redux/account/reducers';
import type { AccountProps } from '../../app/components/Account';
describe('components/Account', () => {
const state: AccountReduxState = {
accountToken: '1234',
accountHistory: [],
expiry: (new Date('2038-01-01')).toISOString(),
status: 'none',
error: null
};
const makeProps = (state: AccountReduxState, mergeProps: $Shape<AccountProps>): AccountProps => {
const defaultProps: AccountProps = {
account: state,
onClose: () => {},
onLogout: () => {},
onBuyMore: () => {}
};
return Object.assign({}, defaultProps, mergeProps);
};
it('should call close callback', (done) => {
const props = makeProps(state, {
onClose: () => done()
});
const component = getComponent(render(props), 'account__close');
click(component);
});
it('should call logout callback', (done) => {
const props = makeProps(state, {
onLogout: () => done()
});
const component = getComponent(render(props), 'account__logout');
click(component);
});
it('should call "buy more" callback', (done) => {
const props = makeProps(state, {
onBuyMore: () => done()
});
const component = getComponent(render(props), 'account__buymore');
click(component);
});
it('should display "out of time" message when account expired', () => {
const expiredState: AccountReduxState = {
accountToken: '1234',
accountHistory: [],
expiry: (new Date('2001-01-01')).toISOString(),
status: 'none',
error: null
};
const props = makeProps(expiredState, {});
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(state, {});
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')();
}
|