Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
fix(validation): rejected files may not have correct status
Browse files Browse the repository at this point in the history
closes #1345
  • Loading branch information
rnicholus committed Jan 8, 2015
1 parent 6bae0f4 commit 5d7c020
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/js/uploader.basic.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@
_onValidateCallbackFailure: function(items, index, params, endpoint) {
var nextIndex = index + 1;

this._fileOrBlobRejected(items[0].id, items[0].file.name);
this._fileOrBlobRejected(items[index].id, items[index].file.name);

this._maybeProcessNextItemAfterOnValidateCallback(false, items, nextIndex, params, endpoint);
},
Expand Down
38 changes: 38 additions & 0 deletions test/unit/submit-validate-cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (qqtest.canDownloadFileAsBlob) {
var oldWrapCallbacks,
testImgKey = "up.jpg",
testImgType = "image/jpeg",
fileTestHelper = helpme.setupFileTests(),
testBlob;

before(function() {
Expand Down Expand Up @@ -97,6 +98,43 @@ if (qqtest.canDownloadFileAsBlob) {
});
});

it("handles a file rejected via onValidate callback", function(done) {
var filesValidated = 0,
uploader = new qq.FineUploaderBasic({
validation: {
stopOnFirstInvalidFile: false
},
callbacks: {
onAllComplete: function(succeeded, failed) {
assert.equal(succeeded.length, 1, "wrong succeeded count");
assert.equal(failed.length, 0, "wrong failed count");
assert.equal(uploader.getUploads({id: 0}).status, qq.status.UPLOAD_SUCCESSFUL);
assert.equal(uploader.getUploads({id: 1}).status, qq.status.REJECTED);
done();
},
onValidate: function(blobData, button) {
qq.log("VALIDATING" + blobData.name);
filesValidated++;

if (filesValidated === 2) {
return false;
}
}
}
});

qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
fileTestHelper.mockXhr();

uploader.addFiles([
{blob: blob, name: "name1"},
{blob: blob, name: "name2"}
]);

fileTestHelper.getRequests()[0].respond(200, null, JSON.stringify({success: true}));
});
});

describe("file rejection via callback", function() {
function setupUploader(callback, blob, done, useQ) {
var uploader = new qq.FineUploaderBasic({
Expand Down

0 comments on commit 5d7c020

Please sign in to comment.