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

Increase coverage on failing modules - Closes #561 #612

Merged
merged 13 commits into from
Mar 27, 2018
Merged
2 changes: 0 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ module.exports = function (config) {
excludes: [
'src/components/delegateSidebar/index.js',
'src/components/setting/index.js',
'src/components/setting/setting.js',
'src/components/menuBar/menuBar.js',
'src/components/accountVisual/demo.js',
'src/components/delegateList/votingHeader.js',
'src/components/dialog/index.js',
'src/components/app/index.js',
'src/components/transactions/transactionList.js',
'src/components/relativeLink/index.js',
Expand Down
67 changes: 54 additions & 13 deletions src/components/setting/setting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { mount } from 'enzyme';
import sinon from 'sinon';
import configureMockStore from 'redux-mock-store';
import PropTypes from 'prop-types';
import { MemoryRouter } from 'react-router-dom';
import Setting from './setting';
import accounts from '../../../test/constants/accounts';
import i18n from '../../i18n';


describe('Setting', () => {
const history = {
location: {
Expand Down Expand Up @@ -46,12 +45,25 @@ describe('Setting', () => {

const t = key => key;
let wrapper;
const settingsUpdated = sinon.spy();

let settingsUpdated;
let accountUpdated;

beforeEach(() => {
wrapper = mount(<MemoryRouter>
<Setting store={store} settingsUpdated={settingsUpdated} settings={settings} t={t}/>
</MemoryRouter>, options);
settingsUpdated = sinon.spy();
accountUpdated = sinon.spy();
const props = {
settingsUpdated,
accountUpdated,
settings,
t,
};

wrapper = mount(
<Setting
store={store}
{...props}/>, options);

clock = sinon.useFakeTimers({
toFake: ['setTimeout', 'clearTimeout', 'Date', 'setInterval'],
});
Expand All @@ -74,15 +86,45 @@ describe('Setting', () => {
expect(wrapper.find('#carouselNav li').at(1).props().className).to.be.include('activeSlide');
});

it.skip('should click on .autoLog update the setting', () => {
wrapper.find('.autoLog input').simulate('click');
clock.tick(100);
wrapper.find('.autoLog label').simulate('click');
it('should change advanceMode setting when clicking on checkbox', () => {
wrapper.find('.advancedMode').at(0).find('input').simulate('change', { target: { checked: false, value: false } });
clock.tick(300);
wrapper.update();
clock.tick(500);
const expectedCallToSettingsUpdated = {
advancedMode: !settings.advancedMode,
};
expect(settingsUpdated).to.have.been.calledWith(expectedCallToSettingsUpdated);
});

it('should change autolog setting when clicking on checkbox', () => {
wrapper.find('.autoLog').at(0).find('input').simulate('change', { target: { checked: false, value: false } });
clock.tick(300);
wrapper.update();
const expectedCallToSettingsUpdated = {
autoLog: !settings.autoLog,
};
expect(settingsUpdated).to.have.been.calledWith(expectedCallToSettingsUpdated);
});

expect(settingsUpdated).to.have.been.calledOnce();

it('should update expireTime when updating autolog', () => {
const accountToExpireTime = { ...account };
const settingsToExpireTime = { ...settings };
settingsToExpireTime.autoLog = false;
accountToExpireTime.passphrase = accounts.genesis.passphrase;
wrapper.setProps({ account: accountToExpireTime, settings: settingsToExpireTime });
wrapper.update();

wrapper.find('.autoLog').at(0).find('input').simulate('change', { target: { checked: true, value: true } });
clock.tick(300);
wrapper.update();

const timeNow = Date.now();
const expectedCallToAccountUpdated = {
expireTime: timeNow,
};
expect(accountUpdated.getCall(0).args[0].expireTime)
.to.be.greaterThan(expectedCallToAccountUpdated.expireTime);
});

// TODO: will be re-enabled when the functionality is re-enabled
Expand All @@ -103,4 +145,3 @@ describe('Setting', () => {
expect(i18n.language).to.be.equal('en');
});
});