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

Migration regressions in voting tab - Closes #597 #606

Merged
merged 7 commits into from
Aug 16, 2017
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
2 changes: 1 addition & 1 deletion src/components/voting/confirmVotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class ConfirmVotes extends React.Component {
onClick: this.props.closeDialog,
}}
primaryButton={{
label: 'Vote',
label: 'Confirm',
fee: Fees.vote,
disabled: (
this.props.votedList.length === 0 &&
Expand Down
14 changes: 6 additions & 8 deletions src/components/voting/confirmVotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import sinonChai from 'sinon-chai';
import PropTypes from 'prop-types';
import sinonStubPromise from 'sinon-stub-promise';
import store from '../../store';
import ConfrimVotesContainer, { ConfirmVotes } from './confirmVotes';
import ConfirmVotesContainer, { ConfirmVotes } from './confirmVotes';
import * as delegateApi from '../../utils/api/delegate';

sinonStubPromise(sinon);
Expand Down Expand Up @@ -43,9 +43,8 @@ const props = {
pendingVotesAdded: sinon.spy(),
addTransaction: sinon.spy(),
};

describe('ConfrimVotesContainer', () => {
it('should render ConfrimVotes', () => {
describe('ConfirmVotesContainer', () => {
it('should render ConfirmVotes', () => {
store.getState = () => ({
peers: {},
voting: {
Expand All @@ -54,15 +53,14 @@ describe('ConfrimVotesContainer', () => {
},
account: {},
});
const wrapper = mount(<ConfrimVotesContainer {...props} store={store} />, {
const wrapper = mount(<ConfirmVotesContainer {...props} store={store} />, {
context: { store },
childContextTypes: { store: PropTypes.object.isRequired },
});
expect(wrapper.find('ConfirmVotes').exists()).to.be.equal(true);
});
});

describe('ConfrimVotes', () => {
describe('ConfirmVotes', () => {
let wrapper;
const delegateApiMock = sinon.stub(delegateApi, 'vote');
beforeEach(() => {
Expand All @@ -79,7 +77,7 @@ describe('ConfrimVotes', () => {
expect(props.pendingVotesAdded).to.have.been.calledWith();
expect(props.addTransaction).to.have.been.calledWith();
expect(props.showSuccessAlert).to.have.been.calledWith();
// it should triger 'props.clearVoteLists' after 10000 ms
// it should trigger 'props.clearVoteLists' after 10000 ms
clock.tick(10000);
expect(props.clearVoteLists).to.have.been.calledWith();
});
Expand Down
15 changes: 10 additions & 5 deletions src/components/voting/voting.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class Voting extends React.Component {

loadVotedDelegates(refresh) {
listAccountDelegates(this.props.activePeer, this.props.address).then((res) => {
const votedDelegates = res.delegates
.map(delegate => Object.assign({}, delegate, { voted: true }));
this.setState({
votedDelegates,
});
if (res.delegates) {
const votedDelegates = res.delegates
.map(delegate => Object.assign({}, delegate, { voted: true }));
this.setState({
votedDelegates,
});
}
if (refresh) {
setTimeout(() => {
const delegates = this.state.delegates.map(delegate => this.setStatus(delegate));
Expand All @@ -61,6 +63,9 @@ class Voting extends React.Component {
} else {
this.loadDelegates(this.query);
}
})
.catch(() => {
this.loadDelegates(this.query);
});
}

Expand Down
9 changes: 7 additions & 2 deletions src/components/voting/votingHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ class VotingHeader extends React.Component {
query: value,
searchIcon: icon,
});
this.props.search(value);
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
if (value === this.state.query) {
this.props.search(value);
}
}, 250);
}

clearSearch() {
Expand Down Expand Up @@ -72,7 +77,7 @@ class VotingHeader extends React.Component {
</IconMenu>
<Button icon='done' flat
onClick={() => this.props.setActiveDialog({
title: 'Verify Vote for delegates',
title: 'Vote for delegates',
childComponent: Confirm,
childComponentProps: {
addTransaction: this.props.addTransaction,
Expand Down
9 changes: 2 additions & 7 deletions src/components/voting/votingHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,12 @@ describe('VotingHeader', () => {
});

it('should this.props.search when this.search is called', () => {
const clock = sinon.useFakeTimers();
wrapper.instance().search('query', '555');
clock.tick(250);
expect(props.search).to.have.been.calledWith('555');
});


it('should this.props.search when this.search is called', () => {
wrapper.instance().search('query', '555');
expect(props.search).to.have.been.calledWith('555');
});


it('click on #searchIcon should clear vlaue of search input', () => {
wrapper.instance().search('query', '555');
wrapper.find('#searchIcon').simulate('click');
Expand Down