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

Setup auto update - Closes #196 #765

Merged
merged 19 commits into from
Nov 20, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more unit tests for autoUpdater
  • Loading branch information
slaweet committed Nov 20, 2017
commit e230e0521cbc59274c3456c4f0862924fb7045bb
44 changes: 41 additions & 3 deletions app/src/modules/autoUpdater.test.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai'; // eslint-disable-line import/no-extraneous-depen
import sinon, { spy } from 'sinon'; // eslint-disable-line import/no-extraneous-dependencies
import autoUpdater from './autoUpdater';

describe('autoUpdater', () => {
describe.only('autoUpdater', () => {
const version = '1.2.3';
let params;
let callbacks;
@@ -20,13 +20,19 @@ describe('autoUpdater', () => {
callbacks[name] = callback;
},
quitAndInstall: spy(),
downloadUpdate: spy(),
},
dialog: {
showMessageBox: (options, callback) => {
callbacks.dialog = callback;
},
showErrorBox: spy(),
},
win: {
browser: {
setProgressBar: spy(),
},
},
};

clock = sinon.useFakeTimers({
@@ -67,22 +73,54 @@ describe('autoUpdater', () => {
expect(dialogSpy).to.have.been.calledWith();
});

it.skip('should params.autoUpdater.quitAndInstall() in params.dialog.showMessageBox callback if the first button was pressed', () => {
it('should call params.dialog.showMessageBox on params.autoUpdater.on("update-not-available", ...) if checkForUpdates was called', () => {
const dialogSpy = spy(params.dialog, 'showMessageBox');

const checkForUpdates = autoUpdater(params);
checkForUpdates({});
callbacks['update-not-available']({ version });

expect(dialogSpy).to.have.been.calledWith();
});

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

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

it('should not params.autoUpdater.quitAndInstall() in params.dialog.showMessageBox callback if the second button was pressed', () => {
it('should not params.autoUpdater.quitAndInstall() on "update-downloaded" in params.dialog.showMessageBox callback if the second button 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', () => {
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', () => {
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"', () => {
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", ...) ', () => {
const error = new Error('Error: Can not find Squirrel');
const consoleSpy = spy(console, 'error');