Skip to content

Commit c781834

Browse files
alejandronanezandrewda
authored andcommitted
test: add UserProfile unit tests (#547)
1 parent fc1ebaa commit c781834

4 files changed

Lines changed: 281 additions & 114 deletions

File tree

__tests__/tests/components/RepositoryProfile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ describe('<RepositoryProfile />', () => {
2424
const wrapper = shallow(
2525
<RepositoryProfile {...defaultProps} language={false} />
2626
);
27-
const theIcon = wrapper.find({ name: 'fiber-manual-record' });
27+
const icon = wrapper.find({ name: 'fiber-manual-record' });
2828

29-
expect(theIcon.length).toBeTruthy();
29+
expect(icon.length).toBeTruthy();
3030
});
3131

3232
it('should not render the Icon component if loading is true', () => {
3333
const wrapper = shallow(
3434
<RepositoryProfile {...defaultProps} loading={true} />
3535
);
36-
const theIcon = wrapper.find({ name: 'fiber-manual-record' });
36+
const icon = wrapper.find({ name: 'fiber-manual-record' });
3737

38-
expect(theIcon.length).toBeFalsy();
38+
expect(icon.length).toBeFalsy();
3939
});
4040

4141
it('should not render the Icon component if repository language is null', () => {
@@ -48,9 +48,9 @@ describe('<RepositoryProfile />', () => {
4848
}}
4949
/>
5050
);
51-
const theIcon = wrapper.find({ name: 'fiber-manual-record' });
51+
const icon = wrapper.find({ name: 'fiber-manual-record' });
5252

53-
expect(theIcon.length).toBeFalsy();
53+
expect(icon.length).toBeFalsy();
5454
});
5555

5656
it('should render repository fork text container if repository.fork is true', () => {
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
4+
import { UserProfile } from 'components';
5+
6+
const defaultProps = {
7+
type: 'org',
8+
initialUser: {
9+
avatar_url: {},
10+
updated_at: '12/12/12',
11+
},
12+
user: {
13+
public_repos: 15,
14+
updated_at: '12/12/12',
15+
repositoryList: {
16+
title: 'repo title',
17+
},
18+
followers: 15,
19+
following: 15,
20+
},
21+
starCount: '12',
22+
isFollowing: false,
23+
isFollower: false,
24+
locale: 'en',
25+
navigation: {},
26+
};
27+
28+
describe('<UserProfile />', () => {
29+
it('should render user profile if user has public repos and has starred repos', () => {
30+
const wrapper = shallow(<UserProfile {...defaultProps} />);
31+
32+
const container = wrapper.find({ nativeId: 'user-profile-container' });
33+
34+
expect(container.length).toBeTruthy();
35+
});
36+
37+
it('should return an uri based on initialUser data if initialUser has the property avatar_url', () => {
38+
const initialUser = {
39+
avatar_url: 'foo.jpg',
40+
updated_at: '01/01/01',
41+
};
42+
const wrapper = shallow(
43+
<UserProfile {...defaultProps} initialUser={initialUser} />
44+
);
45+
46+
const result = wrapper.instance().getUserUri();
47+
const expectedResult = `${initialUser.avatar_url}&lastModified=${initialUser.updated_at}`;
48+
49+
expect(result).toEqual(expectedResult);
50+
});
51+
52+
it("should return an uri based on user data if initialUser doesn't have the property avatar_url", () => {
53+
const initialUser = {
54+
updated_at: '01/01/01',
55+
};
56+
const user = {
57+
avatar_url: 'foo.jpg',
58+
updated_at: '01/01/01',
59+
};
60+
const wrapper = shallow(
61+
<UserProfile {...defaultProps} initialUser={initialUser} user={user} />
62+
);
63+
64+
const result = wrapper.instance().getUserUri();
65+
const expectedResult = `${user.avatar_url}&lastModified=${user.updated_at}`;
66+
67+
expect(result).toEqual(expectedResult);
68+
});
69+
70+
it('should call navigation when user press Repository List TouchableOpacity component', () => {
71+
const navigationMock = jest.fn();
72+
const navigation = {
73+
navigate: navigationMock,
74+
};
75+
const wrapper = shallow(
76+
<UserProfile {...defaultProps} navigation={navigation} />
77+
);
78+
const expectedSecondArgument = {
79+
repoCount: 15,
80+
title: 'Repositories',
81+
user: {
82+
...defaultProps.user,
83+
},
84+
};
85+
86+
wrapper.find({ nativeId: 'touchable-repository-list' }).simulate('press');
87+
88+
expect(navigationMock).toHaveBeenCalledTimes(1);
89+
expect(navigationMock).toHaveBeenCalledWith(
90+
'RepositoryList',
91+
expectedSecondArgument
92+
);
93+
});
94+
95+
it('should call navigation when user press Start Count List TouchableOpacity component', () => {
96+
const navigationMock = jest.fn();
97+
const navigation = {
98+
navigate: navigationMock,
99+
};
100+
const wrapper = shallow(
101+
<UserProfile {...defaultProps} navigation={navigation} type="foo" />
102+
);
103+
const expectedSecondArgument = {
104+
followerCount: 15,
105+
title: 'Followers',
106+
user: defaultProps.user,
107+
};
108+
109+
wrapper.find({ nativeId: 'touchable-followers-list' }).simulate('press');
110+
111+
expect(navigationMock).toHaveBeenCalledTimes(1);
112+
expect(navigationMock).toHaveBeenCalledWith(
113+
'FollowerList',
114+
expectedSecondArgument
115+
);
116+
});
117+
118+
it('should call navigation when user press Following List TouchableOpacity component', () => {
119+
const navigationMock = jest.fn();
120+
const navigation = {
121+
navigate: navigationMock,
122+
};
123+
const wrapper = shallow(
124+
<UserProfile {...defaultProps} navigation={navigation} type="foo" />
125+
);
126+
const expectedSecondArgument = {
127+
followingCount: 15,
128+
title: 'Following',
129+
user: defaultProps.user,
130+
};
131+
132+
wrapper.find({ nativeId: 'touchable-following-list' }).simulate('press');
133+
134+
expect(navigationMock).toHaveBeenCalledTimes(1);
135+
expect(navigationMock).toHaveBeenCalledWith(
136+
'FollowingList',
137+
expectedSecondArgument
138+
);
139+
});
140+
});

0 commit comments

Comments
 (0)