From b66c8c4f98370710d3f40cfa5d7848f840bd70b6 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Tue, 27 Feb 2018 17:51:40 +0100 Subject: [PATCH 1/5] Use generic step helper in wallet test --- test/integration/wallet.test.js | 158 +++++++++++++--------------- test/utils/genericStepDefinition.js | 4 + 2 files changed, 78 insertions(+), 84 deletions(-) diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index 805bc0a9ea..c8edb3c91d 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -21,7 +21,25 @@ import txTypes from './../../src/constants/transactionTypes'; import getNetwork from './../../src/utils/getNetwork'; import Wallet from '../../src/components/transactionDashboard'; import accounts from '../constants/accounts'; -import { click, containsMessage } from './steps'; +import GenericStepDefinition from '../utils/genericStepDefinition'; + +class Helper extends GenericStepDefinition { + checkRowCount(length) { + this.wrapper.update(); + expect(this.wrapper.find('TransactionRow')).to.have.length(length); + } + + 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: Wallet', () => { let store; @@ -29,6 +47,7 @@ describe('@integration: Wallet', () => { let requestToActivePeerStub; let accountAPIStub; let localStorageStub; + let helper; 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.'; @@ -72,7 +91,6 @@ describe('@integration: Wallet', () => { requestToActivePeerStub.restore(); accountAPIStub.restore(); localStorageStub.restore(); - wrapper.update(); }); const setupStep = (accountType, isLocked = false) => { @@ -103,40 +121,14 @@ describe('@integration: Wallet', () => { accountAPIStub.withArgs(match.any).returnsPromise().resolves({ ...account }); store.dispatch(accountLoggedIn(account)); wrapper = mount(renderWithRouter(Wallet, store, { location: { search: '' } })); - }; - - const fillInputField = (value, field) => { - wrapper.find(`.${field} input`).first().simulate('change', { target: { value } }); - }; - - const clickStep = (elementName) => { - click(wrapper, elementName); - }; - - const shouldContainMessage = (elementName, message) => { - containsMessage(wrapper, elementName, message); - }; - - 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); }; 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('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('Given I\'m on "wallet" as "empty account"', () => setupStep('empty account')); + step('And I fill in "1" to "amount" field', () => helper.fillInputField('1', 'amount')); + step('And I fill in "537318935439898807L" to "recipient" field', () => helper.fillInputField('537318935439898807L', 'recipient')); step('Then I should see "Not enough LSK" error message', () => { expect(wrapper.find('Input').at(1).html()).to.contain('Not enough LSK'); }); @@ -146,84 +138,82 @@ 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('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')); + step('Given I\'m on "wallet" as "genesis" account', () => setupStep('genesis')); + step('And I fill in "1" to "amount" field', () => helper.fillInputField('1', 'amount')); + step('And I fill in "537318935439898807L" to "recipient" field', () => helper.fillInputField('537318935439898807L', 'recipient')); + step('And I click "send next button"', () => helper.clickOnElement('button.send-next-button')); step('When I click "send button"', () => { requestToActivePeerStub.withArgs(match.any, 'transactions', match.any).returnsPromise().rejects({}); - wrapper.find('.send-button button').simulate('click'); + helper.clickOnElement('.send-button button'); }); - step(`Then I should see text ${errorMessage} in "result box message" element`, shouldContainMessage.bind(this, 'result box message', errorMessage)); + step(`Then I should see text ${errorMessage} in "result box message" element`, () => helper.haveTextOf('.result-box-message', errorMessage)); }); describe('Scenario: should allow to send LSK from unlocked account', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); - 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')); - step('When I click "send button"', () => { wrapper.find('.send-button button').simulate('click'); }); - step(`Then I should see text ${successMessage} in "result box message" element`, shouldContainMessage.bind(this, 'result box message', successMessage)); + step('Given I\'m on "wallet" as "genesis" account', () => setupStep('genesis')); + step('And I fill in "1" to "amount" field', () => { helper.fillInputField('1', 'amount'); }); + step('And I fill in "537318935439898807L" to "recipient" field', () => { helper.fillInputField('537318935439898807L', 'recipient'); }); + step('And I click "send next button"', () => { helper.clickOnElement('button.send-next-button'); }); + step('When I click "send button"', () => helper.clickOnElement('button.send-button button')); + step(`Then I should see text ${successMessage} in "result box message" element`, () => helper.haveTextOf('.result-box-message', successMessage)); }); describe('Scenario: should allow to send LSK from locked account', () => { const { passphrase } = accounts.genesis; - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis', true)); - 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')); - step('And I fill in passphrase of "genesis" to "passphrase" field', fillInputField.bind(null, passphrase, 'passphrase')); - step('When I click "next button"', () => { wrapper.find('.first-passphrase-next button').simulate('click'); }); - step('When I click "send button"', () => { wrapper.find('.send-button button').simulate('click'); }); - step(`Then I should see text ${successMessage} in "result box message" element`, shouldContainMessage.bind(this, 'result box message', successMessage)); + step('Given I\'m on "wallet" as "genesis" account', () => setupStep('genesis', true)); + step('And I fill in "1" to "amount" field', () => { helper.fillInputField('1', 'amount'); }); + step('And I fill in "537318935439898807L" to "recipient" field', () => { helper.fillInputField('537318935439898807L', 'recipient'); }); + step('And I click "send next button"', () => helper.clickOnElement('button.send-next-button')); + step('And I fill in passphrase of "genesis" to "passphrase" field', () => { helper.fillInputField(passphrase, 'passphrase'); }); + step('When I click "next button"', () => helper.clickOnElement('.first-passphrase-next button')); + step('When I click "send button"', () => helper.clickOnElement('.send-button button')); + step(`Then I should see text ${successMessage} in "result box message" element`, () => helper.haveTextOf('.result-box-message', successMessage)); }); 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('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')); - step('And I fill in second passphrase of "second passphrase account" to "second passphrase" field', fillInputField.bind(null, secondPassphrase, 'second-passphrase')); - step('When I click "next button"', () => { wrapper.find('.second-passphrase-next button').simulate('click'); }); - step('When I click "send button"', () => { wrapper.find('.send-button button').simulate('click'); }); - step(`Then I should see text ${successMessage} in "result box message" element`, shouldContainMessage.bind(this, 'result box message', successMessage)); + step('Given I\'m on "wallet" as "second passphrase account"', () => setupStep('second passphrase account')); + step('And I fill in "1" to "amount" field', () => { helper.fillInputField('1', 'amount'); }); + step('And I fill in "537318935439898807L" to "recipient" field', () => { helper.fillInputField('537318935439898807L', 'recipient'); }); + step('And I click "send next button"', () => helper.clickOnElement('button.send-next-button')); + step('And I fill in second passphrase of "second passphrase account" to "second passphrase" field', () => { helper.fillInputField(secondPassphrase, 'second-passphrase'); }); + step('When I click "next button"', () => helper.clickOnElement('.second-passphrase-next button')); + step('When I click "send button"', () => helper.clickOnElement('.send-button button')); + step(`Then I should see text ${successMessage} in "result box message" element`, () => helper.haveTextOf('.result-box-message', successMessage)); }); describe('Scenario: should allow to send LSK from locked account with 2nd passphrase', () => { const { secondPassphrase, passphrase } = accounts['second passphrase account']; - step('Given I\'m on "wallet" as "second passphrase account"', setupStep.bind(null, 'second passphrase account', true)); - 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')); - step('And I fill in passphrase of "second passphrase account" to "passphrase" field', fillInputField.bind(null, passphrase, 'passphrase')); - step('When I click "next button"', () => { wrapper.find('.first-passphrase-next button').simulate('click'); }); - step('And I fill in second passphrase of "second passphrase account" to "second passphrase" field', fillInputField.bind(null, secondPassphrase, 'second-passphrase')); - step('When I click "next button"', () => { wrapper.find('.second-passphrase-next button').simulate('click'); }); - step('When I click "send button"', () => { wrapper.find('.send-button button').simulate('click'); }); - step(`Then I should see text ${successMessage} in "result box message" element`, shouldContainMessage.bind(this, 'result box message', successMessage)); + step('Given I\'m on "wallet" as "second passphrase account"', () => setupStep('second passphrase account', true)); + step('And I fill in "1" to "amount" field', () => { helper.fillInputField('1', 'amount'); }); + step('And I fill in "537318935439898807L" to "recipient" field', () => { helper.fillInputField('537318935439898807L', 'recipient'); }); + step('And I click "send next button"', () => helper.clickOnElement('button.send-next-button')); + step('And I fill in passphrase of "second passphrase account" to "passphrase" field', () => { helper.fillInputField(passphrase, 'passphrase'); }); + step('When I click "next button"', () => helper.clickOnElement('.first-passphrase-next button')); + step('And I fill in second passphrase of "second passphrase account" to "second passphrase" field', () => { helper.fillInputField(secondPassphrase, 'second-passphrase'); }); + step('When I click "next button"', () => helper.clickOnElement('.second-passphrase-next button')); + step('When I click "send button"', () => helper.clickOnElement('.send-button button')); + step(`Then I should see text ${successMessage} in "result box message" element`, () => helper.haveTextOf('.result-box-message', successMessage)); }); }); - describe('transactions', () => { + describe('Transactions', () => { describe('Scenario: should allow to view transactions', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); - step('Then I should see 25 rows', checkRowCount.bind(null, 25)); + step('Given I\'m on "wallet" as "genesis" account', () => setupStep('genesis')); + step('Then I should see 25 rows', () => helper.checkRowCount(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)); + step('Then I should see 50 rows', () => helper.checkRowCount(50)); }); describe('Scenario: should allow to filter transactions', () => { - step('Given I\'m on "wallet" as "genesis" account', setupStep.bind(null, 'genesis')); - 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, 25)); + 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.checkRowCount(5)); + step('When I click on the "Incoming" filter', () => helper.clickOnElement('.filter-in')); + step('Then I expect to see the results for "Incoming"', () => helper.checkRowCount(15)); + step('When I click again on the "All" filter', () => helper.clickOnElement('.filter-all')); + step('Then I expect to see the results for "All"', () => helper.checkRowCount(25)); }); - - describe.skip('Scenario: should allow to search transactions'); }); }); diff --git a/test/utils/genericStepDefinition.js b/test/utils/genericStepDefinition.js index 2ae44a7202..d63ab24e79 100644 --- a/test/utils/genericStepDefinition.js +++ b/test/utils/genericStepDefinition.js @@ -41,4 +41,8 @@ export default class GenericStepDefinition { haveTextOf(query, text) { expect(this.wrapper.find(query)).to.have.text(text); } + + fillInputField(value, field) { + this.wrapper.find(`.${field} input`).first().simulate('change', { target: { value } }); + } } From ff6982d55e36aaa8179f6a1d13ad982ebcc47605 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 28 Feb 2018 10:16:16 +0100 Subject: [PATCH 2/5] Use generic step helper in account transaction test --- test/integration/accountTransactions.test.js | 64 ++++++++++---------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/test/integration/accountTransactions.test.js b/test/integration/accountTransactions.test.js index ba3da61509..7c4e9f75f0 100644 --- a/test/integration/accountTransactions.test.js +++ b/test/integration/accountTransactions.test.js @@ -20,10 +20,29 @@ 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 { + checkRowCount(length) { + this.wrapper.update(); + expect(this.wrapper.find('TransactionRow')).to.have.length(length); + } + + 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; @@ -86,45 +105,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); }; 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.checkRowCount(20)); }); 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.checkRowCount(5)); + step('When I click on the "Incoming" filter', () => helper.clickOnElement('.filter-in')); + step('Then I expect to see the results for "Incoming"', () => helper.checkRowCount(15)); + step('When I click again on the "All" filter', () => helper.clickOnElement('.filter-all')); + step('Then I expect to see the results for "All"', () => helper.checkRowCount(20)); }); 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.checkRowCount(20)); }); }); From 53c0bf7202fe6ee67b5f1c74e6f11aae6ea190f6 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 28 Feb 2018 10:22:44 +0100 Subject: [PATCH 3/5] Use generic step helper in transactionID test --- test/integration/transactionID.test.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/test/integration/transactionID.test.js b/test/integration/transactionID.test.js index 58572629c8..d6f89732b4 100644 --- a/test/integration/transactionID.test.js +++ b/test/integration/transactionID.test.js @@ -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; @@ -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); }; 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()); }); }); From f95fd72032c6aa60adc764c0430b1f2d4a0d5b2b Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 28 Feb 2018 11:02:14 +0100 Subject: [PATCH 4/5] Use generic step helper in account switch test --- test/integration/accountSwitch.test.js | 32 ++++++-------------- test/integration/accountTransactions.test.js | 15 +++------ test/integration/steps.js | 12 -------- test/integration/wallet.test.js | 15 +++------ test/utils/genericStepDefinition.js | 11 ++++++- 5 files changed, 30 insertions(+), 55 deletions(-) delete mode 100644 test/integration/steps.js diff --git a/test/integration/accountSwitch.test.js b/test/integration/accountSwitch.test.js index e79e575b2d..a542dae8ce 100644 --- a/test/integration/accountSwitch.test.js +++ b/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'; @@ -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; @@ -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); }; 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(store.getState().account.publicKey, accounts.genesis.publicKey)); }); }); diff --git a/test/integration/accountTransactions.test.js b/test/integration/accountTransactions.test.js index 7c4e9f75f0..3206337680 100644 --- a/test/integration/accountTransactions.test.js +++ b/test/integration/accountTransactions.test.js @@ -23,11 +23,6 @@ import accounts from '../constants/accounts'; import GenericStepDefinition from '../utils/genericStepDefinition'; class Helper extends GenericStepDefinition { - checkRowCount(length) { - this.wrapper.update(); - expect(this.wrapper.find('TransactionRow')).to.have.length(length); - } - checkSelectedFilter(filter) { const expectedClass = '_active'; @@ -111,22 +106,22 @@ describe('@integration: Account Transactions', () => { describe('Scenario: should allow to view transactions of any account', () => { 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.checkRowCount(20)); + 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({ 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.checkRowCount(5)); + 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.checkRowCount(15)); + 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.checkRowCount(20)); + 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({ address: '123L' })); - step('Then I should see 20 transaction rows as result of the address 123L', () => helper.checkRowCount(20)); + step('Then I should see 20 transaction rows as result of the address 123L', () => helper.shouldSeeCountInstancesOf(20, 'TransactionRow')); }); }); diff --git a/test/integration/steps.js b/test/integration/steps.js deleted file mode 100644 index 561bf825c5..0000000000 --- a/test/integration/steps.js +++ /dev/null @@ -1,12 +0,0 @@ -import { expect } from 'chai'; - -// eslint-disable-next-line import/prefer-default-export -export const click = (wrapper, elementName) => { - const selector = `.${elementName.replace(/ /g, '-')}`; - wrapper.find(selector).first().simulate('click'); -}; - -export const containsMessage = (wrapper, elementName, message) => { - const selector = `.${elementName.replace(/ /g, '-')}`; - expect(wrapper.find(selector).first().text()).to.contain(message); -}; diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index c8edb3c91d..783c109d95 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -24,11 +24,6 @@ import accounts from '../constants/accounts'; import GenericStepDefinition from '../utils/genericStepDefinition'; class Helper extends GenericStepDefinition { - checkRowCount(length) { - this.wrapper.update(); - expect(this.wrapper.find('TransactionRow')).to.have.length(length); - } - checkSelectedFilter(filter) { const expectedClass = '_active'; @@ -200,20 +195,20 @@ describe('@integration: Wallet', () => { describe('Transactions', () => { describe('Scenario: should allow to view transactions', () => { step('Given I\'m on "wallet" as "genesis" account', () => setupStep('genesis')); - step('Then I should see 25 rows', () => helper.checkRowCount(25)); + step('Then I should see 25 rows', () => helper.shouldSeeCountInstancesOf(25, 'TransactionRow')); step('When I scroll to the bottom of "transactions box"', () => { wrapper.find('Waypoint').props().onEnter(); }); - step('Then I should see 50 rows', () => helper.checkRowCount(50)); + step('Then I should see 50 rows', () => { wrapper.update(); helper.shouldSeeCountInstancesOf(50, 'TransactionRow'); }); }); describe('Scenario: should allow to filter transactions', () => { 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.checkRowCount(5)); + 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.checkRowCount(15)); + 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.checkRowCount(25)); + step('Then I expect to see the results for "All"', () => helper.shouldSeeCountInstancesOf(25, 'TransactionRow')); }); }); }); diff --git a/test/utils/genericStepDefinition.js b/test/utils/genericStepDefinition.js index d63ab24e79..64a128c38a 100644 --- a/test/utils/genericStepDefinition.js +++ b/test/utils/genericStepDefinition.js @@ -10,7 +10,7 @@ export default class GenericStepDefinition { * @param {String} query - dom query that we need to simulate clink on it */ clickOnElement(query) { - this.wrapper.find(query).simulate('click'); + this.wrapper.find(query).first().simulate('click'); } /** * check that dom query entry is disable or enable @@ -45,4 +45,13 @@ export default class GenericStepDefinition { fillInputField(value, field) { this.wrapper.find(`.${field} input`).first().simulate('change', { target: { value } }); } + + // eslint-disable-next-line class-methods-use-this + shouldBeLoggedInAs(publicKey, expectedPublicKey) { + expect(publicKey).to.equal(expectedPublicKey); + } + + shouldSeeCountInstancesOf(count, query) { + expect(this.wrapper.find(query)).to.have.lengthOf(count); + } } From 8aae31ae477e3d46519e121af674b8835c30b998 Mon Sep 17 00:00:00 2001 From: Gina Contrino Date: Wed, 28 Feb 2018 11:46:35 +0100 Subject: [PATCH 5/5] Added store to generic test steps --- test/integration/accountSwitch.test.js | 4 ++-- test/integration/accountTransactions.test.js | 2 +- test/integration/transactionID.test.js | 2 +- test/integration/voting.test.js | 2 +- test/integration/wallet.test.js | 2 +- test/utils/genericStepDefinition.js | 8 ++++---- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/integration/accountSwitch.test.js b/test/integration/accountSwitch.test.js index a542dae8ce..9dbf1dab1d 100644 --- a/test/integration/accountSwitch.test.js +++ b/test/integration/accountSwitch.test.js @@ -74,7 +74,7 @@ describe('@integration: Account switch', () => { wrapper = mount(renderWithRouter(SavedAccounts, store)); store.dispatch(accountsRetrieved()); wrapper.update(); - helper = new GenericStepDefinition(wrapper); + helper = new GenericStepDefinition(wrapper, store); }; describe('Scenario: should allow to remove a saved account', () => { @@ -89,6 +89,6 @@ describe('@integration: Account switch', () => { 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"', () => helper.clickOnElement('.saved-account-card')); - step('Then I should be logged in as "genesis" account', () => helper.shouldBeLoggedInAs(store.getState().account.publicKey, accounts.genesis.publicKey)); + step('Then I should be logged in as "genesis" account', () => helper.shouldBeLoggedInAs(accounts.genesis.publicKey)); }); }); diff --git a/test/integration/accountTransactions.test.js b/test/integration/accountTransactions.test.js index 3206337680..d8fac3af2c 100644 --- a/test/integration/accountTransactions.test.js +++ b/test/integration/accountTransactions.test.js @@ -101,7 +101,7 @@ describe('@integration: Account Transactions', () => { wrapper = mount(renderWithRouter(AccountTransactions, store, { match: { params: { address } } })); - helper = new Helper(wrapper); + helper = new Helper(wrapper, store); }; describe('Scenario: should allow to view transactions of any account', () => { diff --git a/test/integration/transactionID.test.js b/test/integration/transactionID.test.js index d6f89732b4..296f26bd73 100644 --- a/test/integration/transactionID.test.js +++ b/test/integration/transactionID.test.js @@ -78,7 +78,7 @@ describe('@integration: Single Transaction', () => { if (accountType) { store.dispatch(accountLoggedIn(account)); } wrapper = mount(renderWithRouter(SingleTransaction, store, { match: { params: { id } } })); - helper = new Helper(wrapper); + helper = new Helper(wrapper, store); }; describe('Scenario: should allow to view transactions of any account', () => { diff --git a/test/integration/voting.test.js b/test/integration/voting.test.js index b4ccc7f3bd..03241e4a89 100644 --- a/test/integration/voting.test.js +++ b/test/integration/voting.test.js @@ -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'); diff --git a/test/integration/wallet.test.js b/test/integration/wallet.test.js index 783c109d95..72d4f55911 100644 --- a/test/integration/wallet.test.js +++ b/test/integration/wallet.test.js @@ -116,7 +116,7 @@ describe('@integration: Wallet', () => { accountAPIStub.withArgs(match.any).returnsPromise().resolves({ ...account }); store.dispatch(accountLoggedIn(account)); wrapper = mount(renderWithRouter(Wallet, store, { location: { search: '' } })); - helper = new Helper(wrapper); + helper = new Helper(wrapper, store); }; describe('Send', () => { diff --git a/test/utils/genericStepDefinition.js b/test/utils/genericStepDefinition.js index 64a128c38a..b3066d3fd8 100644 --- a/test/utils/genericStepDefinition.js +++ b/test/utils/genericStepDefinition.js @@ -2,8 +2,9 @@ import { expect } from 'chai'; export default class GenericStepDefinition { - constructor(input) { + constructor(input, store) { this.wrapper = input; + this.store = store; } /** * simulate click on a dom query @@ -46,9 +47,8 @@ export default class GenericStepDefinition { this.wrapper.find(`.${field} input`).first().simulate('change', { target: { value } }); } - // eslint-disable-next-line class-methods-use-this - shouldBeLoggedInAs(publicKey, expectedPublicKey) { - expect(publicKey).to.equal(expectedPublicKey); + shouldBeLoggedInAs(expectedPublicKey) { + expect(this.store.getState().account.publicKey).to.equal(expectedPublicKey); } shouldSeeCountInstancesOf(count, query) {