2016-02-03 09:34:11 +03:00
|
|
|
'use babel'
|
|
|
|
|
2016-02-24 04:07:11 +03:00
|
|
|
import AutoUpdateManager from '../src/auto-update-manager'
|
2016-02-19 23:40:51 +03:00
|
|
|
import {remote} from 'electron'
|
|
|
|
const electronAutoUpdater = remote.require('electron').autoUpdater
|
2016-02-03 09:34:11 +03:00
|
|
|
|
2016-02-24 04:35:50 +03:00
|
|
|
describe('AutoUpdateManager (renderer)', () => {
|
2016-11-22 21:02:49 +03:00
|
|
|
|
|
|
|
if (process.platform !== 'darwin') return // Tests are tied to electron autoUpdater, we use something else on Linux and Win32
|
|
|
|
|
2016-02-24 04:07:11 +03:00
|
|
|
let autoUpdateManager
|
2016-02-19 10:41:23 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-03-11 21:05:28 +03:00
|
|
|
autoUpdateManager = new AutoUpdateManager({applicationDelegate: atom.applicationDelegate})
|
|
|
|
autoUpdateManager.initialize()
|
2016-02-19 10:41:23 +03:00
|
|
|
})
|
|
|
|
|
2016-02-19 23:40:51 +03:00
|
|
|
afterEach(() => {
|
2016-03-02 01:41:38 +03:00
|
|
|
autoUpdateManager.destroy()
|
2016-02-19 23:40:51 +03:00
|
|
|
})
|
|
|
|
|
2016-02-19 10:41:23 +03:00
|
|
|
describe('::onDidBeginCheckingForUpdate', () => {
|
|
|
|
it('subscribes to "did-begin-checking-for-update" event', () => {
|
|
|
|
const spy = jasmine.createSpy('spy')
|
2016-02-24 04:07:11 +03:00
|
|
|
autoUpdateManager.onDidBeginCheckingForUpdate(spy)
|
2016-02-19 23:40:51 +03:00
|
|
|
electronAutoUpdater.emit('checking-for-update')
|
|
|
|
waitsFor(() => {
|
|
|
|
return spy.callCount === 1
|
|
|
|
})
|
2016-02-19 10:41:23 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-02-26 03:00:48 +03:00
|
|
|
describe('::onDidBeginDownloadingUpdate', () => {
|
2016-02-19 10:41:23 +03:00
|
|
|
it('subscribes to "did-begin-downloading-update" event', () => {
|
|
|
|
const spy = jasmine.createSpy('spy')
|
2016-02-26 03:00:48 +03:00
|
|
|
autoUpdateManager.onDidBeginDownloadingUpdate(spy)
|
2016-02-19 23:40:51 +03:00
|
|
|
electronAutoUpdater.emit('update-available')
|
|
|
|
waitsFor(() => {
|
|
|
|
return spy.callCount === 1
|
|
|
|
})
|
2016-02-19 10:41:23 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-02-26 03:00:48 +03:00
|
|
|
describe('::onDidCompleteDownloadingUpdate', () => {
|
2016-02-19 10:41:23 +03:00
|
|
|
it('subscribes to "did-complete-downloading-update" event', () => {
|
|
|
|
const spy = jasmine.createSpy('spy')
|
2016-02-26 03:00:48 +03:00
|
|
|
autoUpdateManager.onDidCompleteDownloadingUpdate(spy)
|
2016-02-24 04:34:31 +03:00
|
|
|
electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3')
|
2016-02-19 23:40:51 +03:00
|
|
|
waitsFor(() => {
|
|
|
|
return spy.callCount === 1
|
|
|
|
})
|
2016-02-24 04:34:31 +03:00
|
|
|
runs(() => {
|
|
|
|
expect(spy.mostRecentCall.args[0].releaseVersion).toBe('1.2.3')
|
|
|
|
})
|
2016-02-19 10:41:23 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('::onUpdateNotAvailable', () => {
|
|
|
|
it('subscribes to "update-not-available" event', () => {
|
|
|
|
const spy = jasmine.createSpy('spy')
|
2016-02-24 04:07:11 +03:00
|
|
|
autoUpdateManager.onUpdateNotAvailable(spy)
|
2016-02-19 23:40:51 +03:00
|
|
|
electronAutoUpdater.emit('update-not-available')
|
|
|
|
waitsFor(() => {
|
|
|
|
return spy.callCount === 1
|
|
|
|
})
|
2016-02-19 10:41:23 +03:00
|
|
|
})
|
|
|
|
})
|
2016-02-24 04:23:11 +03:00
|
|
|
|
2016-03-30 16:05:57 +03:00
|
|
|
describe('::onUpdateError', () => {
|
|
|
|
it('subscribes to "update-error" event', () => {
|
|
|
|
const spy = jasmine.createSpy('spy')
|
|
|
|
autoUpdateManager.onUpdateError(spy)
|
2016-04-01 10:06:32 +03:00
|
|
|
electronAutoUpdater.emit('error', {}, 'an error message')
|
2016-03-30 16:05:57 +03:00
|
|
|
waitsFor(() => spy.callCount === 1)
|
2016-04-01 10:06:32 +03:00
|
|
|
runs(() => expect(autoUpdateManager.getErrorMessage()).toBe('an error message'))
|
2016-03-30 16:05:57 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-02-26 04:32:02 +03:00
|
|
|
describe('::platformSupportsUpdates', () => {
|
2016-03-01 03:42:25 +03:00
|
|
|
let state, releaseChannel
|
2016-06-18 16:33:08 +03:00
|
|
|
it('returns true on macOS and Windows when in stable', () => {
|
2016-03-01 03:42:25 +03:00
|
|
|
spyOn(autoUpdateManager, 'getState').andCallFake(() => state)
|
2016-03-02 01:59:02 +03:00
|
|
|
spyOn(atom, 'getReleaseChannel').andCallFake(() => releaseChannel)
|
2016-02-26 03:01:23 +03:00
|
|
|
|
2016-03-01 03:42:25 +03:00
|
|
|
state = 'idle'
|
2016-02-26 03:01:23 +03:00
|
|
|
releaseChannel = 'stable'
|
2016-02-26 04:32:02 +03:00
|
|
|
expect(autoUpdateManager.platformSupportsUpdates()).toBe(true)
|
2016-02-26 03:01:23 +03:00
|
|
|
|
2016-03-01 03:42:25 +03:00
|
|
|
state = 'idle'
|
2016-02-26 03:01:23 +03:00
|
|
|
releaseChannel = 'dev'
|
2016-02-26 04:32:02 +03:00
|
|
|
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false)
|
2016-02-26 03:01:23 +03:00
|
|
|
|
2016-03-01 03:42:25 +03:00
|
|
|
state = 'unsupported'
|
2016-02-26 03:01:23 +03:00
|
|
|
releaseChannel = 'stable'
|
2016-02-26 04:32:02 +03:00
|
|
|
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false)
|
2016-02-26 03:01:23 +03:00
|
|
|
|
2016-03-01 03:42:25 +03:00
|
|
|
state = 'unsupported'
|
2016-02-26 03:01:23 +03:00
|
|
|
releaseChannel = 'dev'
|
2016-02-26 04:32:02 +03:00
|
|
|
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false)
|
2016-02-26 03:01:23 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-03-02 01:41:38 +03:00
|
|
|
describe('::destroy', () => {
|
|
|
|
it('unsubscribes from all events', () => {
|
2016-02-24 04:23:11 +03:00
|
|
|
const spy = jasmine.createSpy('spy')
|
|
|
|
const doneIndicator = jasmine.createSpy('spy')
|
|
|
|
atom.applicationDelegate.onUpdateNotAvailable(doneIndicator)
|
|
|
|
autoUpdateManager.onDidBeginCheckingForUpdate(spy)
|
2016-02-26 03:00:48 +03:00
|
|
|
autoUpdateManager.onDidBeginDownloadingUpdate(spy)
|
|
|
|
autoUpdateManager.onDidCompleteDownloadingUpdate(spy)
|
2016-02-24 04:23:11 +03:00
|
|
|
autoUpdateManager.onUpdateNotAvailable(spy)
|
2016-03-02 01:41:38 +03:00
|
|
|
autoUpdateManager.destroy()
|
2016-02-24 04:23:11 +03:00
|
|
|
electronAutoUpdater.emit('checking-for-update')
|
|
|
|
electronAutoUpdater.emit('update-available')
|
2016-02-24 04:34:31 +03:00
|
|
|
electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3')
|
2016-02-24 04:23:11 +03:00
|
|
|
electronAutoUpdater.emit('update-not-available')
|
|
|
|
|
|
|
|
waitsFor(() => {
|
|
|
|
return doneIndicator.callCount === 1
|
|
|
|
})
|
|
|
|
|
|
|
|
runs(() => {
|
|
|
|
expect(spy.callCount).toBe(0)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-02-03 09:34:11 +03:00
|
|
|
})
|