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

Show/Hide network options depending on url params - Closes #47 #81

Merged
merged 3 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
49 changes: 30 additions & 19 deletions src/components/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import styles from './login.css';
import env from '../../constants/env';
import networks from '../../constants/networks';
import getNetwork from '../../utils/getNetwork';
import { parseSearchParams } from './../../utils/searchParams';
import LanguageDropdown from '../languageDropdown';
import RelativeLink from '../relativeLink';
// eslint-disable-next-line import/no-unresolved
import * as shapes from '../../assets/images/*.svg';
import { validateUrl, getLoginData } from '../../utils/login';
import { parseSearchParams } from '../../utils/searchParams';

/**
* The container component containing login
Expand Down Expand Up @@ -159,6 +159,12 @@ class Login extends React.Component {
});
}

// eslint-disable-next-line class-methods-use-this
showNetworkOptions() {
const params = parseSearchParams(this.props.history.location.search);
return params.showNetwork === 'true';
}

render() {
return (
<div className={`box ${styles.wrapper}`}>
Expand All @@ -174,24 +180,29 @@ class Login extends React.Component {
<h2>{this.props.t('Sign In')}</h2>
<form onSubmit={this.onFormSubmit.bind(this)}>
<LanguageDropdown className={styles.outTaken} />
<Dropdown
auto={false}
source={this.networks}
onChange={this.changeHandler.bind(this, 'network')}
label={this.props.t('Select a network')}
value={this.state.network}
className={`${styles.network} network ${styles.outTaken}`}
/>
{
this.state.network === networks.customNode.code &&
<Input type='text'
label={this.props.t('Node address')}
name='address'
className={`address ${styles.outTaken}`}
theme={styles}
value={this.state.address}
error={this.state.addressValidity}
onChange={this.changeHandler.bind(this, 'address')} />
{this.showNetworkOptions()
? <div className={styles.outTaken}>
<Dropdown
auto={false}
source={this.networks}
onChange={this.changeHandler.bind(this, 'network')}
label={this.props.t('Select a network')}
value={this.state.network}
className='network'
/>
{
this.state.network === networks.customNode.code &&
<Input type='text'
label={this.props.t('Node address')}
name='address'
className={`address ${styles.outTaken}`}
theme={styles}
value={this.state.address}
error={this.state.addressValidity}
onChange={this.changeHandler.bind(this, 'address')}/>
}
</div>
: ''
}
<PassphraseInput label={this.props.t('Enter your passphrase')}
className='passphrase'
Expand Down
18 changes: 18 additions & 0 deletions src/components/login/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,27 @@ describe('Login', () => {
expect(props.history.replace).to.have.been.calledWith('/main/transactions');
});

it('hides network options by default', () => {
wrapper = shallow(<Login {...props}/>, options);
props.history.replace.reset();
wrapper.setProps({ history });
expect(wrapper.find('.network')).to.have.length(0);
});

it('shows network options when url param showNetwork is true', () => {
wrapper = shallow(<Login {...props}/>, options);
props.history.replace.reset();
history.location.search = '?showNetwork=true';
wrapper.setProps({ history });
expect(wrapper.find('.network')).to.have.length(1);
});

it('calls localStorage.setItem(\'address\', address) if this.state.address', () => {
const spyFn = spy(localStorage, 'setItem');
wrapper = mount(<Router><Login {...props}/></Router>, options);
// enable the network dropdown
history.location.search = '?showNetwork=true';
wrapper.setProps({ history });
// set the network dropdown
wrapper.find('div.network').simulate('click');
// select custom node
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/step_definitions/login.step.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { defineSupportCode } = require('cucumber');

defineSupportCode(({ Given }) => {
Given('I\'m on login page', (callback) => {
browser.get(browser.params.baseURL).then(callback);
browser.get(`${browser.params.baseURL}#/?showNetwork=true`).then(callback);
});
});