Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina Contrino committed Oct 24, 2017
1 parent 1e9e800 commit d9f720d
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/utils/ipcLocale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,45 @@ describe('ipcLocale', () => {
const i18n = {
changeLanguage: spy(),
on: spy(),
language: '',
};

describe('init', () => {
beforeEach(() => {
delete window.ipc;
});
it('calling init when ipc is not on window should do nothing', () => {
ipcLocale.init();

it('calling init when ipc is not on window does not call ipc', () => {
ipcLocale.init(i18n);
expect(ipc.on).to.not.have.been.calledWith();
expect(ipc.send).to.not.have.been.calledWith();
});

it('calling init when ipc is not on window saves locale in browser when there is no locale in i18n', () => {
window.localStorage.getItem = () => 'en';

ipcLocale.init(i18n);
expect(ipc.on).to.not.have.been.calledWith();
expect(ipc.send).to.not.have.been.calledWith();

expect(i18n.changeLanguage).to.have.been.calledWith('en');
});

it('calling init when ipc is not on window saves locale in browser when there is no locale in localStorage', () => {
window.localStorage.getItem = () => '';
i18n.language = 'de';

ipcLocale.init(i18n);
expect(i18n.changeLanguage).to.have.been.calledWith('de');
});

it('calling init when ipc is not on window saves locale in browser when there is no locale saved at all', () => {
window.localStorage.getItem = () => '';

ipcLocale.init(i18n);
expect(i18n.changeLanguage).to.have.been.calledWith('en');
});

it('should be a function', () => {
expect(typeof ipcLocale.init).to.be.equal('function');
});
Expand All @@ -33,5 +60,13 @@ describe('ipcLocale', () => {
expect(ipc.on).to.have.been.calledWith();
expect(i18n.on).to.have.been.calledWith();
});

it('calling init when ipc is available and there is no locale in i18n will make a request for locale ', () => {
window.ipc = ipc;
i18n.language = '';

ipcLocale.init(i18n);
expect(ipc.send).to.have.been.calledWith('request-locale');
});
});
});

0 comments on commit d9f720d

Please sign in to comment.