From 572bfe596f22b7d4bce95ba13b7e08889fc628e4 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Wed, 5 Dec 2018 17:06:54 +0100 Subject: [PATCH 1/9] :white_check_mark: Fix test coverage for resultBox --- jest.config.js | 2 -- src/components/resultBox/resultBox.js | 25 +++++++------ src/components/resultBox/resultBox.test.js | 42 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/jest.config.js b/jest.config.js index 599b9f751c..ce4982a9b9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -59,7 +59,6 @@ module.exports = { 'src/components/passphraseSteps/index.js', // FollowUp #1515 'src/components/register/register.js', 'src/components/request/specifyRequest.js', - 'src/components/resultBox/resultBox.js', // FollowUp #1515 'src/components/searchBar/index.js', // Passing in mocha but not in Jest 'src/components/send/steps/confirm/confirm.js', // FollowUp #1515 'src/components/send/steps/form/stories.js', @@ -82,7 +81,6 @@ module.exports = { 'src/utils/proxyLogin.js', 'src/utils/rawTransactionWrapper.js', 'src/utils/to.js', - 'src/components/resultBox/resultBox.js', // FollowUp #1515 'src/components/passphraseSteps/index.js', // FollowUp #1515 'src/actions/peers.js', // FollowUp #1515 'src/components/send/steps/confirm/confirm.js', // FollowUp #1515 diff --git a/src/components/resultBox/resultBox.js b/src/components/resultBox/resultBox.js index 3f70eb0f7c..0c14abfc77 100644 --- a/src/components/resultBox/resultBox.js +++ b/src/components/resultBox/resultBox.js @@ -17,6 +17,17 @@ class ResultBox extends React.Component { return this.props.followedAccounts.find(account => account.address === address) === undefined; } + handleRetryButton() { + this.props.transactionFailedClear(); + this.props.prevStep({ + success: null, + account: this.props.account, + recipient: this.props.recipient, + amount: this.props.amount, + password: { value: '' }, + }); + } + render() { return (
@@ -55,17 +66,9 @@ class ResultBox extends React.Component { : null } {!this.props.success && this.props.account.hwInfo ? - : null } diff --git a/src/components/resultBox/resultBox.test.js b/src/components/resultBox/resultBox.test.js index 1ba67b87a8..c2b495a46d 100644 --- a/src/components/resultBox/resultBox.test.js +++ b/src/components/resultBox/resultBox.test.js @@ -119,4 +119,46 @@ describe('Result Box', () => { expect(wrapper).to.have.descendants('.add-to-bookmarks'); }); + + it('should go to next step after clicking "Retry"', () => { + props = { + copy: null, + title: 'test', + account: { hwInfo: {} }, + body: 'test', + success: false, + recipientId: '123', + reset: () => {}, + copyToClipboard: () => {}, + t: () => {}, + followedAccounts: ['123'], + prevStep: spy(), + transactionFailedClear: spy(), + }; + wrapper = mount(, options); + wrapper.debug(); + wrapper.find('.add-to-bookmarks').at(0).simulate('click'); + expect(props.prevStep).to.have.been.calledWith(); + expect(props.transactionFailedClear).to.have.been.calledWith(); + }); + + it('should go to next step after clicking "Add Bookmark"', () => { + props = { + copy: null, + title: 'test', + account: { hwInfo: {} }, + body: 'test', + success: true, + recipientId: 455, + reset: () => {}, + copyToClipboard: () => {}, + t: () => {}, + followedAccounts: ['123'], + nextStep: spy(), + }; + wrapper = mount(, options); + + wrapper.find('.add-follwed-account-button').at(0).simulate('click'); + expect(props.nextStep).to.have.been.calledWith({ address: 455 }); + }); }); From ac173287f1079052f83eded45a07467a8333f5a5 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Thu, 6 Dec 2018 11:40:14 +0100 Subject: [PATCH 2/9] :white_check_mark: Fix test coverage for steps/confirm --- jest.config.js | 2 -- src/components/send/steps/confirm/confirm.js | 2 +- .../send/steps/confirm/confirm.test.js | 24 +++++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/jest.config.js b/jest.config.js index ce4982a9b9..b55bc06ba3 100644 --- a/jest.config.js +++ b/jest.config.js @@ -60,7 +60,6 @@ module.exports = { 'src/components/register/register.js', 'src/components/request/specifyRequest.js', 'src/components/searchBar/index.js', // Passing in mocha but not in Jest - 'src/components/send/steps/confirm/confirm.js', // FollowUp #1515 'src/components/send/steps/form/stories.js', 'src/components/spinner/stories.js', 'src/components/toaster/stories.js', @@ -83,7 +82,6 @@ module.exports = { 'src/utils/to.js', 'src/components/passphraseSteps/index.js', // FollowUp #1515 'src/actions/peers.js', // FollowUp #1515 - 'src/components/send/steps/confirm/confirm.js', // FollowUp #1515 'src/components/sendNew/', ], coverageThreshold: { diff --git a/src/components/send/steps/confirm/confirm.js b/src/components/send/steps/confirm/confirm.js index 6dd5a4daf0..963c0a5f9b 100644 --- a/src/components/send/steps/confirm/confirm.js +++ b/src/components/send/steps/confirm/confirm.js @@ -116,7 +116,7 @@ class Confirm extends React.Component {
-

{title}

+

{title}

{this.props.accountInit diff --git a/src/components/send/steps/confirm/confirm.test.js b/src/components/send/steps/confirm/confirm.test.js index 1926276e89..0edea74e40 100644 --- a/src/components/send/steps/confirm/confirm.test.js +++ b/src/components/send/steps/confirm/confirm.test.js @@ -84,4 +84,28 @@ describe('Confirm Component', () => { expect(wrapper.state('amount').value).to.equal(0.1); }); }); + + describe('With account hardwareWallet account', () => { + beforeEach(() => { + props.address = '123L'; + props.amount = 1; + props.accountInit = false; + props.account.hwInfo = { deviceId: '123123' }; + props.pendingTransactions = ['123']; + + const store = fakeStore({ account }); + + wrapper = mount(, { + context: { store, i18n }, + childContextTypes: { + store: PropTypes.object.isRequired, + i18n: PropTypes.object.isRequired, + }, + }); + }); + + it('hardwareWallet account should show correct title "Confirm transaction on Ledger Nano S"', () => { + expect(wrapper.find('.title').at(0)).to.have.text('Confirm transaction on Ledger Nano S'); + }); + }); }); From d27d8838164e2ee25434e53f3a145d1b3d1bfa89 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Fri, 7 Dec 2018 10:26:36 +0100 Subject: [PATCH 3/9] :white_check_mark: Fix resultBox & action/peers tests --- jest.config.js | 2 -- src/actions/peers.js | 3 ++- src/actions/peers.test.js | 17 +++++++++++++++++ src/components/resultBox/resultBox.js | 2 +- src/components/resultBox/resultBox.test.js | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/jest.config.js b/jest.config.js index b55bc06ba3..7211215817 100644 --- a/jest.config.js +++ b/jest.config.js @@ -41,7 +41,6 @@ module.exports = { 'app/src/ledger.js', 'src/components/receive/index.js', 'src/actions/liskService.js', - 'src/actions/peers.js', // FollowUp #1515 'src/actions/transactions.js', 'src/components/account/stories.js', 'src/components/backgroundMaker/index.js', @@ -81,7 +80,6 @@ module.exports = { 'src/utils/rawTransactionWrapper.js', 'src/utils/to.js', 'src/components/passphraseSteps/index.js', // FollowUp #1515 - 'src/actions/peers.js', // FollowUp #1515 'src/components/sendNew/', ], coverageThreshold: { diff --git a/src/actions/peers.js b/src/actions/peers.js index e40acfe6a9..874d2ff595 100644 --- a/src/actions/peers.js +++ b/src/actions/peers.js @@ -10,6 +10,7 @@ import { extractAddress, extractPublicKey } from '../utils/account'; import { accountLoggedIn, accountLoading, accountLoggedOut } from './account'; import accountConfig from '../constants/account'; import settings from '../constants/settings'; +import { loginType } from '../constants/hwConstants'; const peerSet = (data, config) => ({ data: Object.assign({ @@ -37,7 +38,7 @@ const login = (dispatch, getState, data, config) => { // eslint-disable-line max publicKey, address, network: code || 0, - loginType: data.hwInfo ? 1 : 0, + loginType: data.hwInfo ? loginType.ledger : loginType.normal, peerAddress: data.network.nodes[0], hwInfo: data.hwInfo ? data.hwInfo : {}, }; diff --git a/src/actions/peers.test.js b/src/actions/peers.test.js index a91588859d..36256400e5 100644 --- a/src/actions/peers.test.js +++ b/src/actions/peers.test.js @@ -133,6 +133,23 @@ describe('actions: peers', () => { expect(dispatch).to.have.been.calledWith(); }); + it('dispatch liskAPIClientSet action when hwAccount is logged in ', () => { + getState = () => ({ + peers: { + liskAPIClient: {}, + }, + account: {}, + settings: { autoLog: true }, + }); + + const network = { + testnet: true, + }; + + liskAPIClientSet({ passphrase, network, hwInfo: {} })(dispatch, getState); + expect(dispatch).to.have.been.calledWith(match.hasNested('data.options.nodes', networks.testnet.nodes)); + }); + it('dispatch liskAPIClientSet action even if network.address is undefined', () => { liskAPIClientSet({ passphrase, network: {} })(dispatch, getState); diff --git a/src/components/resultBox/resultBox.js b/src/components/resultBox/resultBox.js index 295991a60e..31e01e0329 100644 --- a/src/components/resultBox/resultBox.js +++ b/src/components/resultBox/resultBox.js @@ -66,7 +66,7 @@ class ResultBox extends React.Component { : null } {!this.props.success && this.props.account && this.props.account.hwInfo ? - : null } From 8ee32b5bde26c01ac1dba3370ea4e258b606e7cb Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Fri, 7 Dec 2018 14:15:44 +0100 Subject: [PATCH 7/9] :recycle: Refactor confirm/confirm.test.js --- .../send/steps/confirm/confirm.test.js | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/components/send/steps/confirm/confirm.test.js b/src/components/send/steps/confirm/confirm.test.js index 0edea74e40..f96c0da24e 100644 --- a/src/components/send/steps/confirm/confirm.test.js +++ b/src/components/send/steps/confirm/confirm.test.js @@ -65,12 +65,15 @@ describe('Confirm Component', () => { describe('With account init', () => { beforeEach(() => { - props.address = '123L'; - props.amount = 1; - props.accountInit = true; + const newProps = { + ...props, + address: '123L', + amount: 1, + accountInit: true, + }; const store = fakeStore({ account }); - wrapper = mount(, { + wrapper = mount(, { context: { store, i18n }, childContextTypes: { store: PropTypes.object.isRequired, @@ -86,25 +89,25 @@ describe('Confirm Component', () => { }); describe('With account hardwareWallet account', () => { - beforeEach(() => { - props.address = '123L'; - props.amount = 1; - props.accountInit = false; - props.account.hwInfo = { deviceId: '123123' }; - props.pendingTransactions = ['123']; + it('hardwareWallet account should show correct title "Confirm transaction on Ledger Nano S"', () => { + const newProps = { + ...props, + address: '123L', + amount: 1, + accountInit: false, + account: { ...props.account, hwInfo: { deviceId: '123123' } }, + pendingTransactions: ['123'], + }; const store = fakeStore({ account }); - wrapper = mount(, { + wrapper = mount(, { context: { store, i18n }, childContextTypes: { store: PropTypes.object.isRequired, i18n: PropTypes.object.isRequired, }, }); - }); - - it('hardwareWallet account should show correct title "Confirm transaction on Ledger Nano S"', () => { expect(wrapper.find('.title').at(0)).to.have.text('Confirm transaction on Ledger Nano S'); }); }); From 60391ccfce10eb78726c67c9557f5e0ea82b67e4 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Mon, 10 Dec 2018 08:51:01 +0100 Subject: [PATCH 8/9] :recycle: Fix className in tests resultBox --- i18n/locales/en/common.json | 2 ++ src/components/resultBox/resultBox.test.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/i18n/locales/en/common.json b/i18n/locales/en/common.json index 8e39b28419..77e8fedeb8 100644 --- a/i18n/locales/en/common.json +++ b/i18n/locales/en/common.json @@ -63,6 +63,8 @@ "Confirm (Fee: 1 LSK)": "Confirm (Fee: 1 LSK)", "Confirm (Fee: {{fee}} LSK)": "Confirm (Fee: {{fee}} LSK)", "Confirm to register your second passphrase on the blockchain.": "Confirm to register your second passphrase on the blockchain.", + "Confirm transaction on Ledger Nano S": "Confirm transaction on Ledger Nano S", + "Confirm transfer": "Confirm transfer", "Confirm vote on Ledger Nano S": "Confirm vote on Ledger Nano S", "Confirm your name": "Confirm your name", "Confirmation in the next step": "Confirmation in the next step", diff --git a/src/components/resultBox/resultBox.test.js b/src/components/resultBox/resultBox.test.js index c2b495a46d..e039e532a5 100644 --- a/src/components/resultBox/resultBox.test.js +++ b/src/components/resultBox/resultBox.test.js @@ -158,7 +158,7 @@ describe('Result Box', () => { }; wrapper = mount(, options); - wrapper.find('.add-follwed-account-button').at(0).simulate('click'); + wrapper.find('.add-to-bookmarks').at(0).simulate('click'); expect(props.nextStep).to.have.been.calledWith({ address: 455 }); }); }); From 5caafca90bc471475005bde8c4cad03ce5484e51 Mon Sep 17 00:00:00 2001 From: michaeltomasik Date: Fri, 14 Dec 2018 01:46:58 +0100 Subject: [PATCH 9/9] :white_check_mark: Fix e2e tests for ResultBox --- src/components/resultBox/resultBox.js | 2 +- src/components/resultBox/resultBox.test.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/resultBox/resultBox.js b/src/components/resultBox/resultBox.js index a2baf1192f..ecfa163bbb 100644 --- a/src/components/resultBox/resultBox.js +++ b/src/components/resultBox/resultBox.js @@ -58,7 +58,7 @@ class ResultBox extends React.Component { {this.props.success && this.props.recipientId && this.isNotYetFollowed(this.props.recipientId) ?
-