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

Commit

Permalink
test(addCanvas): unit tests for canvas to addFiles
Browse files Browse the repository at this point in the history
closes #1198
  • Loading branch information
Ray Nicholus committed Oct 6, 2014
1 parent c9f6de6 commit a21d7ac
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/unit/simple-file-uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,66 @@ if (qqtest.canDownloadFileAsBlob) {
fileTestHelper.getRequests()[0].respond(500, null, JSON.stringify({success: true}));
});
});

describe("canvas uploading", function() {
var origCanvasToBlob;

beforeEach(function() {
origCanvasToBlob = qq.canvasToBlob;
});

afterEach(function() {
qq.canvasToBlob = origCanvasToBlob;
});

it("attempts to convert the passed canvas to a blob", function(done) {
var uploader = new qq.FineUploaderBasic({
request: {
endpoint: "/test/endpoint"
}
}),
canvas = document.createElement("canvas");

qq.canvasToBlob = function(passedCanvas, mime, quality) {
assert.equal(passedCanvas, canvas);
assert.ok(!mime);
assert.ok(!quality);

uploader._handleNewFile = function(file) {
done();
};
};

uploader.addFiles(canvas);
});

it("attempts to convert the passed canvas to a blob, respecting type, quality, and name properties", function(done) {
var uploader = new qq.FineUploaderBasic({
request: {
endpoint: "/test/endpoint"
}
}),
canvas = document.createElement("canvas"),
canvasWrapper = {
canvas: canvas,
type: "foobar",
quality: 3,
name: "mycanvas"
};

qq.canvasToBlob = function(passedCanvas, mime, quality) {
assert.equal(passedCanvas, canvas);
assert.equal(mime, "foobar");
assert.equal(quality, 0.03);

uploader._handleNewFile = function(file) {
assert.equal(file.name, "mycanvas");
done();
};
};

uploader.addFiles(canvasWrapper);
});
});
});
}

0 comments on commit a21d7ac

Please sign in to comment.