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

Commit

Permalink
Resolve FIXME comments in e2e tests #203
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweet committed May 15, 2017
1 parent 9f2de16 commit f19535b
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/delegates/delegates.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions src/app/components/delegates/vote.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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'}}
2 changes: 1 addition & 1 deletion src/app/components/forging/forging.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/services/api/delegateApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
},

Expand Down
70 changes: 28 additions & 42 deletions src/spec/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -65,21 +65,21 @@ 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();
browser.wait(EC.presenceOf(sendElem), waitTime);

// 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();
}
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -267,15 +267,15 @@ 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() {
login(delegateAccount);
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);
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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');
}

Expand All @@ -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');
}

Expand All @@ -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');
}

Expand Down Expand Up @@ -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', () => {
Expand All @@ -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);
});
});

0 comments on commit f19535b

Please sign in to comment.