Skip to content

Commit

Permalink
Merge pull request #612 from LiskHQ/561-coverage-on-failing-modules
Browse files Browse the repository at this point in the history
Increase coverage on failing modules - Closes #561
  • Loading branch information
faival authored Mar 27, 2018
2 parents 5342d1e + dfe045d commit 45e4ca9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
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');
});
});

0 comments on commit 45e4ca9

Please sign in to comment.