-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
150 lines (120 loc) · 3.07 KB
/
test.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const test = require('ava');
const sinon = require('sinon');
const {AutoUpdateStub} = require('./auto-update-stub');
const {ElectronAutoUpdate} = require('.');
test.beforeEach(t => {
t.context.sandbox = sinon.createSandbox({
useFakeTimers: true
});
});
test.afterEach(t => {
const sandbox = t.context.sandbox;
sandbox.clock.restore();
sandbox.restore();
});
test('uses default options', t => {
const updater = new ElectronAutoUpdate({
electronUpdater: {
autoUpdater: {}
}
});
t.like(updater.options, {
checkFrequency: 1000 * 60 * 60
});
});
test('allows override of default options', t => {
const updater = new ElectronAutoUpdate({
checkFrequency: 5,
electronUpdater: {
autoUpdater: {}
}
});
t.like(updater.options, {
checkFrequency: 5
});
});
test('sets the logger for electron-updater', t => {
const logger = {};
const updater = new ElectronAutoUpdate({
logger,
electronUpdater: {
autoUpdater: {}
}
});
t.is(updater.autoUpdater.logger, logger);
});
test('checks for updates at the frequency specified', t => {
const checkSpy = t.context.sandbox.spy();
const dialogFake = t.context.sandbox.fake.resolves({response: 1});
const updater = new ElectronAutoUpdate({
checkFrequency: 5,
electronUpdater: {
autoUpdater: {
checkForUpdates: checkSpy,
on: (eventName, fn) => {
if (eventName === 'update-not-available') {
fn();
}
}
}
},
dialog: {
showMessageBox: dialogFake
}
});
updater.checkForUpdates();
t.context.sandbox.clock.tick(7);
t.is(checkSpy.callCount, 2);
});
test('displays dialog when download is ready', async t => {
const dialogFake = t.context.sandbox.fake.resolves({response: 0});
const quitSpy = t.context.sandbox.spy();
const updater = new ElectronAutoUpdate({
electronUpdater: {
autoUpdater: new AutoUpdateStub({
onQuit: quitSpy,
downloadAvailableIn: 0
})
},
dialog: {
showMessageBox: dialogFake
}
});
await updater.checkForUpdates();
t.is(dialogFake.callCount, 1);
t.truthy(quitSpy.calledOnce);
});
test('it will remind user to update if they choose later', async t => {
const dialogFake = t.context.sandbox.fake.resolves({response: 1, checkboxChecked: true});
const quitSpy = t.context.sandbox.spy();
const updater = new ElectronAutoUpdate({
checkFrequency: 5,
electronUpdater: {
autoUpdater: new AutoUpdateStub({onQuit: quitSpy})
},
dialog: {
showMessageBox: dialogFake
}
});
await updater.checkForUpdates();
t.context.sandbox.clock.tick(7);
t.is(dialogFake.callCount, 2);
t.truthy(quitSpy.notCalled);
});
test('it will not remind a user to install update if they uncheck reminder', async t => {
const dialogFake = t.context.sandbox.fake.resolves({response: 1, checkboxChecked: false});
const quitSpy = t.context.sandbox.spy();
const updater = new ElectronAutoUpdate({
checkFrequency: 5,
electronUpdater: {
autoUpdater: new AutoUpdateStub()
},
dialog: {
showMessageBox: dialogFake
}
});
await updater.checkForUpdates();
t.context.sandbox.clock.tick(7);
t.truthy(dialogFake.calledOnce);
t.truthy(quitSpy.notCalled);
});