Skip to content

Commit dbbc333

Browse files
committed
test(timeRemaining): pause, error and finished upload cases
1 parent a38919b commit dbbc333

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

test/resumableFileSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ describe('FlowFile functions', function() {
55
*/
66
var flow;
77
/**
8-
* @type {FlowFile}
8+
* @type {Flow.FlowFile}
99
*/
1010
var file;
1111

test/setupSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('setup', function() {
3939

4040
expect(flow.progress()).toBe(0);
4141
expect(flow.isUploading()).toBe(false);
42-
expect(flow.timeRemaining()).toBe(Number.POSITIVE_INFINITY);
42+
expect(flow.timeRemaining()).toBe(0);
4343
expect(flow.sizeUploaded()).toBe(0);
4444
});
4545

test/uploadSpec.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ describe('upload file', function() {
417417
expect(fileFirst.averageSpeed).toBe(3.75);
418418

419419
requests[0].respond(200, [], "response");
420-
expect(fileFirst.currentSpeed).toBe(5);
421-
expect(fileFirst.averageSpeed).toBe(3.75);
420+
expect(fileFirst.currentSpeed).toBe(0);
421+
expect(fileFirst.averageSpeed).toBe(0);
422422

423423
requests[1].respond(200, [], "response");
424424
expect(fileFirst.sizeUploaded()).toBe(10);
@@ -427,5 +427,35 @@ describe('upload file', function() {
427427
expect(fileSecond.timeRemaining()).toBe(0);
428428
expect(flow.sizeUploaded()).toBe(15);
429429
expect(flow.timeRemaining()).toBe(0);
430+
431+
// paused and resumed
432+
flow.addFile(new Blob(['012345678901234']));
433+
var fileThird = flow.files[2];
434+
expect(fileThird.timeRemaining()).toBe(Number.POSITIVE_INFINITY);
435+
flow.upload();
436+
clock.tick(1000);
437+
requests[2].progress(10, 15, true);
438+
expect(fileThird.timeRemaining()).toBe(1);
439+
expect(flow.timeRemaining()).toBe(1);
440+
fileThird.pause();
441+
expect(fileThird.timeRemaining()).toBe(0);
442+
expect(flow.timeRemaining()).toBe(0);
443+
fileThird.resume();
444+
expect(fileThird.timeRemaining()).toBe(Number.POSITIVE_INFINITY);
445+
expect(flow.timeRemaining()).toBe(Number.POSITIVE_INFINITY);
446+
clock.tick(1000);
447+
requests[3].progress(11, 15, true);
448+
expect(fileThird.timeRemaining()).toBe(8);
449+
expect(flow.timeRemaining()).toBe(8);
450+
clock.tick(1000);
451+
requests[3].progress(12, 15, true);
452+
expect(fileThird.timeRemaining()).toBe(4);
453+
expect(flow.timeRemaining()).toBe(4);
454+
455+
requests[3].respond(500);
456+
expect(fileThird.currentSpeed).toBe(0);
457+
expect(fileThird.averageSpeed).toBe(0);
458+
expect(fileThird.timeRemaining()).toBe(0);
459+
expect(flow.timeRemaining()).toBe(0);
430460
});
431461
});

0 commit comments

Comments
 (0)