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

Add selected votes counts bar - Closes #445 #754

Merged
merged 11 commits into from
Sep 26, 2017
Prev Previous commit
Next Next commit
Add unit tests for votingBar
slaweet committed Sep 22, 2017
commit 476042307182c2cf0e3bc7a254c35caeee554d3d
14 changes: 7 additions & 7 deletions src/components/voting/votingBar.js
Original file line number Diff line number Diff line change
@@ -17,25 +17,25 @@ const VotingBar = ({ votes }) => {
return (voteList.length + unvoteList.length ?
<div className={`${style.fixedAtBottom} box voting-bar`}>
<div className={`${grid.row} ${grid['center-xs']}`}>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']}`}>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']} upvotes`}>
<span>Upvotes: </span>
<strong>{voteList.length}</strong>
</span>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']}`}>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']} downvotes`}>
<span>Downvotes: </span>
<strong>{unvoteList.length}</strong>
</span>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']}`}>
<span>Total new votes </span>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']} total-new-votes`}>
<span>Total new votes: </span>
<strong className={totalNewVotesCount > voteMaxCount && style.red}>
{voteList.length + unvoteList.length}
{totalNewVotesCount}
</strong>
<span> / {voteMaxCount}</span>
</span>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']}`}>
<span className={`${grid['col-sm-3']} ${grid['col-xs-12']} total-votes`}>
<span>Total votes: </span>
<strong className={totalVotesCount > 101 && style.red}>
{(votedList.length - unvoteList.length) + voteList.length}
{totalVotesCount}
</strong>
<span> / {votedMaxCount}</span>
</span>
57 changes: 57 additions & 0 deletions src/components/voting/votingBar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import VotingBar from './votingBar';

describe.only('VotingBar', () => {
let wrapper;
const props = {
votes: {
voted: {
confirmed: true,
unconfirmed: false,
},
downvote: {
confirmed: true,
unconfirmed: true,
},
upvote: {
confirmed: false,
unconfirmed: true,
},
upvote2: {
confirmed: false,
unconfirmed: true,
},
notVoted: {
confirmed: false,
unconfirmed: false,
},
},
};
beforeEach(() => {
wrapper = mount(<VotingBar {...props} />);
});

it('should render number of upvotes', () => {
expect(wrapper.find('.upvotes').text()).to.equal('Upvotes: 2');
});

it('should render number of downvotes', () => {
expect(wrapper.find('.downvotes').text()).to.equal('Downvotes: 1');
});

it('should render number of downvotes', () => {
expect(wrapper.find('.total-new-votes').text()).to.equal('Total new votes: 3 / 33');
});

it('should render number of total votes', () => {
expect(wrapper.find('.total-votes').text()).to.equal('Total votes: 3 / 101');
});

it('should not render if no upvotes or downvotes', () => {
wrapper.setProps({ votes: {} });
expect(wrapper.html()).to.equal(null);
});
});