Skip to content

Commit

Permalink
Enhance autoUpdater.test.js and test descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gina Contrino committed Feb 26, 2018
1 parent 4cb3a70 commit 0deadf4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
1 change: 0 additions & 1 deletion app/src/modules/autoUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default ({ autoUpdater, dialog, win, process }) => {
console.error('There was a problem updating the application');
// eslint-disable-next-line no-console
console.error(error);
// eslint-disable-next-line max-len
if (updater.error !== error) {
updater.error = error;
dialog.showErrorBox('Error: ', error == null ? 'unknown' : error.toString());
Expand Down
41 changes: 28 additions & 13 deletions app/src/modules/autoUpdater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,33 @@ describe('autoUpdater', () => {
expect(params.autoUpdater.checkForUpdates).to.have.been.calledWithExactly();
});

it('should call params.autoUpdater.checkForUpdates every 24 hours', () => {
it('should check for updates every 24 hours if platform is not linux', () => {
autoUpdater(params);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(1);
clock.tick(24 * 60 * 60 * 1000);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(2);
clock.tick(24 * 60 * 60 * 1000);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(3);

params.autoUpdater.checkForUpdates.reset();
params.process.platform = 'linux';
autoUpdater(params);
expect(params.autoUpdater.checkForUpdates).to.have.callCount(0);
});

it('should call params.autoUpdater.on with "update-downloaded" and "error"', () => {
it('should show error box when there was an error', () => {
autoUpdater(params);
expect(callbacks['update-downloaded']).to.be.a('function');
expect(callbacks.error).to.be.a('function');
callbacks.error(undefined);
expect(params.dialog.showErrorBox).to.not.have.been.calledWith();

callbacks.error(null);
expect(params.dialog.showErrorBox).to.have.been.calledWith('Error: ', 'unknown');

callbacks.error('error');
expect(params.dialog.showErrorBox).to.have.been.calledWith('Error: ', 'error');
});

it('should call params.dialog.showMessageBox on params.autoUpdater.on("update-downloaded", ...) ', () => {
it('should show info box when update downloaded', () => {
const dialogSpy = spy(params.dialog, 'showMessageBox');

autoUpdater(params);
Expand All @@ -73,55 +84,59 @@ describe('autoUpdater', () => {
expect(dialogSpy).to.have.been.calledWith();
});

it('should call params.dialog.showMessageBox on params.autoUpdater.on("update-not-available", ...) if checkForUpdates was called', () => {
it('should show info box if update was requested but not available', () => {
const dialogSpy = spy(params.dialog, 'showMessageBox');

const checkForUpdates = autoUpdater(params);
checkForUpdates({});

callbacks['update-not-available']({ version });
expect(dialogSpy).to.have.been.calledWith({ title: 'No Updates', message: 'Current version is up-to-date.' });

expect(dialogSpy).to.have.been.calledWith();
dialogSpy.reset();
callbacks['update-not-available']({ version });
expect(dialogSpy).to.have.not.been.calledWith();
});

it('should params.autoUpdater.quitAndInstall() on "update-downloaded" in params.dialog.showMessageBox callback if the first button was pressed', () => {
it('should install update once downloaded and "Restart now" button pressed', () => {
autoUpdater(params);
callbacks['update-downloaded']({ version });
callbacks.dialog(0);

expect(params.autoUpdater.quitAndInstall).to.have.been.calledWithExactly();
});

it('should not params.autoUpdater.quitAndInstall() on "update-downloaded" in params.dialog.showMessageBox callback if the second button was pressed', () => {
it('should not install update when "Later" was pressed', () => {
autoUpdater(params);
callbacks['update-downloaded']({ version });
callbacks.dialog(1);

expect(params.autoUpdater.quitAndInstall).to.not.have.been.calledWith();
});

it('should params.autoUpdater.downloadUpdate() on "update-available" in params.dialog.showMessageBox callback if the first button was pressed', () => {
it('should download the update if update is available and the "Update" button was pressed', () => {
autoUpdater(params);
callbacks['update-available']({ version });
callbacks.dialog(0);

expect(params.autoUpdater.downloadUpdate).to.have.been.calledWithExactly();
});

it('should not params.autoUpdater.downloadUpdate() on "update-available" in params.dialog.showMessageBox callback if the second button was pressed', () => {
it('should not download the update if update is available and the "Later" button was pressed', () => {
autoUpdater(params);
callbacks['update-available']({ version });
callbacks.dialog(1);

expect(params.autoUpdater.downloadUpdate).to.not.have.been.calledWith();
});

it('should call win.browser.setProgressBar() on "download-progress"', () => {
it('should set the progress bar when being in download progress', () => {
autoUpdater(params);
callbacks['download-progress']({ transferred: 50, total: 100 });
expect(params.win.browser.setProgressBar).to.have.been.calledWith(50 / 100);
});

it('should console.error any error from params.autoUpdater.on("error", ...) ', () => {
it('should log error any update error', () => {
const error = new Error('Error: Can not find Squirrel');
const consoleSpy = spy(console, 'error');

Expand Down
1 change: 0 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ module.exports = function (config) {
'src/components/setting/setting.js',
'src/utils/externalLinks.js',
'src/utils/ipcLocale.js',
'app/src/modules/autoUpdater.js',
'src/components/votesPreview/index.js',
],
overrides: {
Expand Down

0 comments on commit 0deadf4

Please sign in to comment.