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
|
// @flow
import * as React from 'react';
import { shallow } from 'enzyme';
import Account from '../../app/components/Account';
import { BackBarItem } from '../../app/components/NavigationBar';
type AccountProps = React.ElementProps<typeof Account>;
describe('components/Account', () => {
const makeProps = (mergeProps: $Shape<AccountProps>): AccountProps => {
const defaultProps: AccountProps = {
accountToken: '1234',
accountExpiry: new Date('2038-01-01').toISOString(),
expiryLocale: 'en-US',
updateAccountExpiry: () => Promise.resolve(),
onCopyAccountToken: () => {},
onClose: () => {},
onLogout: () => {},
onBuyMore: () => {},
};
return {
...defaultProps,
...mergeProps,
};
};
it('should call close callback', (done) => {
const props = makeProps({
onClose: () => done(),
});
const component = render(props)
.find(BackBarItem)
.dive();
component.simulate('press');
});
it('should call logout callback', (done) => {
const props = makeProps({
onLogout: () => done(),
});
const component = getComponent(render(props), 'account__logout');
component.simulate('press');
});
it('should call "buy more" callback', (done) => {
const props = makeProps({
onBuyMore: () => done(),
});
const component = getComponent(render(props), 'account__buymore');
component.simulate('press');
});
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);
}
|