Skip to content

Commit

Permalink
Merge pull request #570 from LiskHQ/535-increase-test-coverage
Browse files Browse the repository at this point in the history
Increase test coverage - Closes #535
  • Loading branch information
michaeltomasik committed Mar 26, 2018
2 parents 8c0290d + 5a06ca8 commit 6617db1
Show file tree
Hide file tree
Showing 27 changed files with 219 additions and 1,046 deletions.
10 changes: 2 additions & 8 deletions i18n/locales/en/common.json
Expand Up @@ -6,7 +6,6 @@
"Activity": "Activity",
"Add": "Add",
"Add a Lisk ID": "Add a Lisk ID",
"Add vote to": "Add vote to",
"Additional fee": "Additional fee",
"Address": "Address",
"Address timeout in": "Address timeout in",
Expand Down Expand Up @@ -120,7 +119,6 @@
"Next": "Next",
"No Updates": "No Updates",
"No activity yet": "No activity yet",
"No matches": "No matches",
"No results": "No results",
"Node address": "Node address",
"Not enough LSK": "Not enough LSK",
Expand Down Expand Up @@ -153,15 +151,15 @@
"Redo": "Redo",
"Register": "Register",
"Register 2nd passphrase": "Register 2nd passphrase",
"Register Second Passphrase": "Register Second Passphrase",
"Register as delegate": "Register as delegate",
"Reload": "Reload",
"Remove": "Remove",
"Remove vote from": "Remove vote from",
"Report Issue...": "Report Issue...",
"Required": "Required",
"Restart now": "Restart now",
"Safekeeping": "Safekeeping",
"Search": "Search",
"Search by username": "Search by username",
"Search for Lisk ID or Transaction ID": "Search for Lisk ID or Transaction ID",
"Search for a delegate": "Search for a delegate",
"Second Signature Creation": "Second Signature Creation",
Expand Down Expand Up @@ -231,10 +229,6 @@
"You are looking into a saved account. In order to {{nextAction}} you need to enter your passphrase.": "You are looking into a saved account. In order to {{nextAction}} you need to enter your passphrase.",
"You can also press ↲ enter to search": "You can also press ↲ enter to search",
"You can always get it back.": "You can always get it back.",
"You can select up to {{count}} delegates in one voting turn.": "You can select up to {{count}} delegates in one voting turn.",
"You can select up to {{count}} delegates in one voting turn._plural": "You can select up to {{count}} delegates in one voting turn.",
"You can vote for up to {{count}} delegates in total.": "You can vote for up to {{count}} delegates in total.",
"You can vote for up to {{count}} delegates in total._plural": "You can vote for up to {{count}} delegates in total.",
"You have already registered as a delegate.": "You have already registered as a delegate.",
"You only need to do this once for each Lisk ID.": "You only need to do this once for each Lisk ID.",
"You will need it to use your Lisk ID, like sending and voting. You are responsible for keeping your second passphrase safe. No one can restore it, not even Lisk.": "You will need it to use your Lisk ID, like sending and voting. You are responsible for keeping your second passphrase safe. No one can restore it, not even Lisk.",
Expand Down
12 changes: 2 additions & 10 deletions karma.conf.js
Expand Up @@ -77,18 +77,10 @@ module.exports = function (config) {
'src/components/secondPassphrase/secondPassphrase.js',
'src/components/toolbox/sliderCheckbox/index.js',
'src/components/toolbox/transitionWrapper/index.js',
'src/components/searchBar/index.js',
'src/components/sendWritable/index.js',
'src/components/signMessage/index.js',
'src/components/signMessage/index.js',
'src/components/voteDialog/index.js',
'src/components/sidechains/index.js',
'src/components/header/header.js',
'src/components/login/index.js',
'src/components/login/login.js',
'src/components/register/index.js',
'src/components/searchBar/index.js',
'src/components/register/register.js',
'src/components/transactions/transactionOverview.js',
'src/components/voteUrlProcessor/index.js',
],
overrides: {
'src/store/**/*.js': {
Expand Down
25 changes: 25 additions & 0 deletions src/components/dialog/dialogs.js
@@ -0,0 +1,25 @@
import i18next from 'i18next';
import RegisterDelegate from '../registerDelegate';
import SavedAccounts from '../savedAccounts';
import savedAccountsTheme from '../savedAccounts/modalTheme.css';
import SecondPassphrase from '../secondPassphrase';
import Send from '../sendWritable';

export default () => ({
send: {
title: i18next.t('Send'),
component: Send,
},
'register-delegate': {
title: i18next.t('Register as delegate'),
component: RegisterDelegate,
},
'register-second-passphrase': {
title: i18next.t('Register Second Passphrase'),
component: SecondPassphrase,
},
'saved-accounts': {
component: SavedAccounts,
theme: savedAccountsTheme,
},
});
14 changes: 7 additions & 7 deletions src/components/header/header.js
Expand Up @@ -86,13 +86,13 @@ class Header extends React.Component {
</div>
</div>
</PrivateWrapper>
{this.shouldShowActionButton() && <Link className={styles.login}
to='/'>
<ActionButton className={styles.button}>{this.props.t('Sign in')}</ActionButton>
<span className={styles.link}>
{this.props.t('Sign in')} <FontIcon value='arrow-right'/>
</span>
</Link>
{ this.shouldShowActionButton() &&
<Link className={styles.login} to='/'>
<ActionButton className={styles.button}>{this.props.t('Sign in')}</ActionButton>
<span className={styles.link}>
{this.props.t('Sign in')} <FontIcon value='arrow-right'/>
</span>
</Link>
}
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/components/login/index.test.js
@@ -1,11 +1,13 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import { MemoryRouter } from 'react-router-dom';
import configureMockStore from 'redux-mock-store';
import PropTypes from 'prop-types';
import i18n from '../../i18n';
import LoginHOC from './index';
import * as savedAccounts from '../../actions/savedAccounts';

describe('LoginHOC', () => {
// Mocking store
Expand Down Expand Up @@ -66,4 +68,11 @@ describe('LoginHOC', () => {
expect(props.account).to.be.equal(account);
expect(typeof props.activePeerSet).to.be.equal('function');
});

it('should bind activeAccountSaved action to Login props.activeAccountSaved', () => {
const actionsSpy = sinon.spy(savedAccounts, 'activeAccountSaved');
wrapper.find('Login').props().activeAccountSaved();
expect(actionsSpy).to.be.calledWith();
actionsSpy.restore();
});
});
3 changes: 1 addition & 2 deletions src/components/register/index.test.js
Expand Up @@ -8,7 +8,6 @@ import configureMockStore from 'redux-mock-store';
import i18n from '../../i18n';
import Register from './index';


describe('RegisterHOC', () => {
let wrapper;
const peers = {};
Expand All @@ -29,6 +28,6 @@ describe('RegisterHOC', () => {
});

it('should render Register', () => {
expect(wrapper.find('Register')).to.have.lengthOf(1);
expect(wrapper).to.have.descendants('Register');
});
});
12 changes: 12 additions & 0 deletions src/components/register/register.test.js
Expand Up @@ -66,4 +66,16 @@ describe('Register', () => {
passphrase,
}));
});

it('should return to Login page when prevPage in MultiStep is executed', () => {
expect(wrapper.find('Register').props().history.location.pathname).to.not.be.equal('/');
wrapper.find('MultiStep').props().prevPage();
expect(wrapper.find('Register').props().history.location.pathname).to.be.equal('/');
});

it('should remove "contentFocused" class in unMount', () => {
expect(document.getElementsByClassName('contentFocused')).to.have.length(1);
wrapper.unmount();
expect(document.getElementsByClassName('contentFocused')).to.have.length(0);
});
});
19 changes: 19 additions & 0 deletions src/components/savedAccounts/modalTheme.css
@@ -0,0 +1,19 @@
.dialog.fullscreen {
width: 100vw; /* stylelint-disable-line */
height: 100vh; /* stylelint-disable-line */
max-width: 100vw; /* stylelint-disable-line */
max-height: 100vh; /* stylelint-disable-line */
border-radius: 0;
background: #013165;
}

.innerBody {
padding: 24px;
max-height: auto;
}

@media screen and (min-width: 600px) {
.innerBody {
max-height: auto;
}
}
94 changes: 94 additions & 0 deletions src/components/searchBar/index.test.js
@@ -0,0 +1,94 @@
/* eslint-disable */
import React from 'react';
// import { expect } from 'chai';
import { mount } from 'enzyme';
import { stub, spy } from 'sinon';
import { Provider } from 'react-redux';
import { HashRouter as Router } from 'react-router-dom';
import PropTypes from 'prop-types';

import i18n from '../../i18n';
import Search from './index';

describe('SearchBar', () => {
// let wrapper;
let history;
let props;
let options;
let localStorageStub;
const store = {};
const peers = {
data: {},
status: true,
};

// Mocking store
beforeEach(() => {
localStorageStub = stub(localStorage, 'getItem');
localStorageStub.withArgs('searches').returns([]);

history = {
location: {
pathname: 'explorer',
search: '',
},
push: spy(),
};
props = {
history,
t: () => {},
};
options = {
context: {
store: {}, history, i18n, router: { route: history, history },
},
childContextTypes: {
store: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
i18n: PropTypes.object.isRequired,
router: PropTypes.object.isRequired,
},
lifecycleExperimental: true,
};
store.getState = () => ({
peers,
});
store.subscribe = () => {};
store.dispatch = () => {};
// wrapper = mount(
// <Provider store={store}>
// <Router>
// <Search {...props} />
// </Router>
// </Provider>, options,
// );
});

afterEach(() => {
localStorageStub.restore();
});

// it('should call getSearchItem on componentWillReceiveProps', () => {
// wrapper.find('Search').props().history.push('/explorer/');
// wrapper.update();
// expect(wrapper.find('Search input').props().value).to.equal('');
// wrapper.find('Search').props().history.push('/explorer/transaciton/123');
// wrapper.update();
// expect(wrapper.find('Search input')).to.have.props({ value: '123' });
// });

// it('should change input value on change event', () => {
// wrapper.find('Search input').simulate('change', { target: { value: '12025' } });
// expect(wrapper.find('Search input')).to.have.props({ value: '12025' });
// });

// it('should change value on keyup event', () => {
// wrapper.find('Search input').simulate('keyup', { which: 13, target: { value: '999' } });
// expect(wrapper.find('Search input')).to.have.props({ value: '999' });
// });

// it('should render Search', () => {
// expect(wrapper).to.have.descendants('.search-bar-input');
// });
});

7 changes: 1 addition & 6 deletions src/components/sendWritable/index.js
@@ -1,7 +1,6 @@
import { connect } from 'react-redux';
import { translate } from 'react-i18next';

import { sent } from '../../actions/account';
import Send from './send';

const mapStateToProps = state => ({
Expand All @@ -10,8 +9,4 @@ const mapStateToProps = state => ({
pendingTransactions: state.transactions.pending,
});

const mapDispatchToProps = dispatch => ({
sent: data => dispatch(sent(data)),
});

export default connect(mapStateToProps, mapDispatchToProps)(translate()(Send));
export default connect(mapStateToProps)(translate()(Send));
7 changes: 0 additions & 7 deletions src/components/sendWritable/index.test.js
Expand Up @@ -29,11 +29,4 @@ describe('SendWritableHOC', () => {
it('should render Send', () => {
expect(wrapper.find('SendWritable')).to.have.lengthOf(1);
});

it('should mount Send with appropriate properties', () => {
const props = wrapper.find('SendWritable').props();
expect(props.activePeer).to.be.equal(peers.data);
expect(props.account).to.be.equal(account);
expect(typeof props.sent).to.be.equal('function');
});
});
2 changes: 0 additions & 2 deletions src/components/sendWritable/send.test.js
@@ -1,7 +1,6 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import sinon from 'sinon';
import configureStore from 'redux-mock-store';
import PropTypes from 'prop-types';
import accounts from '../../../test/constants/accounts';
Expand All @@ -26,7 +25,6 @@ describe('Send Writable Component', () => {
account,
pendingTransactions: [],
closeDialog: () => {},
sent: sinon.spy(),
t: key => key,
nextStep: () => {},
history: { location: { search: '' } },
Expand Down
3 changes: 1 addition & 2 deletions src/components/sidechains/index.js
@@ -1,5 +1,4 @@
import React from 'react';
import { withRouter } from 'react-router';
import { translate } from 'react-i18next';
import { FontIcon } from '../fontIcon';
import Box from '../box';
Expand Down Expand Up @@ -33,5 +32,5 @@ class Sidechains extends React.Component {
}
}

export default withRouter(translate()(Sidechains));
export default translate()(Sidechains);

27 changes: 27 additions & 0 deletions src/components/sidechains/index.test.js
@@ -0,0 +1,27 @@
import React from 'react';
import { expect } from 'chai';
import { mount } from 'enzyme';
import PropTypes from 'prop-types';
import configureMockStore from 'redux-mock-store';

import i18n from '../../i18n';
import Sidechains from './index';

describe('Sidechains', () => {
const store = configureMockStore([])({});
const options = {
context: { store, i18n },
childContextTypes: {
store: PropTypes.object.isRequired,
i18n: PropTypes.object.isRequired,
},
};

it('should render "Coming soon" in h2', () => {
const props = {
t: () => {},
};
const wrapper = mount(<Sidechains {...props} />, options);
expect(wrapper.find('h2')).to.have.text('Coming soon.');
});
});
18 changes: 18 additions & 0 deletions src/components/transactions/transactionOverview.test.js
@@ -0,0 +1,18 @@
import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import TransactionOverview from './transactionOverview';

describe('TransactionOverview', () => {
it('should render Waypoint on smallScreen', () => {
window.innerWidth = 200;
const props = {
t: () => {},
loading: [],
transactions: [],
peers: {},
};
const wrapper = shallow(<TransactionOverview {...props} />);
expect(wrapper).to.have.descendants('Waypoint');
});
});

0 comments on commit 6617db1

Please sign in to comment.