From 53b397dfb83f4f0112aca63af2e7eaac307a7220 Mon Sep 17 00:00:00 2001 From: rnicholus Date: Mon, 16 Oct 2017 15:02:26 -0500 Subject: [PATCH] test for per-file chunk size support --- test/unit/chunked-uploads.js | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/unit/chunked-uploads.js b/test/unit/chunked-uploads.js index 136dfca69..7972dd4ea 100644 --- a/test/unit/chunked-uploads.js +++ b/test/unit/chunked-uploads.js @@ -935,5 +935,59 @@ if (qqtest.canDownloadFileAsBlob) { }, { omitDefaultParams: true }); }); }); + + describe("variable chunk size", function() { + it("allows an alternate chunk size to be specified for each file", function(done) { + var uploader = new qq.FineUploaderBasic({ + maxConnections: 1, + request: { + endpoint: testUploadEndpoint + }, + chunking: { + enabled: true, + partSize: function(id) { + if (id === 0) { + return expectedFileSize / 2; + } + + return expectedFileSize / 3; + } + }, + callbacks: { + onUploadChunk: function(id, name, chunkData) { + setTimeout(function() { + var uploadChunkRequest; + + if (id === 0) { + uploadChunkRequest = fileTestHelper.getRequests()[chunkData.partIndex]; + } + else if (id === 1) { + uploadChunkRequest = fileTestHelper.getRequests()[2 + chunkData.partIndex]; + } + + uploadChunkRequest.respond(200, null, JSON.stringify({success: true})); + }, 10); + + if (id === 0) { + assert.equal(chunkData.totalParts, 2); + } + else if (id === 1) { + assert.equal(chunkData.totalParts, 3); + + if (chunkData.partIndex === 2) { + done(); + } + } + } + } + }); + + qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) { + fileTestHelper.mockXhr(); + uploader.addFiles({name: "test0", blob: blob}); + uploader.addFiles({name: "test1", blob: blob}); + }); + }); + }); }); }