Skip to content

Commit 7d6139f

Browse files
Sterling Weievilaliv3
authored andcommitted
Add unit-tests for fileRemove event.
1 parent 628dc31 commit 7d6139f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

test/fileRemoveSpec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
describe('fileRemoved event', function() {
2+
/**
3+
* @type {Flow}
4+
*/
5+
var flow;
6+
7+
beforeEach(function () {
8+
flow = new Flow({
9+
generateUniqueIdentifier: function (file) {
10+
return file.size;
11+
}
12+
});
13+
});
14+
15+
it('should call fileRemoved event on Flow.removeFile', function() {
16+
var valid = false;
17+
var removedFile = null;
18+
flow.on('fileRemoved', function (file) {
19+
expect(file.file instanceof Blob).toBeTruthy();
20+
removedFile = file;
21+
valid = true;
22+
});
23+
flow.addFile(new Blob(['file part']));
24+
var addedFile = flow.files[0];
25+
flow.removeFile(addedFile);
26+
expect(removedFile).toBe(addedFile);
27+
expect(valid).toBeTruthy();
28+
});
29+
30+
it('should call fileRemoved event FlowFile.cancel', function() {
31+
var valid = false;
32+
var removedFile = null;
33+
flow.on('fileRemoved', function (file) {
34+
expect(file.file instanceof Blob).toBeTruthy();
35+
removedFile = file;
36+
valid = true;
37+
});
38+
flow.addFile(new Blob(['file part']));
39+
var addedFile = flow.files[0];
40+
addedFile.cancel();
41+
expect(removedFile).toBe(addedFile);
42+
expect(valid).toBeTruthy();
43+
});
44+
45+
});

test/singleFileSpec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,29 @@ describe('add single file', function() {
2323
expect(flow.files.length).toBe(1);
2424
expect(file.isUploading()).toBeFalsy();
2525
});
26+
27+
it('should fire remove event after adding another file', function(){
28+
var events = [];
29+
flow.on('catchAll', function (event) {
30+
events.push(event);
31+
});
32+
flow.addFile(new Blob(['file part']));
33+
expect(flow.files.length).toBe(1);
34+
expect(events.length).toBe(3);
35+
expect(events[0]).toBe('fileAdded');
36+
expect(events[1]).toBe('filesAdded');
37+
expect(events[2]).toBe('filesSubmitted');
38+
39+
var removedFile = flow.files[0];
40+
flow.on('fileRemoved', function(file){
41+
expect(file).toBe(removedFile);
42+
});
43+
flow.addFile(new Blob(['file part 2']));
44+
expect(flow.files.length).toBe(1);
45+
expect(events.length).toBe(7);
46+
expect(events[3]).toBe('fileAdded');
47+
expect(events[4]).toBe('filesAdded');
48+
expect(events[5]).toBe('fileRemoved');
49+
expect(events[6]).toBe('filesSubmitted');
50+
});
2651
});

0 commit comments

Comments
 (0)