forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto-update-manager-spec.js
128 lines (111 loc) · 4.2 KB
/
auto-update-manager-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const AutoUpdateManager = require('../src/auto-update-manager');
const { remote } = require('electron');
const electronAutoUpdater = remote.require('electron').autoUpdater;
describe('AutoUpdateManager (renderer)', () => {
if (process.platform !== 'darwin') return; // Tests are tied to electron autoUpdater, we use something else on Linux and Win32
let autoUpdateManager;
beforeEach(() => {
autoUpdateManager = new AutoUpdateManager({
applicationDelegate: atom.applicationDelegate
});
autoUpdateManager.initialize();
});
afterEach(() => {
autoUpdateManager.destroy();
});
describe('::onDidBeginCheckingForUpdate', () => {
it('subscribes to "did-begin-checking-for-update" event', () => {
const spy = jasmine.createSpy('spy');
autoUpdateManager.onDidBeginCheckingForUpdate(spy);
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);
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');
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');
autoUpdateManager.onUpdateNotAvailable(spy);
electronAutoUpdater.emit('update-not-available');
waitsFor(() => {
return spy.callCount === 1;
});
});
});
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);
runs(() =>
expect(autoUpdateManager.getErrorMessage()).toBe('an error message')
);
});
});
describe('::platformSupportsUpdates', () => {
let state, releaseChannel;
it('returns true on macOS and Windows when in stable', () => {
spyOn(autoUpdateManager, 'getState').andCallFake(() => state);
spyOn(atom, 'getReleaseChannel').andCallFake(() => releaseChannel);
state = 'idle';
releaseChannel = 'stable';
expect(autoUpdateManager.platformSupportsUpdates()).toBe(true);
state = 'idle';
releaseChannel = 'dev';
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false);
state = 'unsupported';
releaseChannel = 'stable';
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false);
state = 'unsupported';
releaseChannel = 'dev';
expect(autoUpdateManager.platformSupportsUpdates()).toBe(false);
});
});
describe('::destroy', () => {
it('unsubscribes from all events', () => {
const spy = jasmine.createSpy('spy');
const doneIndicator = jasmine.createSpy('spy');
atom.applicationDelegate.onUpdateNotAvailable(doneIndicator);
autoUpdateManager.onDidBeginCheckingForUpdate(spy);
autoUpdateManager.onDidBeginDownloadingUpdate(spy);
autoUpdateManager.onDidCompleteDownloadingUpdate(spy);
autoUpdateManager.onUpdateNotAvailable(spy);
autoUpdateManager.destroy();
electronAutoUpdater.emit('checking-for-update');
electronAutoUpdater.emit('update-available');
electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3');
electronAutoUpdater.emit('update-not-available');
waitsFor(() => {
return doneIndicator.callCount === 1;
});
runs(() => {
expect(spy.callCount).toBe(0);
});
});
});
});