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

Commit

Permalink
Merge pull request #383 from LiskHQ/343-remove-input-name-button
Browse files Browse the repository at this point in the history
Remove 'input names' feature from Voting tab - Closes #343
  • Loading branch information
reyraa authored Jun 12, 2017
2 parents e66c779 + 5ab91e7 commit 910973d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 166 deletions.
84 changes: 0 additions & 84 deletions src/components/delegates/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,90 +253,6 @@ app.component('delegates', {
}, UPDATE_INTERVAL);
}

/**
* Needs summary
*
* @method parseVoteListFromInput
*/
parseVoteListFromInput() {
this._parseListFromInput('voteList');
}

/**
* Needs summary
*
* @method parseUnvoteListFromInput
*/
parseUnvoteListFromInput() {
this._parseListFromInput('unvoteList');
}

/**
* @private
*/
_parseListFromInput(listName) {
const list = this[listName];
this.invalidUsernames = [];
this.pendingRequests = 0;
this.usernameList = this.usernameInput.trim().split(this.usernameSeparator);
this.usernameList.forEach((username) => {
if ((listName === 'voteList' && !this.votedDict[username.trim()]) ||
(listName === 'unvoteList' && this.votedDict[username.trim()])) {
this._setSelected(username.trim(), list);
}
});

if (this.pendingRequests === 0) {
this._selectFinish(true, list);
}
}

/**
* @private
*/
_selectFinish(success, list) {
if (list.length !== 0) {
this.usernameListActive = false;
this.usernameInput = '';
this.openVoteDialog();
} else {
this.dialog.errorToast('No delegate usernames could be parsed from the input');
}
}

/**
* @private
*/
_setSelected(username, list) {
const delegate = this.delegates.filter(d => d.username === username)[0];
if (delegate) {
this._selectDelegate(delegate, list);
} else {
this.pendingRequests++;
this.delegateApi.getDelegate(username,
).then((data) => {
this._selectDelegate(data.delegate, list);
}).catch(() => {
this.invalidUsernames.push(username);
}).finally(() => {
this.pendingRequests--;
if (this.pendingRequests === 0) {
this._selectFinish(this.invalidUsernames.length === 0, list);
}
});
}
}
// eslint-disable-next-line class-methods-use-this
_selectDelegate(delegate, list) {
// eslint-disable-next-line no-param-reassign
delegate.status = delegate.status || {};
// eslint-disable-next-line no-param-reassign
delegate.status.selected = true;
if (list.indexOf(delegate) === -1) {
list.push(delegate);
}
}

/**
* Uses dialog.modal to show vote list directive.
*
Expand Down
3 changes: 0 additions & 3 deletions src/components/delegates/delegates.pug
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ div.offline-hide
i.material-icons.search-append(ng-click='$ctrl.clearSearch()', ng-if='search') close
i.material-icons.search-append(ng-hide='search') search
span.pull-right.right-action-buttons
md-button(ng-click='$ctrl.usernameListActive = true')
i.material-icons list
span Input Names
md-menu.pull-right.right-action-buttons
md-button.pull-right.my-votes-button(ng-click='$mdOpenMenu()', ng-disabled='$ctrl.votedList.length == 0')
i.material-icons visibility
Expand Down
79 changes: 0 additions & 79 deletions test/components/delegates/delegates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,83 +303,4 @@ describe('delegates component controller', () => {
$scope.$apply();
});
});

describe('parseVoteListFromInput(list)', () => {
let delegateApiMock;

beforeEach(() => {
delegateApiMock = sinon.mock(controller.delegateApi);
});

it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were immediately resolved', () => {
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = 'genesis_20\ngenesis_42\ngenesis_46\n';
controller.parseVoteListFromInput(controller.unvoteList);
expect(spy).to.have.been.calledWith();
});

it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were resolved immediately or from server', () => {
const username = 'not_fetched_yet';
const deffered = $q.defer();
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = `${username}\ngenesis_42\ngenesis_46`;

controller.parseVoteListFromInput(controller.unvoteList);

deffered.resolve({
success: true,
delegate: {
username,
},
});
$scope.$apply();
expect(spy).to.have.been.calledWith();
});

it('parses this.usernameInput to list of delegates and opens vote dialog if any delegates were resolved', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const spy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = `${username}\ngenesis_42\ngenesis_46`;

controller.parseVoteListFromInput(controller.unvoteList);

deffered.reject({ success: false });
$scope.$apply();
expect(spy).to.have.been.calledWith();
});

it('parses this.usernameInput to list of delegates and shows error toast if no delegates were resolved', () => {
const username = 'invalid_name';
const deffered = $q.defer();
delegateApiMock.expects('getDelegate').withArgs(username).returns(deffered.promise);
const toastSpy = sinon.spy(controller.dialog, 'errorToast');
const dialogSpy = sinon.spy(controller, 'openVoteDialog');
controller.usernameInput = username;
controller.voteList = [];

controller.parseVoteListFromInput(controller.unvoteList);

deffered.reject({ success: false });
$scope.$apply();
expect(toastSpy).to.have.been.calledWith();
expect(dialogSpy).to.not.have.been.calledWith();
});
});

describe('parseUnvoteListFromInput(list)', () => {
it('parses this.usernameInput to list of delegates and opens vote dialog if all delegates were immediately resolved', () => {
const delegate = {
username: 'genesis_20',
status: {},
};
const spy = sinon.spy(controller, 'openVoteDialog');
controller.votedDict[delegate.username] = delegate;
controller.usernameInput = `${delegate.username}\ngenesis_42\ngenesis_46\n`;
controller.parseUnvoteListFromInput(controller.unvoteList);
expect(spy).to.have.been.calledWith();
});
});
});

0 comments on commit 910973d

Please sign in to comment.