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 #784 from LiskHQ/783-relative-lisnk-e2e-test
Stabilise RelativeLink e2e tests - Closes #783
- Loading branch information
Showing
10 changed files
with
226 additions
and
48 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
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,15 @@ | ||
import { connect } from 'react-redux'; | ||
import { translate } from 'react-i18next'; | ||
import { dialogDisplayed } from '../../actions/dialog'; | ||
import { activePeerSet } from '../../actions/peers'; | ||
import Register from './register'; | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
setActiveDialog: data => dispatch(dialogDisplayed(data)), | ||
activePeerSet: data => dispatch(activePeerSet(data)), | ||
}); | ||
|
||
export default connect( | ||
null, | ||
mapDispatchToProps, | ||
)(translate()(Register)); |
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,31 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import i18n from '../../i18n'; | ||
import Register from './index'; | ||
|
||
|
||
describe('RegisterHOC', () => { | ||
let wrapper; | ||
const peers = {}; | ||
const account = {}; | ||
const store = configureMockStore([])({ | ||
peers, | ||
account, | ||
}); | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<Provider store={store}> | ||
<I18nextProvider i18n={ i18n }> | ||
<Register /> | ||
</I18nextProvider> | ||
</Provider>); | ||
}); | ||
|
||
it('should render Register', () => { | ||
expect(wrapper.find('Register')).to.have.lengthOf(1); | ||
}); | ||
}); |
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,3 @@ | ||
.hidden { | ||
display: none; | ||
} |
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,60 @@ | ||
import React from 'react'; | ||
import Passphrase from '../passphrase'; | ||
import networksRaw from '../login/networks'; | ||
|
||
const Register = ({ | ||
activePeerSet, closeDialog, t, | ||
}) => { | ||
const validateUrl = (value) => { | ||
const addHttp = (url) => { | ||
const reg = /^(?:f|ht)tps?:\/\//i; | ||
return reg.test(url) ? url : `http://${url}`; | ||
}; | ||
|
||
const errorMessage = 'URL is invalid'; | ||
|
||
const isValidLocalhost = url => url.hostname === 'localhost' && url.port.length > 1; | ||
const isValidRemote = url => /(([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})/.test(url.hostname); | ||
|
||
let addressValidity = ''; | ||
try { | ||
const url = new URL(addHttp(value)); | ||
addressValidity = url && (isValidRemote(url) || isValidLocalhost(url)) ? '' : errorMessage; | ||
} catch (e) { | ||
addressValidity = errorMessage; | ||
} | ||
|
||
return addressValidity === ''; | ||
}; | ||
|
||
const onLoginSubmission = (passphrase) => { | ||
let NetworkIndex = parseInt(localStorage.getItem('network'), 10) || 0; | ||
const address = localStorage.getItem('address') || ''; | ||
if (!NetworkIndex || (NetworkIndex === 2 && !validateUrl(address))) { | ||
NetworkIndex = 0; | ||
} | ||
|
||
const network = Object.assign({}, networksRaw[NetworkIndex]); | ||
if (NetworkIndex === 2) { | ||
network.address = address; | ||
} | ||
|
||
// set active peer | ||
activePeerSet({ | ||
passphrase, | ||
network, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Passphrase | ||
onPassGenerated={onLoginSubmission} | ||
keepModal={false} | ||
closeDialog={closeDialog} | ||
confirmButton={'Login'} | ||
useCaseNote={t('your passphrase will be required for logging in to your account.')} | ||
securityNote={t('This passphrase is not recoverable and if you lose it, you will lose access to your account forever.')}/> | ||
); | ||
}; | ||
|
||
export default Register; |
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,56 @@ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount } from 'enzyme'; | ||
import { spy } from 'sinon'; | ||
import PropTypes from 'prop-types'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import Register from './register'; | ||
|
||
describe('Register', () => { | ||
let wrapper; | ||
const peers = { data: {} }; | ||
const account = {}; | ||
const store = configureMockStore([])({ | ||
peers, | ||
account, | ||
activePeerSet: () => {}, | ||
}); | ||
const options = { | ||
context: { store }, | ||
childContextTypes: { | ||
store: PropTypes.object.isRequired, | ||
}, | ||
}; | ||
const prop = { | ||
account, | ||
peers, | ||
activePeerSet: spy(), | ||
t: key => key, | ||
}; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<Register {...prop} />, options); | ||
}); | ||
|
||
it('renders Passphrase component', () => { | ||
expect(wrapper.find('Passphrase')).to.have.length(1); | ||
}); | ||
|
||
it('should mount Register with appropriate properties', () => { | ||
const props = wrapper.find('Passphrase').props(); | ||
expect(props.useCaseNote).to.be.equal('your passphrase will be required for logging in to your account.'); | ||
expect(props.securityNote).to.be.equal('This passphrase is not recoverable and if you lose it, you will lose access to your account forever.'); | ||
expect(props.confirmButton).to.be.equal('Login'); | ||
expect(props.keepModal).to.be.equal(false); | ||
expect(typeof props.onPassGenerated).to.be.equal('function'); | ||
}); | ||
|
||
it('should call activePeerSet if props.onPassGenerated is called', () => { | ||
const props = wrapper.find('Passphrase').props(); | ||
props.onPassGenerated('sample passphrase'); | ||
expect(prop.activePeerSet).to.have.been.calledWith({ | ||
network: { name: 'Mainnet', port: 443, ssl: true }, | ||
passphrase: 'sample passphrase', | ||
}); | ||
}); | ||
}); |