From f19535b31213a25640dda2ec523f0c544b7b9821 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Thu, 11 May 2017 10:03:18 +0200 Subject: [PATCH] Resolve FIXME comments in e2e tests #203 --- .../delegateRegistration.js | 2 +- src/app/components/delegates/delegates.pug | 4 +- src/app/components/delegates/vote.pug | 9 ++- src/app/components/forging/forging.js | 2 +- src/app/services/api/delegateApi.js | 12 ++-- src/spec/spec.js | 70 ++++++++----------- 6 files changed, 42 insertions(+), 57 deletions(-) diff --git a/src/app/components/delegate-registration/delegateRegistration.js b/src/app/components/delegate-registration/delegateRegistration.js index b4d377de1..d38725928 100644 --- a/src/app/components/delegate-registration/delegateRegistration.js +++ b/src/app/components/delegate-registration/delegateRegistration.js @@ -15,7 +15,7 @@ app.directive('delegateRegistration', ($mdDialog, delegateService, Account, dial ) .then(() => { dialog.successAlert({ - title: 'Congratulations!', + title: 'Success', text: 'Account was successfully registered as delegate.', }) .then(() => { diff --git a/src/app/components/delegates/delegates.pug b/src/app/components/delegates/delegates.pug index 475d9e27a..cec51219b 100644 --- a/src/app/components/delegates/delegates.pug +++ b/src/app/components/delegates/delegates.pug @@ -38,7 +38,7 @@ div.offline-hide md-button.md-icon-button.lsk-vote-remove-button(ng-click='$ctrl.unselect(username)') i.material-icons close span.pull-right.right-action-buttons - md-button(ng-click='$ctrl.openVoteDialog()') + md-button.vote-button(ng-click='$ctrl.openVoteDialog()') i.material-icons done span Vote span(ng-if='$ctrl.voteList.length || $ctrl.unvoteList.length') @@ -59,7 +59,7 @@ div.offline-hide th(md-column) Uptime th(md-column) Approval tbody(md-body, infinite-scroll='$ctrl.showMore()', infinite-scroll-distance='1') - tr(md-row, ng-hide='$ctrl.filteredDelegates.length || $ctrl.loading') + tr(md-row, ng-if='!$ctrl.filteredDelegates.length && !$ctrl.loading') td(md-cell, colspan='6') No delegates found tr(md-row, ng-repeat="delegate in ($ctrl.filteredDelegates = ($ctrl.delegates | filter : {username: search} )) | limitTo : $ctrl.delegatesDisplayedCount", ng-class='{"downvote": delegate.status.voted && !delegate.status.selected, "upvote": !delegate.status.voted && delegate.status.selected, "pending": delegate.status.pending}') td(md-cell) diff --git a/src/app/components/delegates/vote.pug b/src/app/components/delegates/vote.pug index 2152f2210..257804018 100644 --- a/src/app/components/delegates/vote.pug +++ b/src/app/components/delegates/vote.pug @@ -18,6 +18,9 @@ div.dialog-vote(aria-label='Vote for delegates') md-chip-template {{$chip.username}} md-autocomplete(flex, required, md-input-minlength='2', md-no-cache='false', md-selected-item='$ctrl.selectedUnvoteDelegate', md-search-text='$ctrl.unvoteSearchText', md-items='delegate in $ctrl.delegateService.unvoteAutocomplete($ctrl.unvoteSearchText, $ctrl.votedList)', md-item-text='delegate.username', md-require-match, placeholder='Search by username') span(md-highlight-text='$ctrl.unvoteSearchText') {{delegate.username}} + md-input-container.md-block(ng-if='$ctrl.account.get().secondSignature') + label Second Passphrase + input(type='password', ng-model='$ctrl.secondPassphrase') p.pull-right Fee: 1 LSK md-divider div(layout='row') @@ -28,11 +31,7 @@ div.dialog-vote(aria-label='Vote for delegates') br span You can vote for up to 101 delegates in total. md-divider - md-input-container.md-block(ng-if='$ctrl.account.get().secondSignature') - label Second Passphrase - input(type='password', ng-model='$ctrl.secondPassphrase') - md-divider md-dialog-actions(layout='row') md-button(ng-click="$ctrl.$mdDialog.cancel()") Cancel span(flex) - md-button(ng-disabled='!$ctrl.canVote()', ng-click="$ctrl.vote()") {{$ctrl.votingInProgress ? 'Voting...' : 'Confirm vote'}} + md-button.md-primary(ng-disabled='!$ctrl.canVote()', ng-click="$ctrl.vote()") {{$ctrl.votingInProgress ? 'Voting...' : 'Confirm vote'}} diff --git a/src/app/components/forging/forging.js b/src/app/components/forging/forging.js index ed4b5a5cd..ebbf2a489 100644 --- a/src/app/components/forging/forging.js +++ b/src/app/components/forging/forging.js @@ -54,7 +54,7 @@ app.component('forging', { this.blocks = data.blocks; } else if (offset) { Array.prototype.push.apply(this.blocks, data.blocks); - } else if (this.blocks[0].id !== data.blocks[0].id) { + } else if (this.blocks[0] && data.blocks[0] && this.blocks[0].id !== data.blocks[0].id) { Array.prototype.unshift.apply(this.blocks, data.blocks.filter(block => block.timestamp > this.blocks[0].timestamp)); } diff --git a/src/app/services/api/delegateApi.js b/src/app/services/api/delegateApi.js index 44bdf4843..a58bd5bed 100644 --- a/src/app/services/api/delegateApi.js +++ b/src/app/services/api/delegateApi.js @@ -11,14 +11,14 @@ app.factory('delegateService', Peers => ({ return Peers.sendRequestPromise('delegates/get', options); }, - vote(options) { + vote({secret, publicKey, voteList, unvoteList, secondSecret = null}) { return Peers.sendRequestPromise('accounts/delegates', { - secret: options.secret, - publicKey: options.publicKey, - secondSecret: options.secondSecret, - delegates: options.voteList.map(delegate => `+${delegate.publicKey}`).concat( - options.unvoteList.map(delegate => `-${delegate.publicKey}`), + secret: secret, + publicKey: publicKey, + delegates: voteList.map(delegate => `+${delegate.publicKey}`).concat( + unvoteList.map(delegate => `-${delegate.publicKey}`), ), + secondSecret: secondSecret, }); }, diff --git a/src/spec/spec.js b/src/spec/spec.js index af687105f..3ba46b55b 100644 --- a/src/spec/spec.js +++ b/src/spec/spec.js @@ -43,7 +43,7 @@ function waitForElemAndClickIt(selector) { } function checkErrorMessage(message) { - waitForElemAndCheckItsText('send .md-input-message-animation', message); + waitForElemAndCheckItsText('transfer .md-input-message-animation', message); } function launchApp() { @@ -65,10 +65,10 @@ function logout() { logoutButton.click(); } -function send(fromAccount, toAddress, amount) { +function transfer(fromAccount, toAddress, amount) { login(fromAccount); - const sendElem = element(by.css('send')); - const sendModalButton = element(by.css('md-content.header button.send')); + const sendElem = element(by.css('transfer')); + const sendModalButton = element(by.css('md-content.header button.transfer')); browser.wait(EC.presenceOf(sendModalButton), waitTime); sendModalButton.click(); @@ -76,10 +76,10 @@ function send(fromAccount, toAddress, amount) { // wait for modal animation to finish browser.sleep(1000); - element(by.css('send input[name="recipient"]')).sendKeys(toAddress); - element(by.css('send input[name="amount"]')).sendKeys(`${amount}`); - element(by.css('send input[name="recipient"]')).click(); - const sendButton = element.all(by.css('send button.md-primary')).get(0); + element(by.css('transfer input[name="recipient"]')).sendKeys(toAddress); + element(by.css('transfer input[name="amount"]')).sendKeys(`${amount}`); + element(by.css('transfer input[name="recipient"]')).click(); + const sendButton = element.all(by.css('transfer button.md-primary')).get(0); // browser.wait(EC.presenceOf(sendButton), waitTime); sendButton.click(); } @@ -187,18 +187,18 @@ function testShowBalance() { function testSend() { const amount = 1.1; - send(masterAccount, delegateAccount.address, amount); + transfer(masterAccount, delegateAccount.address, amount); browser.sleep(1000); - checkAlertDialog('Success', `${amount} sent to ${delegateAccount.address}`); + checkAlertDialog('Success', `${amount} LSK was successfully transferred to ${delegateAccount.address}`); } function testSendWithNotEnoughFunds() { - send(emptyAccount, delegateAccount.address, 10000); + transfer(emptyAccount, delegateAccount.address, 10000); checkErrorMessage('Insufficient funds'); } function testSendWithInvalidAddress() { - send(masterAccount, emptyAccount.address.substr(0, 10), 1); + transfer(masterAccount, emptyAccount.address.substr(0, 10), 1); checkErrorMessage('Invalid'); } @@ -267,8 +267,7 @@ function testDelegateRegistration() { waitForElemAndClickIt('md-dialog button.md-primary'); browser.sleep(500); - // FIXME: the title should really be "Success", not "Congratulations!" to be consistent - checkAlertDialog('Congratulations!', 'Account was successfully registered as delegate.'); + checkAlertDialog('Success', 'Account was successfully registered as delegate.'); } function testForgingCenter() { @@ -276,6 +275,7 @@ function testForgingCenter() { waitForElemAndClickIt('main md-tab-item:nth-child(3)'); // FIXME: there is some bug in forging center that makes it really slow to load + // should be fixed by @alihaghighatkhah in #174 browser.sleep(5000); waitForElemAndCheckItsText('forging md-card .title', delegateAccount.username); @@ -288,9 +288,7 @@ function testViewDelegates() { waitForElemAndCheckItsText('delegates table thead tr th:nth-child(1)', 'Vote'); waitForElemAndCheckItsText('delegates table tbody tr td:nth-child(2)', '1'); - // FIXME: there are 20 delegates displayed, so this should be toEqual(20) - // but we have to use ng-if instead of ng-hide for tr with "No delegates found" message - expect(element.all(by.css('delegates table tbody tr')).count()).toEqual(21); + expect(element.all(by.css('delegates table tbody tr')).count()).toEqual(20); } function testSearchDelegates() { @@ -301,9 +299,7 @@ function testSearchDelegates() { browser.sleep(500); waitForElemAndCheckItsText('delegates table tbody tr td:nth-child(3)', delegateAccount.username); - // FIXME: there should be 1 delegate displayed, so this should be toEqual(1) - // but we have to use ng-if instead of ng-hide for tr with "No delegates found" message - expect(element.all(by.css('delegates table tbody tr')).count()).toEqual(2); + expect(element.all(by.css('delegates table tbody tr')).count()).toEqual(1); } function testViewVotes() { @@ -321,10 +317,8 @@ function testVoteFromTable() { waitForElemAndClickIt('delegates tr:nth-child(3) md-checkbox'); waitForElemAndClickIt('delegates tr:nth-child(5) md-checkbox'); waitForElemAndClickIt('delegates tr:nth-child(8) md-checkbox'); - // FIXME: add 'vote-button' class the "Vote" button and use it here - element.all(by.css('delegates md-card-title button')).last().click(); - // FIXME: add 'md-primary' class the "Confirm vote" button and use it here - waitForElemAndClickIt('vote md-dialog-actions button[ng-disabled]'); + element.all(by.css('delegates md-card-title button.vote-button')).last().click(); + waitForElemAndClickIt('vote md-dialog-actions button.md-primary'); waitForElemAndCheckItsText('md-toast', 'Voting successful'); } @@ -333,14 +327,12 @@ function testVoteFromDialog() { waitForElemAndClickIt('main md-tab-item:nth-child(2)'); waitForElemAndClickIt('delegates tr:nth-child(3) md-checkbox'); waitForElemAndClickIt('delegates tr:nth-child(3) md-checkbox'); - // FIXME: add 'vote-button' class the "Vote" button and use it here - element.all(by.css('delegates md-card-title button')).last().click(); + element.all(by.css('delegates md-card-title button.vote-button')).last().click(); element(by.css('md-autocomplete-wrap input')).sendKeys('genesis_7'); waitForElemAndClickIt('md-autocomplete-parent-scope'); element(by.css('md-autocomplete-wrap input')).sendKeys('genesis_7'); waitForElemAndClickIt('md-autocomplete-parent-scope'); - // FIXME: add 'md-primary' class the "Confirm vote" button and use it here - waitForElemAndClickIt('vote md-dialog-actions button[ng-disabled]'); + waitForElemAndClickIt('vote md-dialog-actions button.md-primary'); waitForElemAndCheckItsText('md-toast', 'Voting successful'); } @@ -350,10 +342,8 @@ function testUnvote() { waitForElemAndClickIt('delegates tr:nth-child(3) md-checkbox'); waitForElemAndClickIt('delegates tr:nth-child(5) md-checkbox'); waitForElemAndClickIt('delegates tr:nth-child(8) md-checkbox'); - // FIXME: add 'vote-button' class the "Vote" button and use it here - element.all(by.css('delegates md-card-title button')).last().click(); - // FIXME: add 'md-primary' class the "Confirm vote" button and use it here - waitForElemAndClickIt('vote md-dialog-actions button[ng-disabled]'); + element.all(by.css('delegates md-card-title button.vote-button')).last().click(); + waitForElemAndClickIt('vote md-dialog-actions button.md-primary'); waitForElemAndCheckItsText('md-toast', 'Voting successful'); } @@ -411,10 +401,9 @@ describe('Lisk Nano', () => { }); describe('Send dialog', () => { - it('should allow to send transaction when enough funds and correct address form', testSend); - // FIXME: there is currently a bug - #194 Maximum amount validation doesn't work - xit('should not allow to send transaction when not enough funds', testSendWithNotEnoughFunds); - it('should not allow to send transaction when invalid address', testSendWithInvalidAddress); + it('should allow to do a transfer when enough funds and correct address form', testSend); + it('should not allow to do a transfer when not enough funds', testSendWithNotEnoughFunds); + it('should not allow to do a transfer when invalid address', testSendWithInvalidAddress); }); describe('Transactions tab', () => { @@ -429,11 +418,8 @@ describe('Lisk Nano', () => { it('should allow to view delegates', testViewDelegates); it('should allow to search delegates', testSearchDelegates); it('should allow to view my votes', testViewVotes); - // FIXME: voting is broken, because it sends secondPassphrase = undefined - xit('should allow to select delegates in the "Voting" tab and vote for them', testVoteFromTable); - // FIXME: voting is broken, because it sends secondPassphrase = undefined - xit('should allow to select delegates in the "Vote" dialog and vote for them', testVoteFromDialog); - // FIXME: voting is broken, because it sends secondPassphrase = undefined - xit('should allow to remove votes form delegates', testUnvote); + it('should allow to select delegates in the "Voting" tab and vote for them', testVoteFromTable); + it('should allow to select delegates in the "Vote" dialog and vote for them', testVoteFromDialog); + it('should allow to remove votes form delegates', testUnvote); }); });