diff --git a/src/components/delegates/delegates.js b/src/components/delegates/delegates.js index fac85e8e4..d6563ccac 100644 --- a/src/components/delegates/delegates.js +++ b/src/components/delegates/delegates.js @@ -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. * diff --git a/src/components/delegates/delegates.pug b/src/components/delegates/delegates.pug index 8ae53307e..ac18705f7 100644 --- a/src/components/delegates/delegates.pug +++ b/src/components/delegates/delegates.pug @@ -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 diff --git a/test/components/delegates/delegates.spec.js b/test/components/delegates/delegates.spec.js index fdec0cde3..555388731 100644 --- a/test/components/delegates/delegates.spec.js +++ b/test/components/delegates/delegates.spec.js @@ -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(); - }); - }); });