-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add hw wallet unit tests - Closes #1428 #1599
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
28df5cc
:recycle: Move hwWallet HOC to seperate file
michaeltomasik 6994a8f
:white_check_mark: Add tests for hwWallet unit
michaeltomasik 2ff1de8
Merge branch '1.9.0' into 1428-add-hwWallet-unit-tests
michaeltomasik ad643da
:white_check_mark: Add more tests for hardware wallet
michaeltomasik 655014e
:white_check_mark: Finish ledger tests
michaeltomasik 0c2e33a
Merge branch '1.10.0' into 1428-add-hwWallet-unit-tests
michaeltomasik 1a230a8
refactor hwWallet tests
michaeltomasik File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ const AccountCard = ({ | |
onClick={() => { | ||
onClickHandler(account, index); | ||
}}> | ||
<div className={styles.accountVisualWrapper}> | ||
<div className={`${styles.accountVisualWrapper} accountVisualWrapper`}> | ||
<AccountVisual | ||
address={account.address} | ||
size={100} sizeS={60} | ||
|
@@ -27,14 +27,18 @@ const AccountCard = ({ | |
{fromRawLsk(account.balance)}<p>LSK</p> | ||
</div> | ||
{isEditMode ? | ||
<div className={styles.edit} onClick={(e) => { | ||
<div | ||
className={styles.edit} | ||
onClick={/* istanbul ignore next */(e) => { | ||
e.stopPropagation(); | ||
}}> | ||
<ToolBoxInput | ||
placeholder={'Title'} | ||
onChange={value => changeInput(value, account.address)} | ||
theme={styles} | ||
onKeyDown={ (event) => { if (event.keyCode === keyCodes.enter) saveAccountNames(); }} | ||
onKeyDown={/* istanbul ignore next */(event) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
if (event.keyCode === keyCodes.enter) saveAccountNames(); | ||
}} | ||
value={hardwareAccountName}></ToolBoxInput> | ||
</div> : | ||
null} | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaeltomasik do you think you could put the message outside the code, I mean like
Maybe that works too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried and it needs to be there so it does not lower test coverage