Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test coverage of send transactions with HW wallet - Closes #1515 #1544

Merged
merged 13 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -56,12 +55,10 @@ module.exports = {
'src/components/newsFeed/news.js',
'src/components/passphrase/create/create.js',
'src/components/passphraseCreation/index.js',
'src/components/passphraseSteps/index.js', // FollowUp #1515
'src/components/passphraseSteps/index.js',
'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',
'src/components/spinner/stories.js',
'src/components/toaster/stories.js',
Expand All @@ -82,10 +79,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
'src/components/sendNew/',
],
coverageThreshold: {
Expand Down
3 changes: 2 additions & 1 deletion src/actions/peers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 : {},
};
Expand Down
17 changes: 17 additions & 0 deletions src/actions/peers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});
slaweet marked this conversation as resolved.
Show resolved Hide resolved

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);

Expand Down
13 changes: 12 additions & 1 deletion src/components/resultBox/resultBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ class ResultBox extends React.Component {
return this.props.followedAccounts.find(account => account.address === address) === undefined;
}

handleRetryButton() {
slaweet marked this conversation as resolved.
Show resolved Hide resolved
this.props.transactionFailedClear();
this.props.prevStep({
success: null,
account: this.props.account,
recipient: this.props.recipient,
amount: this.props.amount,
password: { value: '' },
});
}

render() {
return (
<div className={`${styles.resultBox}`}>
Expand Down Expand Up @@ -55,7 +66,7 @@ class ResultBox extends React.Component {
</Button> : null
}
{!this.props.success && this.props.account && this.props.account.hwInfo ?
<Button className={`add-follwed-account-button ${styles.addFollowedAccountButton}`}
<Button className={`add-to-bookmarks ${styles.addFollowedAccountButton}`}
onClick={() => {
this.props.transactionFailedClear();
this.props.prevStep({
Expand Down
44 changes: 43 additions & 1 deletion src/components/resultBox/resultBox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,48 @@ describe('Result Box', () => {

wrapper = mount(<ResultBox {...props} />, options);

expect(wrapper).to.have.descendants('.add-follwed-account-button');
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(<ResultBox {...props} />, 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(<ResultBox {...props} />, options);
slaweet marked this conversation as resolved.
Show resolved Hide resolved

wrapper.find('.add-follwed-account-button').at(0).simulate('click');
expect(props.nextStep).to.have.been.calledWith({ address: 455 });
});
});
2 changes: 1 addition & 1 deletion src/components/send/steps/confirm/confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Confirm extends React.Component {
<div className={`${styles.wrapper} send`}>
<div className={styles.header}>
<header className={styles.headerWrapper}>
<h2>{title}</h2>
<h2 className='title'>{title}</h2>
</header>
</div>
{this.props.accountInit
Expand Down
24 changes: 24 additions & 0 deletions src/components/send/steps/confirm/confirm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
slaweet marked this conversation as resolved.
Show resolved Hide resolved

const store = fakeStore({ account });

wrapper = mount(<Confirm {...props} />, {
context: { store, i18n },
childContextTypes: {
store: PropTypes.object.isRequired,
i18n: PropTypes.object.isRequired,
},
});
});
slaweet marked this conversation as resolved.
Show resolved Hide resolved

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');
});
});
});