Skip to content

Commit

Permalink
✅ tests for transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiklimenok committed Oct 10, 2018
1 parent 1864276 commit 6e11da6
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/components/spinner/index.js
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import styles from './spinner.css';

const Spinner = () => (
<span className={styles.spinner}>
<span className={`${styles.spinner} spinner`}>
<div className={styles.bounce1} />
<div className={styles.bounce2} />
<div className={styles.bounce3} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/timestamp/index.js
Expand Up @@ -53,7 +53,7 @@ export const Time = translate()((props) => {
export const DateFromTimestamp = translate()((props) => {
moment.locale(i18n.language);
const day = moment(_convertTimeFromFirstBlock(props.time));
return (<span>{day.format('ll')}</span>);
return (<span className={'date'}>{day.format('ll')}</span>);
});

export const TimeFromTimestamp = translate()((props) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/transactions/transactionRow.js
Expand Up @@ -20,12 +20,12 @@ class TransactionRow extends React.Component {
return (
<div className={`${grid.row} ${styles.rows} ${styles.clickable} transactions-row`} onClick={onClick}>
<div className={`${styles.leftText} ${grid['col-xs-6']} ${grid['col-sm-4']} transactions-cell`}>
<div className={`${styles.address}`}>
<div className={`${styles.address} transaction-address`}>
<TransactionType {...props.value} address={props.address}></TransactionType>
</div>
</div>
<div className={`${styles.rightText} ${grid['col-sm-3']} transactions-cell`}>
<div className={`${styles.hiddenXs} ${styles.reference}`}>
<div className={`${styles.hiddenXs} ${styles.reference} transaction-reference`}>
{props.value.asset && props.value.asset.data ?
<span>{props.value.asset.data}</span>
: '-'}
Expand Down
2 changes: 1 addition & 1 deletion src/components/transactions/transactionType.js
Expand Up @@ -37,7 +37,7 @@ const TransactionType = (props) => {
const address = props.address !== props.senderId ? props.senderId : props.recipientId;
const template = type || props.showTransaction ?
<span className={styles.smallButton}>{type || t('Transaction')}</span> :
<span className={styles.ordinaryText}>{address}</span>;
<span className={`${styles.ordinaryText}`}>{address}</span>;
return template;
};

Expand Down
8 changes: 8 additions & 0 deletions test/constants/urls.js
@@ -0,0 +1,8 @@
const urls = {
dashboard: '/dashboard',
wallet: '/wallet',
help: '/help',
settings: '/settings',
};

export default urls;
45 changes: 0 additions & 45 deletions test/cypress/e2e/ex-protractor-cucumber/send.spec.js
@@ -1,17 +1,6 @@
import accounts from '../../../constants/accounts';

describe('Send dialog', () => {
it('should allow to send when enough funds and correct address form', () => {
cy.loginUI(accounts.genesis, 'test');
cy.visit('/wallet');
cy.get('.amount input').click().type('1');
cy.get('.convertor').get('.converted-price').contains(/^\d{1,100}(\.\d{1,2})? USD$/);
cy.get('.recipient input').click().type('23495548317450503L');
cy.get('.send-next-button').click();
cy.get('.send-button').click();
cy.get('.result-box-message').should('have.text', 'Transaction is being processed and will be confirmed. It may take up to 15 minutes to be secured in the blockchain.');
});

it('should be correct number of transactions in a table', () => {
cy.loginUI(accounts.genesis, 'dev');
cy.get('.transactions-row').should('have.length', 5);
Expand All @@ -20,38 +9,4 @@ describe('Send dialog', () => {
cy.get('.transaction-results').scrollTo('bottom');
cy.get('.transactions-row').should('have.length', 50);
});

it('should allow to send when using launch protocol', () => {
cy.loginUI(accounts.genesis, 'dev');
cy.visit('/wallet?recipient=4995063339468361088L&amount=5');
cy.get('.recipient input').should('have.value', '4995063339468361088L');
cy.get('.amount input').should('have.value', '5');
cy.get('.send-next-button').click();
cy.get('.send-button').click();
cy.get('.result-box-message').should('have.text', 'Transaction is being processed and will be confirmed. It may take up to 15 minutes to be secured in the blockchain.');
});

it('should be able to init account if needed', () => {
cy.loginUI(accounts.genesis, 'dev');
cy.visit('wallet');
cy.get('.amount input').click().type('1');
cy.get('.convertor').get('.converted-price').contains(/^\d{1,100}(\.\d{1,2})? USD$/);
cy.get('.recipient input').click().type('94495548317450502L');
cy.get('.send-next-button').click();
cy.get('.send-button').click();
cy.wait(15000);
cy.reload();
cy.loginUI(accounts['without initialization'], 'dev');
cy.visit('wallet');
cy.get('.account-initialization').get('.account-init-button').click();
cy.get('.send-button').click();
cy.get('.result-box-message').should('have.text', 'Transaction is being processed and will be confirmed. It may take up to 15 minutes to be secured in the blockchain.');
cy.get('.okay-button').click();
cy.get('.account-initialization').should('have.length', 0);
cy.wait(15000);
cy.visit('dashboard');
cy.visit('wallet');
cy.get('.account-initialization').should('have.length', 0);
cy.get('.transactions-row').should('have.length', 2);
});
});
2 changes: 1 addition & 1 deletion test/cypress/e2e/login.spec.js
Expand Up @@ -2,7 +2,7 @@ import numeral from 'numeral';
import { fromRawLsk } from '../../../src/utils/lsk';
import accounts from '../../constants/accounts';
import networks from '../../constants/networks';
import chooseNetwork from './utils/chooseNetwork';
import chooseNetwork from '../utils/chooseNetwork';

const ss = {
newAccountBtn: '.new-account-button',
Expand Down
2 changes: 1 addition & 1 deletion test/cypress/e2e/registration.spec.js
@@ -1,5 +1,5 @@
import networks from '../../constants/networks';
import chooseNetwork from './utils/chooseNetwork';
import chooseNetwork from '../utils/chooseNetwork';

const ss = {
networkStatus: '.network-status',
Expand Down
185 changes: 185 additions & 0 deletions test/cypress/e2e/transfer.spec.js
@@ -0,0 +1,185 @@
import accounts from '../../constants/accounts';
import networks from '../../constants/networks';
import urls from '../../constants/urls';

const ss = {
sidebarMenuWalletBtn: '#transactions',
recipientInput: '.recipient input',
amountInput: '.amount input',
referenceInput: '.reference input',
convertorElement: '.convertor',
convertedPrice: '.converted-price',
nextButton: '.send-next-button',
sendButton: '.send-button',
secondPassphraseInput: '.second-passphrase input',
secondPassphraseNextBtn: '.second-passphrase-next',
resultMessage: '.result-box-message',
okayBtn: '.okay-button',
transactoinsTable: '.transaction-results',
transactionRow: '.transaactions-row',
accountInitializationMsg: '.account-initialization',
accountInitializationBtn: '.account-init-button',
spinner: '.spinner',
transactionAddress: '.transaction-address span',
transactionReference: '.transaction-reference',
transactionAmount: '#transactionAmount span',
headerBalance: '.balance span',
};

const msg = {
transferTxSuccess: 'Transaction is being processed and will be confirmed. It may take up to 15 minutes to be secured in the blockchain.',
accountInitializatoinAddress: 'Account initialization',
};

const txConfirmationTimeout = 11000;

const checkWalletPageLoaded = () => cy.get(ss.recipientInput);

const getRandomAddress = () => `23495548666${Math.floor((Math.random() * 899000) + 100000)}L`;
const getRandomAmount = () => Math.floor((Math.random() * 100) + 1);
const getRandomReference = () => Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 5);

const castBalanceStringToNumber = number => parseFloat(number.replace(/,/g, ''));

describe('Wallet', () => {
let randomAddress;
let randomAmount;
let randomReference;
const transactionFee = 0.1;

beforeEach(() => {
randomAddress = getRandomAddress();
randomAmount = getRandomAmount();
randomReference = getRandomReference();
});

it(`Opens by url ${urls.wallet}`, () => {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit(urls.wallet);
cy.url().should('contain', 'wallet');
checkWalletPageLoaded();
});

it('Opens by sidebar button', () => {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit('/dashboard');
cy.get(ss.sidebarMenuWalletBtn).click();
cy.url().should('contain', 'wallet');
checkWalletPageLoaded();
});

it('Transfer tx with empty ref appears in activity pending -> approved,' +
'Header balance is affected', function () {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit(urls.wallet);
cy.get(ss.headerBalance).invoke('text').as('balanceBeforeString');
cy.get(ss.recipientInput).type(randomAddress);
cy.get(ss.amountInput).click().type(randomAmount);
cy.get(ss.nextButton).click();
cy.get(ss.sendButton).click();
cy.get(ss.resultMessage).should('have.text', msg.transferTxSuccess);
cy.get(ss.transactionRow).eq(0).as('tx');
cy.get('@tx').find('.spinner');
cy.get('@tx').find(ss.transactionAddress).should('have.text', randomAddress);
cy.get('@tx').find(ss.transactionReference).should('have.text', '-');
cy.get('@tx').find(ss.transactionAmount).should('have.text', randomAmount.toString());
cy.wait(txConfirmationTimeout);
cy.get('@tx').find(ss.spinner).should('not.exist');
cy.get(ss.headerBalance).should((headerBalance) => {
const balanceAfter = castBalanceStringToNumber(headerBalance.text());
const balanceBefore = castBalanceStringToNumber(this.balanceBeforeString);
expect(balanceAfter)
.to.be.equal(parseFloat((balanceBefore - (randomAmount + transactionFee)).toFixed(6)));
});
});

it('Transfer tx with ref appears in dashboard activity pending -> approved', () => {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit(urls.wallet);
cy.get(ss.recipientInput).type(randomAddress);
cy.get(ss.referenceInput).click().type(randomReference);
cy.get(ss.amountInput).click().type(randomAmount);
cy.get(ss.nextButton).click();
cy.get(ss.sendButton).click();
cy.get(ss.resultMessage).should('have.text', msg.transferTxSuccess);
cy.visit(urls.dashboard);
cy.get(ss.transactionRow).eq(0).as('tx');
cy.get('@tx').find(ss.spinner);
cy.get('@tx').find(ss.transactionAddress).should('have.text', randomAddress);
cy.get('@tx').find(ss.transactionReference).should('have.text', randomReference);
cy.get('@tx').find(ss.transactionAmount).should('have.text', randomAmount.toString());
cy.wait(txConfirmationTimeout);
cy.get('@tx').find(ss.spinner).should('not.exist');
});

it('Transfer tx with second passphrase', () => {
cy.autologin(accounts['second passphrase account'].passphrase, networks.devnet.node);
cy.visit(urls.wallet);
cy.get(ss.recipientInput).type(randomAddress);
cy.get(ss.referenceInput).click().type(randomReference);
cy.get(ss.amountInput).click().type(randomAmount);
cy.get(ss.nextButton).click();
cy.get(ss.secondPassphraseInput).each(($el, index) => {
const passphraseWordsArray = accounts['second passphrase account'].secondPassphrase.split(' ');
cy.wrap($el).type(passphraseWordsArray[index]);
});
cy.get(ss.secondPassphraseNextBtn).click();
cy.get(ss.sendButton).click();
cy.get(ss.resultMessage).should('have.text', msg.transferTxSuccess);
cy.get(ss.transactionRow).eq(0).as('tx');
cy.get('@tx').find('.spinner');
cy.get('@tx').find(ss.transactionAddress).should('have.text', randomAddress);
});

it('Transfer to myself appears as account initialization', () => {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit(urls.wallet);
cy.get(ss.recipientInput).type(accounts.genesis.address);
cy.get(ss.amountInput).click().type(randomAmount);
cy.get(ss.nextButton).click();
cy.get(ss.sendButton).click();
cy.get(ss.transactionRow).eq(0).find(ss.transactionAddress).should('have.text', msg.accountInitializatoinAddress);
});

it('Launch protocol link prefills recipient, amount and reference', () => {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit('/wallet?recipient=4995063339468361088L&amount=5&reference=test');
cy.get(ss.recipientInput).should('have.value', '4995063339468361088L');
cy.get(ss.amountInput).should('have.value', '5');
cy.get(ss.referenceInput).should('have.value', 'test');
});

it('Fiat converter shows amount in USD', () => {
cy.addLocalStorage('settings', 'currency', 'USD');
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit('/wallet?recipient=4995063339468361088L&amount=5');
cy.get(ss.convertedPrice).contains(/^\d{1,100}(\.\d{1,2})? USD$/);
});

it('Fiat converter shows amount in EUR', () => {
cy.addLocalStorage('settings', 'currency', 'EUR');
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit('/wallet?recipient=4995063339468361088L&amount=5');
cy.get(ss.convertedPrice).contains(/^\d{1,100}(\.\d{1,2})? EUR$/);
});

it('Should be able to init account when needed', () => {
cy.autologin(accounts.genesis.passphrase, networks.devnet.node);
cy.visit(urls.wallet);
cy.get(ss.recipientInput).type(accounts['without initialization'].address);
cy.get(ss.amountInput).click().type(randomAmount);
cy.get(ss.nextButton).click();
cy.get(ss.sendButton).click();
cy.wait(txConfirmationTimeout);
cy.autologin(accounts['without initialization'].passphrase, networks.devnet.node);
cy.reload();
cy.visit(urls.wallet);
cy.get(ss.accountInitializationMsg).get(ss.accountInitializationBtn).click();
cy.get(ss.sendButton).click();
cy.get(ss.resultMessage).should('have.text', msg.transferTxSuccess);
cy.get(ss.accountInitializationMsg).should('not.exist');
cy.wait(txConfirmationTimeout);
cy.reload();
cy.get(ss.accountInitializationMsg).should('not.exist');
});
});
@@ -1,4 +1,4 @@
import networks from '../../../constants/networks';
import networks from '../../constants/networks';

const ss = {
networkDropdown: '.network',
Expand Down

0 comments on commit 6e11da6

Please sign in to comment.