Skip to content

Commit

Permalink
Merge pull request #487 from LiskHQ/485-use-generic-steps-in-integrat…
Browse files Browse the repository at this point in the history
…ion-tests

Use generic step helper in integration tests - Closes #485
  • Loading branch information
gina contrino committed Feb 28, 2018
2 parents e1b0adf + 8aae31a commit 2fecccb
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 162 deletions.
32 changes: 10 additions & 22 deletions test/integration/accountSwitch.test.js
@@ -1,5 +1,4 @@
import { step } from 'mocha-steps';
import { expect } from 'chai';
import { stub, match } from 'sinon';
import { mount } from 'enzyme';
import thunk from 'redux-thunk';
Expand All @@ -16,11 +15,12 @@ import savedAccountsReducer from '../../src/store/reducers/savedAccounts';
import SavedAccounts from '../../src/components/savedAccounts';
import * as accountApi from '../../src/utils/api/account';
import * as peers from '../../src/utils/api/peers';
import { click } from './steps';
import GenericStepDefinition from '../utils/genericStepDefinition';

describe('@integration: Account switch', () => {
let store;
let wrapper;
let helper;
let getAccountStub;
let requestToActivePeerStub;
let localStorageStub;
Expand Down Expand Up @@ -74,33 +74,21 @@ describe('@integration: Account switch', () => {
wrapper = mount(renderWithRouter(SavedAccounts, store));
store.dispatch(accountsRetrieved());
wrapper.update();
};

const clickStep = (elementName) => {
click(wrapper, elementName);
};

const shouldSeeCountInstancesOf = (count, elementName) => {
const selector = `.${elementName.replace(/ /g, '-')}`;
expect(wrapper.find(selector)).to.have.lengthOf(count);
};

const shouldBeLoggedInAs = (accountName) => {
expect(store.getState().account.publicKey).to.equal(accounts[accountName].publicKey);
helper = new GenericStepDefinition(wrapper, store);
};

describe('Scenario: should allow to remove a saved account', () => {
step('Given I\'m on "account switcher" with accounts: "genesis,delegate,empty account"', setupStep);
step('Then I should see 3 instances of "saved account card"', shouldSeeCountInstancesOf.bind(null, 3, 'saved account card'));
step('When I click "edit button"', clickStep.bind(null, 'edit button'));
step('When I click "remove button"', clickStep.bind(null, 'remove button'));
step('When I click "remove button"', clickStep.bind(null, 'remove button'));
step('Then I should see 2 instances of "saved account card"', shouldSeeCountInstancesOf.bind(null, 2, 'saved account card'));
step('Then I should see 3 instances of "saved account card"', () => helper.shouldSeeCountInstancesOf(3, '.saved-account-card'));
step('When I click "edit button"', () => helper.clickOnElement('button.edit-button'));
step('When I click "remove button"', () => helper.clickOnElement('button.remove-button'));
step('When I click "remove button"', () => helper.clickOnElement('button.remove-button'));
step('Then I should see 2 instances of "saved account card"', () => helper.shouldSeeCountInstancesOf(2, '.saved-account-card'));
});

describe('Scenario: should allow to switch account', () => {
step('Given I\'m on "account switcher" with accounts: "genesis,delegate,empty account"', setupStep);
step('When I click "saved account card"', clickStep.bind(null, 'saved account card'));
step('Then I should be logged in as "genesis" account', shouldBeLoggedInAs.bind(null, 'genesis'));
step('When I click "saved account card"', () => helper.clickOnElement('.saved-account-card'));
step('Then I should be logged in as "genesis" account', () => helper.shouldBeLoggedInAs(accounts.genesis.publicKey));
});
});
59 changes: 28 additions & 31 deletions test/integration/accountTransactions.test.js
Expand Up @@ -20,10 +20,24 @@ import getNetwork from './../../src/utils/getNetwork';
import { accountLoggedIn } from '../../src/actions/account';
import AccountTransactions from './../../src/components/accountTransactions';
import accounts from '../constants/accounts';
import { click } from './steps';
import GenericStepDefinition from '../utils/genericStepDefinition';

class Helper extends GenericStepDefinition {
checkSelectedFilter(filter) {
const expectedClass = '_active';

const activeFilter = this.wrapper.find('.transaction-filter-item').filterWhere((item) => {
const className = item.prop('className');
return className.includes(expectedClass);
});

expect(activeFilter.text().toLowerCase()).to.equal(filter);
}
}

describe('@integration: Account Transactions', () => {
let store;
let helper;
let wrapper;
let requestToActivePeerStub;
let accountAPIStub;
Expand Down Expand Up @@ -86,45 +100,28 @@ describe('@integration: Account Transactions', () => {
if (accountType) { store.dispatch(accountLoggedIn(account)); }
wrapper = mount(renderWithRouter(AccountTransactions, store,
{ match: { params: { address } } }));
};

const clickStep = (elementName) => {
click(wrapper, elementName);
};

const checkRowCount = (length) => {
expect(wrapper.find('TransactionRow')).to.have.length(length);
};

const checkSelectedFilter = (filter) => {
const expectedClass = '_active';

const activeFilter = wrapper.find('.transaction-filter-item').filterWhere((item) => {
const className = item.prop('className');
return className.includes(expectedClass);
});

expect(activeFilter.text().toLowerCase()).to.equal(filter);
helper = new Helper(wrapper, store);
};

describe('Scenario: should allow to view transactions of any account', () => {
step('Given I\'m on "accounts/123L" as "genesis" account', setupStep.bind(null, { accountType: 'genesis', address: '123L' }));
step('Then I should see 20 transaction rows as result of the address 123L', checkRowCount.bind(null, 20));
step('Given I\'m on "accounts/123L" as "genesis" account', () => setupStep({ accountType: 'genesis', address: '123L' }));
step('Then I should see 20 transaction rows as result of the address 123L', () => helper.shouldSeeCountInstancesOf(20, 'TransactionRow'));
});

describe('Scenario: should allow to filter transactions', () => {
step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, { accountType: 'genesis', address: '123L' }));
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('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('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, 20));
step('Given I\'m on "wallet" as "genesis" account', () => setupStep({ accountType: 'genesis', address: '123L' }));
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('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('When I click again on the "All" filter', () => helper.clickOnElement('.filter-all'));
step('Then I expect to see the results for "All"', () => helper.shouldSeeCountInstancesOf(20, 'TransactionRow'));
});

describe('Scenario: allows to view transactions without login', () => {
step('Given I\'m on "accounts/123L" with no account', setupStep.bind(null, { address: '123L' }));
step('Then I should see 20 transaction rows as result of the address 123L', checkRowCount.bind(null, 20));
step('Given I\'m on "accounts/123L" with no account', () => setupStep({ address: '123L' }));
step('Then I should see 20 transaction rows as result of the address 123L', () => helper.shouldSeeCountInstancesOf(20, 'TransactionRow'));
});
});
12 changes: 0 additions & 12 deletions test/integration/steps.js

This file was deleted.

25 changes: 15 additions & 10 deletions test/integration/transactionID.test.js
Expand Up @@ -19,9 +19,19 @@ import getNetwork from './../../src/utils/getNetwork';
import { accountLoggedIn } from '../../src/actions/account';
import SingleTransaction from './../../src/components/singleTransaction';
import accounts from '../constants/accounts';
import GenericStepDefinition from '../utils/genericStepDefinition';

class Helper extends GenericStepDefinition {
checkTxDetails() {
expect(this.wrapper.find('#transaction-id').first().text()).to.contain('123456789');
expect(this.wrapper.find('#sender-address').first().text()).to.contain('123l');
expect(this.wrapper.find('#receiver-address').first().text()).to.contain('456l');
}
}

describe('@integration: Single Transaction', () => {
let store;
let helper;
let wrapper;
let requestToActivePeerStub;
let accountAPIStub;
Expand Down Expand Up @@ -68,21 +78,16 @@ describe('@integration: Single Transaction', () => {
if (accountType) { store.dispatch(accountLoggedIn(account)); }
wrapper = mount(renderWithRouter(SingleTransaction, store,
{ match: { params: { id } } }));
};

const checkTxDetails = () => {
expect(wrapper.find('#transaction-id').first().text()).to.contain('123456789');
expect(wrapper.find('#sender-address').first().text()).to.contain('123l');
expect(wrapper.find('#receiver-address').first().text()).to.contain('456l');
helper = new Helper(wrapper, store);
};

describe('Scenario: should allow to view transactions of any account', () => {
step('Given I\'m on "transactions/123456789" as "genesis" account', setupStep.bind(null, { accountType: 'genesis', id: '123456789' }));
step('Then I should see the transaction details of 123456789', checkTxDetails);
step('Given I\'m on "transactions/123456789" as "genesis" account', () => setupStep({ accountType: 'genesis', id: '123456789' }));
step('Then I should see the transaction details of 123456789', () => helper.checkTxDetails());
});

describe('Scenario: should allow to view transactions of any account without login', () => {
step('Given I\'m on "transactions/123456789" as "genesis" account', setupStep.bind(null, { id: '123456789' }));
step('Then I should see the transaction details of 123456789', checkTxDetails);
step('Given I\'m on "transactions/123456789" as "genesis" account', () => setupStep({ id: '123456789' }));
step('Then I should see the transaction details of 123456789', () => helper.checkTxDetails());
});
});
2 changes: 1 addition & 1 deletion test/integration/voting.test.js
Expand Up @@ -140,7 +140,7 @@ const loginProcess = (votes = []) => {
});

wrapper = mount(renderWithRouter(Voting, store));
helper = new Helper(wrapper);
helper = new Helper(wrapper, store);
expect(store.getState().account).to.be.an('Object');
expect(store.getState().voting).to.be.an('Object');
expect(store.getState().peers).to.be.an('Object');
Expand Down

0 comments on commit 2fecccb

Please sign in to comment.