Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1599 from LiskHQ/1428-add-hwWallet-unit-tests
Add hw wallet unit tests - Closes #1428
- Loading branch information
Showing
12 changed files
with
490 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { spy } from 'sinon'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import i18n from '../../i18n'; | ||
import ToolBoxInput from '../toolbox/inputs/toolBoxInput'; | ||
import AccountCard from './accountCard'; | ||
|
||
describe('AccountCard', () => { | ||
let wrapper; | ||
let props; | ||
|
||
beforeEach(() => { | ||
props = { | ||
account: { | ||
address: '123L', | ||
}, | ||
hardwareAccountName: 'test', | ||
isEditMode: true, | ||
changeInput: spy(), | ||
onClickHandler: spy(), | ||
index: 0, | ||
}; | ||
|
||
wrapper = mount(<AccountCard {...props} />, { | ||
context: { i18n }, | ||
childContextTypes: { | ||
i18n: PropTypes.object.isRequired, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should find ToolBoxInput when isEditMode true', () => { | ||
expect(wrapper.find(ToolBoxInput).exists()).to.equal(true); | ||
}); | ||
|
||
it('should call changeInput when changing text in ToolBoxInput', () => { | ||
wrapper.find(ToolBoxInput).props().onChange('test'); | ||
expect(props.changeInput).to.have.been.calledWith('test', '123L'); | ||
}); | ||
|
||
it('should call onClickHandler on click accountVisualWrapper', () => { | ||
const newProps = { | ||
...props, | ||
isEditMode: false, | ||
}; | ||
|
||
wrapper = mount(<AccountCard {...newProps} />, { | ||
context: { i18n }, | ||
childContextTypes: { | ||
i18n: PropTypes.object.isRequired, | ||
}, | ||
}); | ||
wrapper.find('.accountVisualWrapper').simulate('click'); | ||
expect(props.onClickHandler).to.have.been.calledWith({ address: '123L' }, 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { spy } from 'sinon'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import i18n from '../../i18n'; | ||
import AddAccountCard from './addAccountCard'; | ||
|
||
describe('AddAccountCard', () => { | ||
let wrapper; | ||
let props; | ||
|
||
it('should call addAccount on click addAccountCard', () => { | ||
props = { | ||
t: spy(), | ||
addAccount: spy(), | ||
}; | ||
|
||
wrapper = mount(<AddAccountCard {...props} />, { | ||
context: { i18n }, | ||
childContextTypes: { | ||
i18n: PropTypes.object.isRequired, | ||
}, | ||
}); | ||
|
||
wrapper.find(AddAccountCard).simulate('click'); | ||
expect(props.addAccount).to.have.been.calledWith(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from 'react'; | ||
import to from 'await-to-js'; | ||
import Box from '../box'; | ||
|
||
import UnlockWallet from './unlockWallet'; | ||
import LedgerLogin from './ledgerLoginHOC'; | ||
import getNetwork from '../../utils/getNetwork'; | ||
import { getAccountFromLedgerIndex } from '../../utils/ledger'; | ||
import Piwik from '../../utils/piwik'; | ||
|
||
import { loginType } from '../../constants/hwConstants'; | ||
import routes from '../../constants/routes'; | ||
|
||
import styles from './unlockWallet.css'; | ||
|
||
class HwWallet extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
isLedgerLogin: true, | ||
}; | ||
} | ||
|
||
async componentDidMount() { | ||
this.ledgerLogin(); | ||
} | ||
|
||
handleOnClick() { | ||
Piwik.trackingEvent('HwWallet', 'button', 'Continue'); | ||
this.ledgerLogin(); | ||
} | ||
|
||
cancelLedgerLogin() { | ||
Piwik.trackingEvent('HwWallet', 'button', 'Cancel Ledger'); | ||
this.props.history.push(`${routes.loginV2.path}`); | ||
} | ||
|
||
async ledgerLogin() { // eslint-disable-line max-statements | ||
this.props.loadingStarted('ledgerLogin'); | ||
|
||
const finishTimeout = setTimeout(() => { | ||
this.setState({ isLedgerLogin: false }); | ||
this.props.loadingFinished('ledgerLogin'); | ||
}, 6000); | ||
let error; | ||
let ledgerAccount; | ||
// eslint-disable-next-line prefer-const | ||
[error, ledgerAccount] = await to(getAccountFromLedgerIndex()); // by default index 0 | ||
if (!error) { | ||
const network = Object.assign({}, getNetwork(this.props.network)); | ||
/* istanbul ignore else */ | ||
if (ledgerAccount.publicKey) { | ||
clearTimeout(finishTimeout); | ||
this.props.loadingFinished('ledgerLogin'); | ||
this.setState({ isLedgerLogin: true, isLedgerFirstLogin: true }); | ||
} | ||
|
||
// set active peer | ||
this.props.liskAPIClientSet({ | ||
publicKey: ledgerAccount.publicKey, | ||
loginType: loginType.ledger, | ||
network, | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
if (this.state.isLedgerLogin) { | ||
return ( | ||
<Box> | ||
<LedgerLogin | ||
loginType={loginType.normal} | ||
network={getNetwork(this.props.network)} | ||
cancelLedgerLogin={this.cancelLedgerLogin.bind(this)} /> | ||
</Box>); | ||
} | ||
|
||
return ( | ||
<Box className={styles.unlockWallet}> | ||
<UnlockWallet | ||
handleOnClick={this.handleOnClick.bind(this)} | ||
cancelLedgerLogin={this.cancelLedgerLogin.bind(this)} /> | ||
</Box>); | ||
} | ||
} | ||
|
||
export default HwWallet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.