Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only start uploader when all files have been setup #85

Merged
merged 1 commit into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addon/system/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ export default Ember.Object.extend({
if (this.file.status === plupload.FAILED) {
this.file.status = plupload.QUEUED;
}
uploader.start();
if (this.get('queue').every((f) => f.settings)) {
uploader.start();
}
}

return this._deferred.promise;
Expand Down
3 changes: 2 additions & 1 deletion addon/system/upload-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export default Ember.ArrayProxy.extend({
for (let i = 0, len = files.length; i < len; i++) {
var file = File.create({
uploader: uploader,
file: files[i]
file: files[i],
queue: this
});

this.pushObject(file);
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/system/file-test.js
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');
});