Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Merge fix-follow into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
indeyets committed Sep 23, 2016
2 parents b38d83f + ab3d9f2 commit 69d7d52
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/components/follow-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { PropTypes } from 'react';
import { find } from 'lodash';

import {
ArrayOfUsersId as ArrayOfUsersIdPropType,
Expand Down Expand Up @@ -62,8 +61,7 @@ export default class FollowButton extends React.Component {
return null; // do not allow to follow one's self
}

const is_followed = find(following, user.id);
if (is_followed) {
if (following.includes(user.id)) {
return <button className="button button-wide button-yellow" onClick={this.unfollowUser}>Following</button>;
}

Expand Down
5 changes: 4 additions & 1 deletion test-helpers/factories/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ const faker = require('faker');

export default new Factory()
.attr('id', () => uuid.v4())
.attr('created_at', () => faker.date.recent())
.attr('updated_at', () => faker.date.recent())
.attr('username', () => faker.internet.userName().toLowerCase())
.attr('email', () => faker.internet.email())
.attr('password', () => faker.internet.password())
.attr('hashed_password', ['password'], password => bcrypt.hashSync(password, 10))
.attr('email_check_hash', '');
.attr('email_check_hash', '')
.attr('more', { first_login: false });
48 changes: 45 additions & 3 deletions test/unit/components/follow-button.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,57 @@
/*eslint-env node, mocha */
import { shallow } from 'enzyme';
import { v4 as uuid4 } from 'uuid';

import { TestUtils, unexpected, expect, React } from '../../../test-helpers/expect-unit';
import { expect, React } from '../../../test-helpers/expect-unit';
import FollowButton from '../../../src/components/follow-button';
import userFactory from '../../../test-helpers/factories/user';


describe('Follow button Test', function() {
describe('Follow button Test', function () {
const currentUser = userFactory.build();
currentUser.favourites = [];
currentUser.geotags = [];
currentUser.hashtags = [];
currentUser.schools = [];
currentUser.suggested_users = [];
currentUser.followed_geotags = [];
currentUser.followed_hashtags = [];
currentUser.followed_schools = [];
currentUser.liked_geotags = [];
currentUser.liked_hashtags = [];
currentUser.liked_schools = [];
currentUser.likes = [];
currentUser.recent_tags = {
geotags: [],
hashtags: [],
schools: []
};

it('is empty for anonym user or when no current_user in props', function() {
it('is empty for anonym user or when no current_user in props', function () {
const wrapper = shallow(<FollowButton />);

return expect(wrapper.equals(null), 'to be true');
});

it('should render "Follow" for unfollowed users', () => {
const props = {
active_user: currentUser,
following: [uuid4(), uuid4()],
user: userFactory.build()
};
const wrapper = shallow(<FollowButton {...props} />);
return expect(wrapper.text(), 'to be', 'Follow');
});

it('should render "Following" for followed users', () => {
const user = userFactory.build();

const props = {
active_user: currentUser,
following: [uuid4(), uuid4(), user.id],
user
};
const wrapper = shallow(<FollowButton {...props} />);
return expect(wrapper.text(), 'to be', 'Following');
});
});

0 comments on commit 69d7d52

Please sign in to comment.