Skip to content

Commit d86e2ad

Browse files
committed
fix tests for settings(015a4a0)
1 parent 379e837 commit d86e2ad

File tree

1 file changed

+142
-14
lines changed

1 file changed

+142
-14
lines changed

src/renderer/components/services/settings.test.ts

Lines changed: 142 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ jest.mock("electron", () => ({
77
}
88
}));
99

10-
import { ipcRenderer } from "electron";
11-
import Settings, { SettingKey } from "./settings";
10+
import {ipcRenderer} from "electron";
1211
import {UploadAction} from "@common/ipc-actions/upload";
12+
import {DownloadAction} from "@common/ipc-actions/download";
1313
import ByteSize from "@common/const/byte-size";
14+
import Settings, {SettingKey} from "./settings";
1415

1516
// WARNING: The getter tests in "no data in storage" section is
1617
// for testing default value.
@@ -105,7 +106,7 @@ describe("test settings.ts", () => {
105106
it("isDebug setter", () => {
106107
Settings.isDebug = 1;
107108
expect(Settings.isDebug).toBe(1);
108-
expect(ipcRenderer.send).toHaveBeenLastCalledWith(
109+
expect(ipcRenderer.send).toHaveBeenCalledWith(
109110
"UploaderManager",
110111
{
111112
action: UploadAction.UpdateConfig,
@@ -114,9 +115,18 @@ describe("test settings.ts", () => {
114115
},
115116
},
116117
);
118+
expect(ipcRenderer.send).toHaveBeenCalledWith(
119+
"DownloaderManager",
120+
{
121+
action: DownloadAction.UpdateConfig,
122+
data: {
123+
isDebug: true,
124+
},
125+
},
126+
);
117127
Settings.isDebug = 0;
118128
expect(Settings.isDebug).toBe(0);
119-
expect(ipcRenderer.send).toHaveBeenLastCalledWith(
129+
expect(ipcRenderer.send).toHaveBeenCalledWith(
120130
"UploaderManager",
121131
{
122132
action: UploadAction.UpdateConfig,
@@ -125,6 +135,15 @@ describe("test settings.ts", () => {
125135
},
126136
},
127137
);
138+
expect(ipcRenderer.send).toHaveBeenCalledWith(
139+
"DownloaderManager",
140+
{
141+
action: DownloadAction.UpdateConfig,
142+
data: {
143+
isDebug: false,
144+
},
145+
},
146+
);
128147
});
129148

130149
// autoUpgrade
@@ -150,7 +169,7 @@ describe("test settings.ts", () => {
150169
{
151170
action: UploadAction.UpdateConfig,
152171
data: {
153-
resumeUpload: true,
172+
resumable: true,
154173
},
155174
},
156175
);
@@ -161,7 +180,7 @@ describe("test settings.ts", () => {
161180
{
162181
action: UploadAction.UpdateConfig,
163182
data: {
164-
resumeUpload: false,
183+
resumable: false,
165184
},
166185
},
167186
);
@@ -208,7 +227,7 @@ describe("test settings.ts", () => {
208227
{
209228
action: UploadAction.UpdateConfig,
210229
data: {
211-
multipartUploadSize: 10 * ByteSize.MB,
230+
multipartSize: 10 * ByteSize.MB,
212231
},
213232
},
214233
);
@@ -219,7 +238,7 @@ describe("test settings.ts", () => {
219238
{
220239
action: UploadAction.UpdateConfig,
221240
data: {
222-
multipartUploadSize: 8 * ByteSize.MB,
241+
multipartSize: 8 * ByteSize.MB,
223242
},
224243
},
225244
);
@@ -243,7 +262,7 @@ describe("test settings.ts", () => {
243262
{
244263
action: UploadAction.UpdateConfig,
245264
data: {
246-
multipartUploadThreshold: 110 * ByteSize.MB,
265+
multipartThreshold: 110 * ByteSize.MB,
247266
},
248267
},
249268
);
@@ -254,7 +273,7 @@ describe("test settings.ts", () => {
254273
{
255274
action: UploadAction.UpdateConfig,
256275
data: {
257-
multipartUploadThreshold: 100 * ByteSize.MB,
276+
multipartThreshold: 100 * ByteSize.MB,
258277
},
259278
},
260279
);
@@ -272,7 +291,7 @@ describe("test settings.ts", () => {
272291
{
273292
action: UploadAction.UpdateConfig,
274293
data: {
275-
uploadSpeedLimit: Settings.uploadSpeedLimitKBperSec * ByteSize.KB,
294+
speedLimit: Settings.uploadSpeedLimitKBperSec * ByteSize.KB,
276295
},
277296
},
278297
);
@@ -283,7 +302,7 @@ describe("test settings.ts", () => {
283302
{
284303
action: UploadAction.UpdateConfig,
285304
data: {
286-
uploadSpeedLimit: 0,
305+
speedLimit: 0,
287306
},
288307
},
289308
);
@@ -302,7 +321,7 @@ describe("test settings.ts", () => {
302321
{
303322
action: UploadAction.UpdateConfig,
304323
data: {
305-
uploadSpeedLimit: 2048 * ByteSize.KB,
324+
speedLimit: 2048 * ByteSize.KB,
306325
},
307326
},
308327
);
@@ -313,7 +332,7 @@ describe("test settings.ts", () => {
313332
{
314333
action: UploadAction.UpdateConfig,
315334
data: {
316-
uploadSpeedLimit: 1024 * ByteSize.KB,
335+
speedLimit: 1024 * ByteSize.KB,
317336
},
318337
},
319338
);
@@ -326,8 +345,26 @@ describe("test settings.ts", () => {
326345
it("resumeDownload setter", () => {
327346
Settings.resumeDownload = 1;
328347
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+
);
329357
Settings.resumeDownload = 0;
330358
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+
);
331368
});
332369

333370
// maxDownloadConcurrency
@@ -337,8 +374,26 @@ describe("test settings.ts", () => {
337374
it("maxDownloadConcurrency setter", () => {
338375
Settings.maxDownloadConcurrency = 2;
339376
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+
);
340386
Settings.maxDownloadConcurrency = 1;
341387
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+
);
342397
});
343398

344399
// multipartDownloadSize
@@ -348,8 +403,26 @@ describe("test settings.ts", () => {
348403
it("multipartDownloadSize setter", () => {
349404
Settings.multipartDownloadSize = 4;
350405
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+
);
351415
Settings.multipartDownloadSize = 8;
352416
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+
);
353426
});
354427

355428
// multipartDownloadThreshold
@@ -359,8 +432,26 @@ describe("test settings.ts", () => {
359432
it("multipartDownloadThreshold setter", () => {
360433
Settings.multipartDownloadThreshold = 110;
361434
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+
);
362444
Settings.multipartDownloadThreshold = 100;
363445
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+
);
364455
});
365456

366457
// downloadSpeedLimitEnabled
@@ -370,19 +461,56 @@ describe("test settings.ts", () => {
370461
it("downloadSpeedLimitEnabled setter", () => {
371462
Settings.downloadSpeedLimitEnabled = 1;
372463
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+
);
373473
Settings.downloadSpeedLimitEnabled = 0;
374474
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+
);
375484
});
376485

377486
// downloadSpeedLimitKBperSec
378487
it("downloadSpeedLimitKBperSec getter", () => {
379488
expect(Settings.downloadSpeedLimitKBperSec).toBe(1024);
380489
});
381490
it("downloadSpeedLimitKBperSec setter", () => {
491+
Settings.downloadSpeedLimitEnabled = 1;
382492
Settings.downloadSpeedLimitKBperSec = 2048;
383493
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+
);
384503
Settings.downloadSpeedLimitKBperSec = 1024;
385504
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+
);
386514
});
387515

388516
// externalPathEnabled

0 commit comments

Comments
 (0)