Skip to content

Commit

Permalink
Add unit-tests for fileRemove event.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sterling Wei authored and evilaliv3 committed Mar 22, 2016
1 parent 628dc31 commit 7d6139f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/fileRemoveSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
describe('fileRemoved event', function() {
/**
* @type {Flow}
*/
var flow;

beforeEach(function () {
flow = new Flow({
generateUniqueIdentifier: function (file) {
return file.size;
}
});
});

it('should call fileRemoved event on Flow.removeFile', function() {
var valid = false;
var removedFile = null;
flow.on('fileRemoved', function (file) {
expect(file.file instanceof Blob).toBeTruthy();
removedFile = file;
valid = true;
});
flow.addFile(new Blob(['file part']));
var addedFile = flow.files[0];
flow.removeFile(addedFile);
expect(removedFile).toBe(addedFile);
expect(valid).toBeTruthy();
});

it('should call fileRemoved event FlowFile.cancel', function() {
var valid = false;
var removedFile = null;
flow.on('fileRemoved', function (file) {
expect(file.file instanceof Blob).toBeTruthy();
removedFile = file;
valid = true;
});
flow.addFile(new Blob(['file part']));
var addedFile = flow.files[0];
addedFile.cancel();
expect(removedFile).toBe(addedFile);
expect(valid).toBeTruthy();
});

});
25 changes: 25 additions & 0 deletions test/singleFileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,29 @@ describe('add single file', function() {
expect(flow.files.length).toBe(1);
expect(file.isUploading()).toBeFalsy();
});

it('should fire remove event after adding another file', function(){
var events = [];
flow.on('catchAll', function (event) {
events.push(event);
});
flow.addFile(new Blob(['file part']));
expect(flow.files.length).toBe(1);
expect(events.length).toBe(3);
expect(events[0]).toBe('fileAdded');
expect(events[1]).toBe('filesAdded');
expect(events[2]).toBe('filesSubmitted');

var removedFile = flow.files[0];
flow.on('fileRemoved', function(file){
expect(file).toBe(removedFile);
});
flow.addFile(new Blob(['file part 2']));
expect(flow.files.length).toBe(1);
expect(events.length).toBe(7);
expect(events[3]).toBe('fileAdded');
expect(events[4]).toBe('filesAdded');
expect(events[5]).toBe('fileRemoved');
expect(events[6]).toBe('filesSubmitted');
});
});

0 comments on commit 7d6139f

Please sign in to comment.