Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions __tests__/tests/components/RepositoryProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ describe('<RepositoryProfile />', () => {
const wrapper = shallow(
<RepositoryProfile {...defaultProps} language={false} />
);
const theIcon = wrapper.find({ name: 'fiber-manual-record' });
const icon = wrapper.find({ name: 'fiber-manual-record' });

expect(theIcon.length).toBeTruthy();
expect(icon.length).toBeTruthy();
});

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

expect(theIcon.length).toBeFalsy();
expect(icon.length).toBeFalsy();
});

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

expect(theIcon.length).toBeFalsy();
expect(icon.length).toBeFalsy();
});

it('should render repository fork text container if repository.fork is true', () => {
Expand Down
140 changes: 140 additions & 0 deletions __tests__/tests/components/UserProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import React from 'react';
import { shallow } from 'enzyme';

import { UserProfile } from 'components';

const defaultProps = {
type: 'org',
initialUser: {
avatar_url: {},
updated_at: '12/12/12',
},
user: {
public_repos: 15,
updated_at: '12/12/12',
repositoryList: {
title: 'repo title',
},
followers: 15,
following: 15,
},
starCount: '12',
isFollowing: false,
isFollower: false,
locale: 'en',
navigation: {},
};

describe('<UserProfile />', () => {
it('should render user profile if user has public repos and has starred repos', () => {
const wrapper = shallow(<UserProfile {...defaultProps} />);

const container = wrapper.find({ nativeId: 'user-profile-container' });

expect(container.length).toBeTruthy();
});

it('should return an uri based on initialUser data if initialUser has the property avatar_url', () => {
const initialUser = {
avatar_url: 'foo.jpg',
updated_at: '01/01/01',
};
const wrapper = shallow(
<UserProfile {...defaultProps} initialUser={initialUser} />
);

const result = wrapper.instance().getUserUri();
const expectedResult = `${initialUser.avatar_url}&lastModified=${initialUser.updated_at}`;

expect(result).toEqual(expectedResult);
});

it("should return an uri based on user data if initialUser doesn't have the property avatar_url", () => {
const initialUser = {
updated_at: '01/01/01',
};
const user = {
avatar_url: 'foo.jpg',
updated_at: '01/01/01',
};
const wrapper = shallow(
<UserProfile {...defaultProps} initialUser={initialUser} user={user} />
);

const result = wrapper.instance().getUserUri();
const expectedResult = `${user.avatar_url}&lastModified=${user.updated_at}`;

expect(result).toEqual(expectedResult);
});

it('should call navigation when user press Repository List TouchableOpacity component', () => {
const navigationMock = jest.fn();
const navigation = {
navigate: navigationMock,
};
const wrapper = shallow(
<UserProfile {...defaultProps} navigation={navigation} />
);
const expectedSecondArgument = {
repoCount: 15,
title: 'Repositories',
user: {
...defaultProps.user,
},
};

wrapper.find({ nativeId: 'touchable-repository-list' }).simulate('press');

expect(navigationMock).toHaveBeenCalledTimes(1);
expect(navigationMock).toHaveBeenCalledWith(
'RepositoryList',
expectedSecondArgument
);
});

it('should call navigation when user press Start Count List TouchableOpacity component', () => {
const navigationMock = jest.fn();
const navigation = {
navigate: navigationMock,
};
const wrapper = shallow(
<UserProfile {...defaultProps} navigation={navigation} type="foo" />
);
const expectedSecondArgument = {
followerCount: 15,
title: 'Followers',
user: defaultProps.user,
};

wrapper.find({ nativeId: 'touchable-followers-list' }).simulate('press');

expect(navigationMock).toHaveBeenCalledTimes(1);
expect(navigationMock).toHaveBeenCalledWith(
'FollowerList',
expectedSecondArgument
);
});

it('should call navigation when user press Following List TouchableOpacity component', () => {
const navigationMock = jest.fn();
const navigation = {
navigate: navigationMock,
};
const wrapper = shallow(
<UserProfile {...defaultProps} navigation={navigation} type="foo" />
);
const expectedSecondArgument = {
followingCount: 15,
title: 'Following',
user: defaultProps.user,
};

wrapper.find({ nativeId: 'touchable-following-list' }).simulate('press');

expect(navigationMock).toHaveBeenCalledTimes(1);
expect(navigationMock).toHaveBeenCalledWith(
'FollowingList',
expectedSecondArgument
);
});
});
Loading