This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
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 #560 from LiskHQ/540-second-passphrase-field
Create a React component for second passphrase field - Closes #540
- Loading branch information
Showing
9 changed files
with
164 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { connect } from 'react-redux'; | ||
import SecondPassphraseInput from './secondPassphraseInput'; | ||
|
||
const mapStateToProps = state => ({ | ||
hasSecondPassphrase: !!state.account.secondSignature, | ||
}); | ||
|
||
export default connect(mapStateToProps)(SecondPassphraseInput); | ||
|
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 chai, { expect } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import SecondPassphraseInputContainer from './index'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('SecondPassphraseInputContainer', () => { | ||
let wrapper; | ||
|
||
it('should render SecondPassphraseInput with props.hasSecondPassphrase if store.account.secondSignature is truthy', () => { | ||
const store = configureMockStore([])({ account: { secondSignature: 1 } }); | ||
wrapper = mount(<Provider store={store}> | ||
<SecondPassphraseInputContainer onError={ () => {} } /> | ||
</Provider>); | ||
expect(wrapper.find('SecondPassphraseInput')).to.have.lengthOf(1); | ||
expect(wrapper.find('SecondPassphraseInput').props().hasSecondPassphrase).to.equal(true); | ||
}); | ||
|
||
it('should render SecondPassphraseInput with !props.hasSecondPassphrase if store.account.secondSignature is falsy', () => { | ||
const store = configureMockStore([])({ account: { secondSignature: 0 } }); | ||
wrapper = mount(<Provider store={store}> | ||
<SecondPassphraseInputContainer onError={ () => {} } /> | ||
</Provider>); | ||
expect(wrapper.find('SecondPassphraseInput').props().hasSecondPassphrase).to.equal(false); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
src/components/secondPassphraseInput/secondPassphraseInput.js
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,37 @@ | ||
import React from 'react'; | ||
import Input from 'react-toolbox/lib/input'; | ||
import { isValidPassphrase } from '../../utils/passphrase'; | ||
|
||
class SecondPassphraseInput extends React.Component { | ||
componentDidMount() { | ||
if (this.props.hasSecondPassphrase) { | ||
this.props.onError(undefined, ''); | ||
} | ||
} | ||
|
||
handleValueChange(value) { | ||
this.props.onChange(value); | ||
let error; | ||
if (!value) { | ||
error = 'Required'; | ||
} else if (!isValidPassphrase(value)) { | ||
error = 'Invalid passphrase'; | ||
} | ||
if (error) { | ||
this.props.onError(error, value); | ||
} | ||
} | ||
|
||
render() { | ||
return (this.props.hasSecondPassphrase ? | ||
<Input label='Second Passphrase' required={true} | ||
className='second-passphrase' | ||
error={this.props.error} | ||
value={this.props.value} | ||
onChange={this.handleValueChange.bind(this)} /> : | ||
null); | ||
} | ||
} | ||
|
||
export default SecondPassphraseInput; | ||
|
38 changes: 38 additions & 0 deletions
38
src/components/secondPassphraseInput/secondPassphraseInput.test.js
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,38 @@ | ||
import React from 'react'; | ||
import chai, { expect } from 'chai'; | ||
import sinonChai from 'sinon-chai'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import SecondPassphraseInput from './secondPassphraseInput'; | ||
|
||
chai.use(sinonChai); | ||
|
||
describe('SecondPassphraseInput', () => { | ||
let wrapper; | ||
let props; | ||
|
||
beforeEach(() => { | ||
props = { | ||
onChange: sinon.spy(), | ||
onError: sinon.spy(), | ||
}; | ||
}); | ||
|
||
it('should render Input if props.hasSecondPassphrase', () => { | ||
props.hasSecondPassphrase = true; | ||
wrapper = mount(<SecondPassphraseInput {...props} />); | ||
expect(wrapper.find('Input')).to.have.lengthOf(1); | ||
}); | ||
|
||
it('should render null if !props.hasSecondPassphrase', () => { | ||
props.hasSecondPassphrase = false; | ||
wrapper = mount(<SecondPassphraseInput {...props} />); | ||
expect(wrapper.html()).to.equal(null); | ||
}); | ||
|
||
it('should render null if !props.hasSecondPassphrase', () => { | ||
props.hasSecondPassphrase = false; | ||
wrapper = mount(<SecondPassphraseInput {...props} />); | ||
expect(wrapper.html()).to.equal(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
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