pulsar/spec/auto-update-manager-spec.js

129 lines
4.1 KiB
JavaScript
Raw Normal View History

const AutoUpdateManager = require('../src/auto-update-manager')
2019-02-22 10:55:17 +03:00
const { remote } = require('electron')
2016-02-19 23:40:51 +03:00
const electronAutoUpdater = remote.require('electron').autoUpdater
2016-02-24 04:35:50 +03:00
describe('AutoUpdateManager (renderer)', () => {
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
beforeEach(() => {
2019-02-22 10:55:17 +03:00
autoUpdateManager = new AutoUpdateManager({
applicationDelegate: atom.applicationDelegate
})
2017-03-11 21:05:28 +03:00
autoUpdateManager.initialize()
})
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
})
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
})
})
})
describe('::onDidBeginDownloadingUpdate', () => {
it('subscribes to "did-begin-downloading-update" event', () => {
const spy = jasmine.createSpy('spy')
autoUpdateManager.onDidBeginDownloadingUpdate(spy)
2016-02-19 23:40:51 +03:00
electronAutoUpdater.emit('update-available')
waitsFor(() => {
return spy.callCount === 1
})
})
})
describe('::onDidCompleteDownloadingUpdate', () => {
it('subscribes to "did-complete-downloading-update" event', () => {
const spy = jasmine.createSpy('spy')
autoUpdateManager.onDidCompleteDownloadingUpdate(spy)
electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3')
2016-02-19 23:40:51 +03:00
waitsFor(() => {
return spy.callCount === 1
})
runs(() => {
expect(spy.mostRecentCall.args[0].releaseVersion).toBe('1.2.3')
})
})
})
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-24 04:23:11 +03:00
describe('::onUpdateError', () => {
it('subscribes to "update-error" event', () => {
const spy = jasmine.createSpy('spy')
autoUpdateManager.onUpdateError(spy)
electronAutoUpdater.emit('error', {}, 'an error message')
waitsFor(() => spy.callCount === 1)
2019-02-22 10:55:17 +03:00
runs(() =>
expect(autoUpdateManager.getErrorMessage()).toBe('an error message')
)
})
})
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', () => {
2019-02-22 10:55:17 +03:00
spyOn(autoUpdateManager, 'getState').andCallFake(() => state)
2016-03-02 01:59:02 +03:00
spyOn(atom, 'getReleaseChannel').andCallFake(() => releaseChannel)
2016-03-01 03:42:25 +03:00
state = 'idle'
releaseChannel = 'stable'
2016-02-26 04:32:02 +03:00
expect(autoUpdateManager.platformSupportsUpdates()).toBe(true)
2016-03-01 03:42:25 +03:00
state = 'idle'
releaseChannel = 'dev'
2016-02-26 04:32:02 +03:00
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false)
2016-03-01 03:42:25 +03:00
state = 'unsupported'
releaseChannel = 'stable'
2016-02-26 04:32:02 +03:00
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false)
2016-03-01 03:42:25 +03:00
state = 'unsupported'
releaseChannel = 'dev'
2016-02-26 04:32:02 +03:00
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false)
})
})
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)
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')
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)
})
})
})
})