From 875f2c566c0068298c547a928ce8c41a155a755a Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 20 Feb 2018 10:40:12 +0100 Subject: [PATCH 1/3] Bind all params of wallet setup step because otherwise it mocha treats the test as async --- test/integration/wallet.test.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index 805bc0a9ea..48f3e3dce9 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -134,7 +134,7 @@ describe('@integration: Wallet', () => { describe('Send', () => { describe('Scenario: should not allow to send when not enough funds', () => { - step('Given I\'m on "wallet" as "empty account"', setupStep.bind(null, 'empty account')); + step('Given I\'m on "wallet" as "empty account"', setupStep.bind(null, 'empty account', false)); step('And I fill in "1" to "amount" field', fillInputField.bind(null, '1', 'amount')); step('And I fill in "537318935439898807L" to "recipient" field', fillInputField.bind(null, '537318935439898807L', 'recipient')); step('Then I should see "Not enough LSK" error message', () => { @@ -146,7 +146,7 @@ describe('@integration: Wallet', () => { }); describe('Scenario: should give and error message when sending fails', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); + step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis', false)); step('And I fill in "1" to "amount" field', fillInputField.bind(null, '1', 'amount')); step('And I fill in "537318935439898807L" to "recipient" field', fillInputField.bind(null, '537318935439898807L', 'recipient')); step('And I click "send next button"', clickStep.bind(null, 'send next button')); @@ -158,7 +158,7 @@ describe('@integration: Wallet', () => { }); describe('Scenario: should allow to send LSK from unlocked account', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); + step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis', false)); step('And I fill in "1" to "amount" field', fillInputField.bind(null, '1', 'amount')); step('And I fill in "537318935439898807L" to "recipient" field', fillInputField.bind(null, '537318935439898807L', 'recipient')); step('And I click "send next button"', clickStep.bind(null, 'send next button')); @@ -180,7 +180,7 @@ describe('@integration: Wallet', () => { describe('Scenario: should allow to send LSK from unlocked account with 2nd passphrase', () => { const { secondPassphrase } = accounts['second passphrase account']; - step('Given I\'m on "wallet" as "second passphrase account"', setupStep.bind(null, 'second passphrase account')); + step('Given I\'m on "wallet" as "second passphrase account"', setupStep.bind(null, 'second passphrase account', false)); step('And I fill in "1" to "amount" field', fillInputField.bind(null, '1', 'amount')); step('And I fill in "537318935439898807L" to "recipient" field', fillInputField.bind(null, '537318935439898807L', 'recipient')); step('And I click "send next button"', clickStep.bind(null, 'send next button')); @@ -207,14 +207,14 @@ describe('@integration: Wallet', () => { describe('transactions', () => { describe('Scenario: should allow to view transactions', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); + step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis', false)); step('Then I should see 25 rows', checkRowCount.bind(null, 25)); step('When I scroll to the bottom of "transactions box"', () => { wrapper.find('Waypoint').props().onEnter(); }); step('Then I should see 50 rows', checkRowCount.bind(null, 50)); }); describe('Scenario: should allow to filter transactions', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); + step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis', false)); step('Then the "All" filter should be selected by default', checkSelectedFilter.bind(null, 'all')); step('When I click on the "Outgoing" filter', clickStep.bind(null, 'filter out')); step('Then I expect to see the results for "Outgoing"', checkRowCount.bind(null, 5)); From a48069867b1a215b8c88e31380a16264fe7bcb75 Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Tue, 20 Feb 2018 14:59:07 +0100 Subject: [PATCH 2/3] Hack integration test of wallet to be more stable --- test/integration/wallet.test.js | 39 ++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index 48f3e3dce9..232d4557e5 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -33,6 +33,13 @@ describe('@integration: Wallet', () => { const successMessage = 'Transaction is being processed and will be confirmed. It may take up to 15 minutes to be secured in the blockchain.'; const errorMessage = 'An error occurred while creating the transaction.'; + const generateTransactions = (n) => { + const transactionExample = { senderId: 'sample_address', receiverId: 'some_address', type: txTypes.send }; + const transactions = new Array(n); + transactions.fill(transactionExample); + return transactions; + }; + beforeEach(() => { requestToActivePeerStub = stub(peers, 'requestToActivePeer'); accountAPIStub = stub(accountAPI, 'getAccount'); @@ -40,8 +47,6 @@ describe('@integration: Wallet', () => { localStorageStub = stub(localStorage, 'getItem'); localStorageStub.withArgs('accounts').returns(JSON.stringify([{}, {}])); - const transactionExample = { senderId: 'sample_address', receiverId: 'some_address', type: txTypes.send }; - requestToActivePeerStub.withArgs(match.any, 'transactions', match({ recipientId: '537318935439898807L', amount: 1e8, @@ -49,23 +54,18 @@ describe('@integration: Wallet', () => { secondSecret: match.any, })) .returnsPromise().resolves({ transactionId: 'Some ID' }); - let transactions = new Array(25); - transactions.fill(transactionExample); - requestToActivePeerStub.withArgs(match.any, 'transactions', match({ limit: 25 })) - .returnsPromise().resolves({ transactions, count: 1000 }); + requestToActivePeerStub.withArgs(match.any, 'transactions', match({ limit: 25, senderId: match.defined, recipientId: match.defined })) + .returnsPromise().resolves({ transactions: generateTransactions(25), count: 1000 }); // incoming transaction result - transactions = new Array(15); - transactions.fill(transactionExample); + const transactions = generateTransactions(15); transactions.push({ senderId: 'sample_address', receiverId: 'some_address', type: txTypes.vote }); - requestToActivePeerStub.withArgs(match.any, 'transactions', match({ senderId: undefined })) + requestToActivePeerStub.withArgs(match.any, 'transactions', match({ recipientId: accounts.genesis.address, senderId: undefined })) .returnsPromise().resolves({ transactions, count: 1000 }); // outgoing transaction result - transactions = new Array(5); - transactions.fill(transactionExample); - requestToActivePeerStub.withArgs(match.any, 'transactions', match({ recipientId: undefined })) - .returnsPromise().resolves({ transactions, count: 1000 }); + requestToActivePeerStub.withArgs(match.any, 'transactions', match({ senderId: accounts.genesis.address, recipientId: undefined })) + .returnsPromise().resolves({ transactions: generateTransactions(5), count: 1000 }); }); afterEach(() => { @@ -214,12 +214,21 @@ describe('@integration: Wallet', () => { }); describe('Scenario: should allow to filter transactions', () => { + beforeEach(() => { + // TODO: this beforeEach block a hack because otherwise the test fails with: + // When I click on the "Outgoing" filter + // Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; + // if returning a Promise, ensure it resolves. + requestToActivePeerStub.withArgs(match.any, 'transactions', match.any) + .returnsPromise().resolves({ transactions: generateTransactions(25), count: 1000 }); + }); + step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis', false)); step('Then the "All" filter should be selected by default', checkSelectedFilter.bind(null, 'all')); step('When I click on the "Outgoing" filter', clickStep.bind(null, 'filter out')); - step('Then I expect to see the results for "Outgoing"', checkRowCount.bind(null, 5)); + step('Then I expect to see the results for "Outgoing"', checkRowCount.bind(null, 25)); step('When I click on the "Incoming" filter', clickStep.bind(null, 'filter in')); - step('Then I expect to see the results for "Incoming"', checkRowCount.bind(null, 15)); + step('Then I expect to see the results for "Incoming"', checkRowCount.bind(null, 25)); step('When I click again on the "All" filter', clickStep.bind(null, 'filter all')); step('Then I expect to see the results for "All"', checkRowCount.bind(null, 25)); }); From 3654fb47cb7165cc2910add0bd600e03e89d514e Mon Sep 17 00:00:00 2001 From: Vit Stanislav Date: Mon, 26 Feb 2018 12:55:04 +0100 Subject: [PATCH 3/3] Mock i18n in localeHandler test --- app/src/modules/localeHandler.test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/modules/localeHandler.test.js b/app/src/modules/localeHandler.test.js index 9f816f02b0..91f24ebdb1 100644 --- a/app/src/modules/localeHandler.test.js +++ b/app/src/modules/localeHandler.test.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; // eslint-disable-line import/no-extraneous-dependencies -import { spy } from 'sinon'; // eslint-disable-line import/no-extraneous-dependencies +import { spy, mock } from 'sinon'; // eslint-disable-line import/no-extraneous-dependencies import win from './win'; import localeHandler from './localeHandler'; import i18n from './../i18n'; @@ -9,6 +9,7 @@ describe('localeHandler', () => { const options = []; let storage; let electron; + let i18nMock; beforeEach(() => { storage = { @@ -27,16 +28,18 @@ describe('localeHandler', () => { }, app: { getName: () => ('some name'), getVersion: () => ('some version') }, }; + i18nMock = mock(i18n); }); afterEach(() => { win.eventStack.length = 0; + i18nMock.verify(); }); it('Changes the locale and rebuilds the menu', () => { + i18nMock.expects('changeLanguage').once(); const event = {}; localeHandler.update({ electron, event, langCode: 'de', storage }); - expect(i18n.language).to.equal('de'); expect(options[0].lang).to.equal('de'); expect(electron.Menu.setApplicationMenu).to.have.been.calledWith(electron.Menu); expect(event.returnValue).to.equal('Rebuilt electron menu.');