@@ -7,10 +7,11 @@ jest.mock("electron", () => ({
7
7
}
8
8
} ) ) ;
9
9
10
- import { ipcRenderer } from "electron" ;
11
- import Settings , { SettingKey } from "./settings" ;
10
+ import { ipcRenderer } from "electron" ;
12
11
import { UploadAction } from "@common/ipc-actions/upload" ;
12
+ import { DownloadAction } from "@common/ipc-actions/download" ;
13
13
import ByteSize from "@common/const/byte-size" ;
14
+ import Settings , { SettingKey } from "./settings" ;
14
15
15
16
// WARNING: The getter tests in "no data in storage" section is
16
17
// for testing default value.
@@ -105,7 +106,7 @@ describe("test settings.ts", () => {
105
106
it ( "isDebug setter" , ( ) => {
106
107
Settings . isDebug = 1 ;
107
108
expect ( Settings . isDebug ) . toBe ( 1 ) ;
108
- expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
109
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith (
109
110
"UploaderManager" ,
110
111
{
111
112
action : UploadAction . UpdateConfig ,
@@ -114,9 +115,18 @@ describe("test settings.ts", () => {
114
115
} ,
115
116
} ,
116
117
) ;
118
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith (
119
+ "DownloaderManager" ,
120
+ {
121
+ action : DownloadAction . UpdateConfig ,
122
+ data : {
123
+ isDebug : true ,
124
+ } ,
125
+ } ,
126
+ ) ;
117
127
Settings . isDebug = 0 ;
118
128
expect ( Settings . isDebug ) . toBe ( 0 ) ;
119
- expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
129
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith (
120
130
"UploaderManager" ,
121
131
{
122
132
action : UploadAction . UpdateConfig ,
@@ -125,6 +135,15 @@ describe("test settings.ts", () => {
125
135
} ,
126
136
} ,
127
137
) ;
138
+ expect ( ipcRenderer . send ) . toHaveBeenCalledWith (
139
+ "DownloaderManager" ,
140
+ {
141
+ action : DownloadAction . UpdateConfig ,
142
+ data : {
143
+ isDebug : false ,
144
+ } ,
145
+ } ,
146
+ ) ;
128
147
} ) ;
129
148
130
149
// autoUpgrade
@@ -150,7 +169,7 @@ describe("test settings.ts", () => {
150
169
{
151
170
action : UploadAction . UpdateConfig ,
152
171
data : {
153
- resumeUpload : true ,
172
+ resumable : true ,
154
173
} ,
155
174
} ,
156
175
) ;
@@ -161,7 +180,7 @@ describe("test settings.ts", () => {
161
180
{
162
181
action : UploadAction . UpdateConfig ,
163
182
data : {
164
- resumeUpload : false ,
183
+ resumable : false ,
165
184
} ,
166
185
} ,
167
186
) ;
@@ -208,7 +227,7 @@ describe("test settings.ts", () => {
208
227
{
209
228
action : UploadAction . UpdateConfig ,
210
229
data : {
211
- multipartUploadSize : 10 * ByteSize . MB ,
230
+ multipartSize : 10 * ByteSize . MB ,
212
231
} ,
213
232
} ,
214
233
) ;
@@ -219,7 +238,7 @@ describe("test settings.ts", () => {
219
238
{
220
239
action : UploadAction . UpdateConfig ,
221
240
data : {
222
- multipartUploadSize : 8 * ByteSize . MB ,
241
+ multipartSize : 8 * ByteSize . MB ,
223
242
} ,
224
243
} ,
225
244
) ;
@@ -243,7 +262,7 @@ describe("test settings.ts", () => {
243
262
{
244
263
action : UploadAction . UpdateConfig ,
245
264
data : {
246
- multipartUploadThreshold : 110 * ByteSize . MB ,
265
+ multipartThreshold : 110 * ByteSize . MB ,
247
266
} ,
248
267
} ,
249
268
) ;
@@ -254,7 +273,7 @@ describe("test settings.ts", () => {
254
273
{
255
274
action : UploadAction . UpdateConfig ,
256
275
data : {
257
- multipartUploadThreshold : 100 * ByteSize . MB ,
276
+ multipartThreshold : 100 * ByteSize . MB ,
258
277
} ,
259
278
} ,
260
279
) ;
@@ -272,7 +291,7 @@ describe("test settings.ts", () => {
272
291
{
273
292
action : UploadAction . UpdateConfig ,
274
293
data : {
275
- uploadSpeedLimit : Settings . uploadSpeedLimitKBperSec * ByteSize . KB ,
294
+ speedLimit : Settings . uploadSpeedLimitKBperSec * ByteSize . KB ,
276
295
} ,
277
296
} ,
278
297
) ;
@@ -283,7 +302,7 @@ describe("test settings.ts", () => {
283
302
{
284
303
action : UploadAction . UpdateConfig ,
285
304
data : {
286
- uploadSpeedLimit : 0 ,
305
+ speedLimit : 0 ,
287
306
} ,
288
307
} ,
289
308
) ;
@@ -302,7 +321,7 @@ describe("test settings.ts", () => {
302
321
{
303
322
action : UploadAction . UpdateConfig ,
304
323
data : {
305
- uploadSpeedLimit : 2048 * ByteSize . KB ,
324
+ speedLimit : 2048 * ByteSize . KB ,
306
325
} ,
307
326
} ,
308
327
) ;
@@ -313,7 +332,7 @@ describe("test settings.ts", () => {
313
332
{
314
333
action : UploadAction . UpdateConfig ,
315
334
data : {
316
- uploadSpeedLimit : 1024 * ByteSize . KB ,
335
+ speedLimit : 1024 * ByteSize . KB ,
317
336
} ,
318
337
} ,
319
338
) ;
@@ -326,8 +345,26 @@ describe("test settings.ts", () => {
326
345
it ( "resumeDownload setter" , ( ) => {
327
346
Settings . resumeDownload = 1 ;
328
347
expect ( Settings . resumeDownload ) . toBe ( 1 ) ;
348
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
349
+ "DownloaderManager" ,
350
+ {
351
+ action : DownloadAction . UpdateConfig ,
352
+ data : {
353
+ resumable : true ,
354
+ } ,
355
+ } ,
356
+ ) ;
329
357
Settings . resumeDownload = 0 ;
330
358
expect ( Settings . resumeDownload ) . toBe ( 0 ) ;
359
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
360
+ "DownloaderManager" ,
361
+ {
362
+ action : DownloadAction . UpdateConfig ,
363
+ data : {
364
+ resumable : false ,
365
+ } ,
366
+ } ,
367
+ ) ;
331
368
} ) ;
332
369
333
370
// maxDownloadConcurrency
@@ -337,8 +374,26 @@ describe("test settings.ts", () => {
337
374
it ( "maxDownloadConcurrency setter" , ( ) => {
338
375
Settings . maxDownloadConcurrency = 2 ;
339
376
expect ( Settings . maxDownloadConcurrency ) . toBe ( 2 ) ;
377
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
378
+ "DownloaderManager" ,
379
+ {
380
+ action : DownloadAction . UpdateConfig ,
381
+ data : {
382
+ maxConcurrency : 2 ,
383
+ } ,
384
+ } ,
385
+ ) ;
340
386
Settings . maxDownloadConcurrency = 1 ;
341
387
expect ( Settings . maxDownloadConcurrency ) . toBe ( 1 ) ;
388
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
389
+ "DownloaderManager" ,
390
+ {
391
+ action : DownloadAction . UpdateConfig ,
392
+ data : {
393
+ maxConcurrency : 1 ,
394
+ } ,
395
+ } ,
396
+ ) ;
342
397
} ) ;
343
398
344
399
// multipartDownloadSize
@@ -348,8 +403,26 @@ describe("test settings.ts", () => {
348
403
it ( "multipartDownloadSize setter" , ( ) => {
349
404
Settings . multipartDownloadSize = 4 ;
350
405
expect ( Settings . multipartDownloadSize ) . toBe ( 4 ) ;
406
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
407
+ "DownloaderManager" ,
408
+ {
409
+ action : DownloadAction . UpdateConfig ,
410
+ data : {
411
+ multipartSize : 4 * ByteSize . MB ,
412
+ } ,
413
+ } ,
414
+ ) ;
351
415
Settings . multipartDownloadSize = 8 ;
352
416
expect ( Settings . multipartDownloadSize ) . toBe ( 8 ) ;
417
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
418
+ "DownloaderManager" ,
419
+ {
420
+ action : DownloadAction . UpdateConfig ,
421
+ data : {
422
+ multipartSize : 8 * ByteSize . MB ,
423
+ } ,
424
+ } ,
425
+ ) ;
353
426
} ) ;
354
427
355
428
// multipartDownloadThreshold
@@ -359,8 +432,26 @@ describe("test settings.ts", () => {
359
432
it ( "multipartDownloadThreshold setter" , ( ) => {
360
433
Settings . multipartDownloadThreshold = 110 ;
361
434
expect ( Settings . multipartDownloadThreshold ) . toBe ( 110 ) ;
435
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
436
+ "DownloaderManager" ,
437
+ {
438
+ action : DownloadAction . UpdateConfig ,
439
+ data : {
440
+ multipartThreshold : 110 * ByteSize . MB ,
441
+ } ,
442
+ } ,
443
+ ) ;
362
444
Settings . multipartDownloadThreshold = 100 ;
363
445
expect ( Settings . multipartDownloadThreshold ) . toBe ( 100 ) ;
446
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
447
+ "DownloaderManager" ,
448
+ {
449
+ action : DownloadAction . UpdateConfig ,
450
+ data : {
451
+ multipartThreshold : 100 * ByteSize . MB ,
452
+ } ,
453
+ } ,
454
+ ) ;
364
455
} ) ;
365
456
366
457
// downloadSpeedLimitEnabled
@@ -370,19 +461,56 @@ describe("test settings.ts", () => {
370
461
it ( "downloadSpeedLimitEnabled setter" , ( ) => {
371
462
Settings . downloadSpeedLimitEnabled = 1 ;
372
463
expect ( Settings . downloadSpeedLimitEnabled ) . toBe ( 1 ) ;
464
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
465
+ "DownloaderManager" ,
466
+ {
467
+ action : DownloadAction . UpdateConfig ,
468
+ data : {
469
+ speedLimit : Settings . uploadSpeedLimitKBperSec * ByteSize . KB ,
470
+ } ,
471
+ } ,
472
+ ) ;
373
473
Settings . downloadSpeedLimitEnabled = 0 ;
374
474
expect ( Settings . downloadSpeedLimitEnabled ) . toBe ( 0 ) ;
475
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
476
+ "DownloaderManager" ,
477
+ {
478
+ action : DownloadAction . UpdateConfig ,
479
+ data : {
480
+ speedLimit : 0 ,
481
+ } ,
482
+ } ,
483
+ ) ;
375
484
} ) ;
376
485
377
486
// downloadSpeedLimitKBperSec
378
487
it ( "downloadSpeedLimitKBperSec getter" , ( ) => {
379
488
expect ( Settings . downloadSpeedLimitKBperSec ) . toBe ( 1024 ) ;
380
489
} ) ;
381
490
it ( "downloadSpeedLimitKBperSec setter" , ( ) => {
491
+ Settings . downloadSpeedLimitEnabled = 1 ;
382
492
Settings . downloadSpeedLimitKBperSec = 2048 ;
383
493
expect ( Settings . downloadSpeedLimitKBperSec ) . toBe ( 2048 ) ;
494
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
495
+ "DownloaderManager" ,
496
+ {
497
+ action : DownloadAction . UpdateConfig ,
498
+ data : {
499
+ speedLimit : 2048 * ByteSize . KB ,
500
+ } ,
501
+ } ,
502
+ ) ;
384
503
Settings . downloadSpeedLimitKBperSec = 1024 ;
385
504
expect ( Settings . downloadSpeedLimitKBperSec ) . toBe ( 1024 ) ;
505
+ expect ( ipcRenderer . send ) . toHaveBeenLastCalledWith (
506
+ "DownloaderManager" ,
507
+ {
508
+ action : DownloadAction . UpdateConfig ,
509
+ data : {
510
+ speedLimit : 1024 * ByteSize . KB ,
511
+ } ,
512
+ } ,
513
+ ) ;
386
514
} ) ;
387
515
388
516
// externalPathEnabled
0 commit comments