-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from LevelbossMike/master
Only start uploader when all files have been setup
- Loading branch information
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import Ember from 'ember'; | ||
import UploadQueue from 'ember-plupload/system/upload-queue'; | ||
import File from 'ember-plupload/system/file'; | ||
import { | ||
module, | ||
test | ||
} from 'qunit'; | ||
|
||
module('File', { | ||
}); | ||
|
||
test("#upload - it will only call its uploader's start method when all queued files have been setup (settings are set on all files)", function(assert) { | ||
assert.expect(3); | ||
let uploadCalls = 0; | ||
const TestableFile = File.extend({ | ||
upload() { | ||
uploadCalls++; | ||
return this._super(...arguments); | ||
} | ||
}); | ||
|
||
const uploader = Ember.Object.extend({ | ||
start() { | ||
assert.equal(uploadCalls, 2, 'Uploader was only started after both files were setup'); | ||
} | ||
}).create(); | ||
|
||
const fileToUpload1 = {id: 1}; | ||
const fileToUpload2 = {id: 2}; | ||
const queue = UploadQueue.create(); | ||
const file1 = TestableFile.create({uploader, queue, file: fileToUpload1}); | ||
const file2 = TestableFile.create({uploader, queue, file: fileToUpload2}); | ||
|
||
queue.pushObject(file1); | ||
queue.pushObject(file2); | ||
|
||
file2.upload('www.example.com'); | ||
assert.equal(uploadCalls, 1, 'first file called #upload'); | ||
file1.upload('www.example.com'); | ||
assert.equal(uploadCalls, 2, 'second file called #upload'); | ||
}); |