Skip to content

Commit

Permalink
Merge pull request #448 from LiskHQ/426-fix-failing-wallet-test
Browse files Browse the repository at this point in the history
Fix @integration: Wallet test that sometimes fails - Closes #426
  • Loading branch information
slaweet authored Mar 2, 2018
2 parents 58534fd + f29aa09 commit 8a26af6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
7 changes: 5 additions & 2 deletions app/src/modules/localeHandler.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,6 +9,7 @@ describe('localeHandler', () => {
const options = {};
let storage;
let electron;
let i18nMock;

beforeEach(() => {
storage = {
Expand All @@ -28,16 +29,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.config.lang).to.equal('de');
expect(electron.Menu.setApplicationMenu).to.have.been.calledWith(electron.Menu);
expect(event.returnValue).to.equal('Rebuilt electron menu.');
Expand Down
39 changes: 24 additions & 15 deletions test/integration/wallet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,39 @@ 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');

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,
secret: match.any,
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(() => {
Expand Down Expand Up @@ -201,12 +201,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('genesis'));
step('Then the "All" filter should be selected by default', () => helper.checkSelectedFilter('all'));
step('When I click on the "Outgoing" filter', () => helper.clickOnElement('.filter-out'));
step('Then I expect to see the results for "Outgoing"', () => helper.shouldSeeCountInstancesOf(5, 'TransactionRow'));
step('Then I expect to see the results for "Outgoing"', () => helper.shouldSeeCountInstancesOf(25, 'TransactionRow'));
step('When I click on the "Incoming" filter', () => helper.clickOnElement('.filter-in'));
step('Then I expect to see the results for "Incoming"', () => helper.shouldSeeCountInstancesOf(15, 'TransactionRow'));
step('Then I expect to see the results for "Incoming"', () => helper.shouldSeeCountInstancesOf(25, 'TransactionRow'));
step('When I click again on the "All" filter', () => helper.clickOnElement('.filter-all'));
step('Then I expect to see the results for "All"', () => helper.shouldSeeCountInstancesOf(25, 'TransactionRow'));
});
Expand Down

0 comments on commit 8a26af6

Please sign in to comment.