aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/blueimp/jquery-file-upload/test/unit.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/blueimp/jquery-file-upload/test/unit.js')
-rw-r--r--vendor/blueimp/jquery-file-upload/test/unit.js297
1 files changed, 150 insertions, 147 deletions
diff --git a/vendor/blueimp/jquery-file-upload/test/unit.js b/vendor/blueimp/jquery-file-upload/test/unit.js
index d9d9fffb9..c70d35dd6 100644
--- a/vendor/blueimp/jquery-file-upload/test/unit.js
+++ b/vendor/blueimp/jquery-file-upload/test/unit.js
@@ -12,7 +12,7 @@
/* global beforeEach, afterEach, describe, it */
/* eslint-disable new-cap */
-(function (expect, $) {
+(function(expect, $) {
'use strict';
var canCreateBlob = !!window.dataURLtoBlob;
@@ -73,29 +73,29 @@
*/
function deleteFiles(files, callback) {
$.when(
- files.map(function (file) {
+ files.map(function(file) {
return $.ajax({
type: file.deleteType,
url: file.deleteUrl
});
})
- ).always(function () {
+ ).always(function() {
callback();
});
}
- beforeEach(function () {
+ beforeEach(function() {
fileGIF = new File([blobGIF], 'example.gif', { type: 'image/gif' });
fileJPEG = new File([blobJPEG], 'example.jpg', { type: 'image/jpeg' });
files = [fileGIF, fileJPEG];
items = [
{
- getAsFile: function () {
+ getAsFile: function() {
return files[0];
}
},
{
- getAsFile: function () {
+ getAsFile: function() {
return files[1];
}
}
@@ -108,71 +108,71 @@
};
});
- afterEach(function (done) {
- $.getJSON(uploadURL).then(function (result) {
+ afterEach(function(done) {
+ $.getJSON(uploadURL).then(function(result) {
deleteFiles(result.files, done);
});
});
- describe('Initialization', function () {
+ describe('Initialization', function() {
var form;
- beforeEach(function () {
+ beforeEach(function() {
form = createFileuploadForm();
});
- afterEach(function () {
+ afterEach(function() {
form.remove();
});
- it('widget', function () {
+ it('widget', function() {
form.fileupload();
expect(form.data('blueimp-fileupload')).to.be.an('object');
});
- it('file input', function () {
+ it('file input', function() {
form.fileupload();
expect(form.fileupload('option', 'fileInput').length).to.equal(1);
});
- it('drop zone', function () {
+ it('drop zone', function() {
form.fileupload();
expect(form.fileupload('option', 'dropZone').length).to.equal(1);
});
- it('paste zone', function () {
+ it('paste zone', function() {
form.fileupload({ pasteZone: document });
expect(form.fileupload('option', 'pasteZone').length).to.equal(1);
});
- it('data attributes', function () {
+ it('data attributes', function() {
form.attr('data-url', 'https://example.org');
form.fileupload();
expect(form.fileupload('option', 'url')).to.equal('https://example.org');
expect(form.data('blueimp-fileupload')).to.be.an('object');
});
- it('event listeners', function () {
+ it('event listeners', function() {
var eventsData = {};
form.fileupload({
autoUpload: false,
pasteZone: document,
- dragover: function () {
+ dragover: function() {
eventsData.dragover = true;
},
- dragenter: function () {
+ dragenter: function() {
eventsData.dragenter = true;
},
- dragleave: function () {
+ dragleave: function() {
eventsData.dragleave = true;
},
- drop: function (e, data) {
+ drop: function(e, data) {
eventsData.drop = data;
},
- paste: function (e, data) {
+ paste: function(e, data) {
eventsData.paste = data;
},
- change: function () {
+ change: function() {
eventsData.change = true;
}
});
@@ -197,40 +197,40 @@
});
});
- describe('API', function () {
+ describe('API', function() {
var form;
- beforeEach(function () {
+ beforeEach(function() {
form = createFileuploadForm().fileupload({
dataType: 'json',
autoUpload: false
});
});
- afterEach(function () {
+ afterEach(function() {
form.remove();
});
- it('destroy', function () {
+ it('destroy', function() {
var eventsData = {};
form.fileupload('option', {
pasteZone: document,
- dragover: function () {
+ dragover: function() {
eventsData.dragover = true;
},
- dragenter: function () {
+ dragenter: function() {
eventsData.dragenter = true;
},
- dragleave: function () {
+ dragleave: function() {
eventsData.dragleave = true;
},
- drop: function (e, data) {
+ drop: function(e, data) {
eventsData.drop = data;
},
- paste: function (e, data) {
+ paste: function(e, data) {
eventsData.paste = data;
},
- change: function () {
+ change: function() {
eventsData.change = true;
}
});
@@ -254,26 +254,26 @@
expect(eventsData.paste).to.equal();
});
- it('disable', function () {
+ it('disable', function() {
var eventsData = {};
form.fileupload('option', {
pasteZone: document,
- dragover: function () {
+ dragover: function() {
eventsData.dragover = true;
},
- dragenter: function () {
+ dragenter: function() {
eventsData.dragenter = true;
},
- dragleave: function () {
+ dragleave: function() {
eventsData.dragleave = true;
},
- drop: function (e, data) {
+ drop: function(e, data) {
eventsData.drop = data;
},
- paste: function (e, data) {
+ paste: function(e, data) {
eventsData.paste = data;
},
- change: function () {
+ change: function() {
eventsData.change = true;
}
});
@@ -298,26 +298,26 @@
expect(eventsData.paste).to.equal();
});
- it('enable', function () {
+ it('enable', function() {
var eventsData = {};
form.fileupload('option', {
pasteZone: document,
- dragover: function () {
+ dragover: function() {
eventsData.dragover = true;
},
- dragenter: function () {
+ dragenter: function() {
eventsData.dragenter = true;
},
- dragleave: function () {
+ dragleave: function() {
eventsData.dragleave = true;
},
- drop: function (e, data) {
+ drop: function(e, data) {
eventsData.drop = data;
},
- paste: function (e, data) {
+ paste: function(e, data) {
eventsData.paste = data;
},
- change: function () {
+ change: function() {
eventsData.change = true;
}
});
@@ -343,9 +343,9 @@
expect(eventsData.paste.files).to.deep.equal(files);
});
- it('option', function () {
+ it('option', function() {
var eventsData = {};
- form.fileupload('option', 'drop', function (e, data) {
+ form.fileupload('option', 'drop', function(e, data) {
eventsData.drop = data;
});
var dropZone = form
@@ -363,9 +363,9 @@
expect(eventsData.drop.files).to.deep.equal(files);
});
- it('add', function () {
+ it('add', function() {
var eventData = [];
- form.fileupload('option', 'add', function (e, data) {
+ form.fileupload('option', 'add', function(e, data) {
eventData.push(data);
});
form.fileupload('add', { files: files });
@@ -374,9 +374,9 @@
expect(eventData[1].files[0]).to.equal(files[1]);
});
- it('send', function (done) {
+ it('send', function(done) {
this.slow(200);
- form.fileupload('send', { files: files }).complete(function (result) {
+ form.fileupload('send', { files: files }).complete(function(result) {
var uploadedFiles = result.responseJSON.files;
expect(uploadedFiles.length).to.equal(2);
expect(uploadedFiles[0].type).to.equal(files[0].type);
@@ -388,20 +388,20 @@
});
});
- describe('Callbacks', function () {
+ describe('Callbacks', function() {
var form;
- beforeEach(function () {
+ beforeEach(function() {
form = createFileuploadForm().fileupload({ dataType: 'json' });
});
- afterEach(function () {
+ afterEach(function() {
form.remove();
});
- it('add', function () {
+ it('add', function() {
var eventData = [];
- form.fileupload('option', 'add', function (e, data) {
+ form.fileupload('option', 'add', function(e, data) {
eventData.push(data);
});
form.fileupload('add', { files: files });
@@ -410,14 +410,14 @@
expect(eventData[1].files[0]).to.equal(files[1]);
});
- it('submit', function (done) {
+ it('submit', function(done) {
this.slow(200);
var eventData = [];
form.fileupload('option', {
- submit: function (e, data) {
+ submit: function(e, data) {
eventData.push(data);
},
- stop: function () {
+ stop: function() {
if (eventData.length < 2) return;
expect(eventData[0].files[0]).to.equal(files[0]);
expect(eventData[1].files[0]).to.equal(files[1]);
@@ -427,14 +427,14 @@
form.fileupload('add', { files: files });
});
- it('send', function (done) {
+ it('send', function(done) {
this.slow(200);
var eventData = [];
form.fileupload('option', {
- send: function (e, data) {
+ send: function(e, data) {
eventData.push(data);
},
- stop: function () {
+ stop: function() {
expect(eventData.length).to.equal(1);
expect(eventData[0].files).to.deep.equal(files);
done();
@@ -443,14 +443,14 @@
form.fileupload('send', { files: files });
});
- it('done', function (done) {
+ it('done', function(done) {
this.slow(200);
var eventData = [];
form.fileupload('option', {
- done: function (e, data) {
+ done: function(e, data) {
eventData.push(data);
},
- stop: function () {
+ stop: function() {
if (eventData.length < 2) return;
expect(eventData[0].result.files.length).to.equal(1);
expect(eventData[1].result.files.length).to.equal(1);
@@ -460,15 +460,15 @@
form.fileupload('add', { files: files });
});
- it('fail', function (done) {
+ it('fail', function(done) {
this.slow(200);
var eventData = [];
form.fileupload('option', {
url: uploadURL + '404',
- fail: function (e, data) {
+ fail: function(e, data) {
eventData.push(data);
},
- stop: function () {
+ stop: function() {
if (eventData.length < 2) return;
expect(eventData[0].result).to.equal();
expect(eventData[1].result).to.equal();
@@ -478,14 +478,14 @@
form.fileupload('add', { files: files });
});
- it('always', function (done) {
+ it('always', function(done) {
this.slow(200);
var eventData = [];
form.fileupload('option', {
- always: function (e, data) {
+ always: function(e, data) {
eventData.push(data);
},
- stop: function () {
+ stop: function() {
if (eventData.length < 2) {
expect(eventData[0].result).to.equal();
form.fileupload('add', { files: [fileGIF] });
@@ -498,17 +498,17 @@
form.fileupload('add', { files: [fileGIF], url: uploadURL + '404' });
});
- it('progress', function (done) {
+ it('progress', function(done) {
this.slow(200);
var loaded;
var total;
form.fileupload('option', {
- progress: function (e, data) {
+ progress: function(e, data) {
loaded = data.loaded;
total = data.total;
expect(loaded).to.be.at.most(total);
},
- stop: function () {
+ stop: function() {
expect(loaded).to.equal(total);
done();
}
@@ -516,21 +516,21 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('progressall', function (done) {
+ it('progressall', function(done) {
this.slow(200);
var loaded;
var total;
var completed = 0;
form.fileupload('option', {
- progressall: function (e, data) {
+ progressall: function(e, data) {
loaded = data.loaded;
total = data.total;
expect(loaded).to.be.at.most(total);
},
- always: function () {
+ always: function() {
completed++;
},
- stop: function () {
+ stop: function() {
if (completed < 2) return;
expect(loaded).to.equal(total);
done();
@@ -539,14 +539,14 @@
form.fileupload('add', { files: files });
});
- it('start', function (done) {
+ it('start', function(done) {
this.slow(200);
var started;
form.fileupload('option', {
- start: function () {
+ start: function() {
started = true;
},
- stop: function () {
+ stop: function() {
expect(started).to.equal(true);
done();
}
@@ -554,21 +554,21 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('stop', function (done) {
+ it('stop', function(done) {
this.slow(200);
form.fileupload('option', {
- stop: function () {
+ stop: function() {
done();
}
});
form.fileupload('add', { files: [fileGIF] });
});
- it('dragover', function () {
+ it('dragover', function() {
var eventsData = {};
form.fileupload('option', {
autoUpload: false,
- dragover: function () {
+ dragover: function() {
eventsData.dragover = true;
}
});
@@ -578,11 +578,11 @@
expect(eventsData.dragover).to.equal(true);
});
- it('dragenter', function () {
+ it('dragenter', function() {
var eventsData = {};
form.fileupload('option', {
autoUpload: false,
- dragenter: function () {
+ dragenter: function() {
eventsData.dragenter = true;
}
});
@@ -592,11 +592,11 @@
expect(eventsData.dragenter).to.equal(true);
});
- it('dragleave', function () {
+ it('dragleave', function() {
var eventsData = {};
form.fileupload('option', {
autoUpload: false,
- dragleave: function () {
+ dragleave: function() {
eventsData.dragleave = true;
}
});
@@ -606,11 +606,11 @@
expect(eventsData.dragleave).to.equal(true);
});
- it('drop', function () {
+ it('drop', function() {
var eventsData = {};
form.fileupload('option', {
autoUpload: false,
- drop: function (e, data) {
+ drop: function(e, data) {
eventsData.drop = data;
}
});
@@ -620,12 +620,12 @@
expect(eventsData.drop.files).to.deep.equal(files);
});
- it('paste', function () {
+ it('paste', function() {
var eventsData = {};
form.fileupload('option', {
autoUpload: false,
pasteZone: document,
- paste: function (e, data) {
+ paste: function(e, data) {
eventsData.paste = data;
}
});
@@ -635,11 +635,11 @@
expect(eventsData.paste.files).to.deep.equal(files);
});
- it('change', function () {
+ it('change', function() {
var eventsData = {};
form.fileupload('option', {
autoUpload: false,
- change: function () {
+ change: function() {
eventsData.change = true;
}
});
@@ -650,20 +650,20 @@
});
});
- describe('Options', function () {
+ describe('Options', function() {
var form;
- beforeEach(function () {
+ beforeEach(function() {
form = createFileuploadForm();
});
- afterEach(function () {
+ afterEach(function() {
form.remove();
});
- it('paramName', function (done) {
+ it('paramName', function(done) {
form.fileupload({
- send: function (e, data) {
+ send: function(e, data) {
expect(data.paramName[0]).to.equal(
form.fileupload('option', 'fileInput').prop('name')
);
@@ -674,9 +674,9 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('url', function (done) {
+ it('url', function(done) {
form.fileupload({
- send: function (e, data) {
+ send: function(e, data) {
expect(data.url).to.equal(form.prop('action'));
done();
return false;
@@ -685,10 +685,10 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('type', function (done) {
+ it('type', function(done) {
form.fileupload({
type: 'PUT',
- send: function (e, data) {
+ send: function(e, data) {
expect(data.type).to.equal('PUT');
done();
return false;
@@ -697,7 +697,7 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('replaceFileInput', function () {
+ it('replaceFileInput', function() {
form.fileupload();
var fileInput = form.fileupload('option', 'fileInput');
fileInput.trigger($.Event('change', eventObject));
@@ -710,10 +710,10 @@
expect(form.fileupload('option', 'fileInput')[0]).to.equal(fileInput[0]);
});
- it('forceIframeTransport', function (done) {
+ it('forceIframeTransport', function(done) {
form.fileupload({
forceIframeTransport: 'PUT',
- send: function (e, data) {
+ send: function(e, data) {
expect(data.dataType.substr(0, 6)).to.equal('iframe');
done();
return false;
@@ -722,10 +722,10 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('singleFileUploads', function (done) {
+ it('singleFileUploads', function(done) {
form.fileupload({
singleFileUploads: false,
- send: function (e, data) {
+ send: function(e, data) {
expect(data.files).to.deep.equal(files);
done();
return false;
@@ -734,12 +734,12 @@
form.fileupload('add', { files: files });
});
- it('limitMultiFileUploads', function (done) {
+ it('limitMultiFileUploads', function(done) {
var completed = 0;
form.fileupload({
singleFileUploads: false,
limitMultiFileUploads: 2,
- send: function (e, data) {
+ send: function(e, data) {
expect(data.files).to.deep.equal(files);
completed++;
if (completed < 2) return;
@@ -750,13 +750,13 @@
form.fileupload('add', { files: files.concat(files) });
});
- it('limitMultiFileUploadSize', function (done) {
+ it('limitMultiFileUploadSize', function(done) {
var completed = 0;
form.fileupload({
singleFileUploads: false,
limitMultiFileUploadSize: files[0].size + files[1].size,
limitMultiFileUploadSizeOverhead: 0,
- send: function (e, data) {
+ send: function(e, data) {
expect(data.files).to.deep.equal(files);
completed++;
if (completed < 2) return;
@@ -767,21 +767,21 @@
form.fileupload('add', { files: files.concat(files) });
});
- it('sequentialUploads', function (done) {
+ it('sequentialUploads', function(done) {
this.slow(400);
var completed = 0;
var events = [];
form.fileupload({
sequentialUploads: true,
dataType: 'json',
- send: function () {
+ send: function() {
events.push('send');
},
- always: function () {
+ always: function() {
events.push('complete');
completed++;
},
- stop: function () {
+ stop: function() {
if (completed === 4) {
expect(events.join(',')).to.equal(
[
@@ -802,36 +802,39 @@
form.fileupload('add', { files: files.concat(files) });
});
- it('limitConcurrentUploads', function (done) {
+ it('limitConcurrentUploads', function(done) {
this.slow(800);
var completed = 0;
var loadCount = 0;
form.fileupload({
limitConcurrentUploads: 2,
dataType: 'json',
- send: function () {
+ send: function() {
loadCount++;
expect(loadCount).to.be.at.most(2);
},
- always: function () {
+ always: function() {
completed++;
loadCount--;
},
- stop: function () {
+ stop: function() {
if (completed === 8) {
done();
}
}
});
form.fileupload('add', {
- files: files.concat(files).concat(files).concat(files)
+ files: files
+ .concat(files)
+ .concat(files)
+ .concat(files)
});
});
- it('multipart', function (done) {
+ it('multipart', function(done) {
form.fileupload({
multipart: false,
- send: function (e, data) {
+ send: function(e, data) {
expect(data.contentType).to.equal(fileGIF.type);
expect(data.headers['Content-Disposition']).to.equal(
'attachment; filename="' + fileGIF.name + '"'
@@ -843,10 +846,10 @@
form.fileupload('add', { files: [fileGIF] });
});
- it('uniqueFilenames', function (done) {
+ it('uniqueFilenames', function(done) {
form.fileupload({
uniqueFilenames: {},
- send: function (e, data) {
+ send: function(e, data) {
var formFiles = data.data.getAll('files[]');
expect(formFiles[0].name).to.equal(fileGIF.name);
expect(formFiles[1].name).to.equal(
@@ -862,27 +865,27 @@
form.fileupload('send', { files: [fileGIF, fileGIF, fileGIF] });
});
- it('maxChunkSize', function (done) {
+ it('maxChunkSize', function(done) {
this.slow(400);
var events = [];
form.fileupload({
maxChunkSize: 32,
dataType: 'json',
- chunkbeforesend: function () {
+ chunkbeforesend: function() {
events.push('chunkbeforesend');
},
- chunksend: function () {
+ chunksend: function() {
events.push('chunksend');
},
- chunkdone: function () {
+ chunkdone: function() {
events.push('chunkdone');
},
- done: function (e, data) {
+ done: function(e, data) {
var uploadedFile = data.result.files[0];
expect(uploadedFile.type).to.equal(fileGIF.type);
expect(uploadedFile.size).to.equal(fileGIF.size);
},
- stop: function () {
+ stop: function() {
expect(events.join(',')).to.equal(
[
'chunkbeforesend',
@@ -905,15 +908,15 @@
form.fileupload('send', { files: [fileGIF] });
});
- it('acceptFileTypes', function (done) {
+ it('acceptFileTypes', function(done) {
var processData;
form.fileupload({
acceptFileTypes: /^image\/gif$/,
singleFileUploads: false,
- processalways: function (e, data) {
+ processalways: function(e, data) {
processData = data;
},
- processstop: function () {
+ processstop: function() {
expect(processData.files[0].error).to.equal();
expect(processData.files[1].error).to.equal(
form.fileupload('option').i18n('acceptFileTypes')
@@ -924,15 +927,15 @@
form.fileupload('add', { files: files });
});
- it('maxFileSize', function (done) {
+ it('maxFileSize', function(done) {
var processData;
form.fileupload({
maxFileSize: 200,
singleFileUploads: false,
- processalways: function (e, data) {
+ processalways: function(e, data) {
processData = data;
},
- processstop: function () {
+ processstop: function() {
expect(processData.files[0].error).to.equal();
expect(processData.files[1].error).to.equal(
form.fileupload('option').i18n('maxFileSize')
@@ -943,15 +946,15 @@
form.fileupload('add', { files: files });
});
- it('minFileSize', function (done) {
+ it('minFileSize', function(done) {
var processData;
form.fileupload({
minFileSize: 200,
singleFileUploads: false,
- processalways: function (e, data) {
+ processalways: function(e, data) {
processData = data;
},
- processstop: function () {
+ processstop: function() {
expect(processData.files[0].error).to.equal(
form.fileupload('option').i18n('minFileSize')
);
@@ -962,18 +965,18 @@
form.fileupload('add', { files: files });
});
- it('maxNumberOfFiles', function (done) {
+ it('maxNumberOfFiles', function(done) {
var processData;
form.fileupload({
maxNumberOfFiles: 2,
- getNumberOfFiles: function () {
+ getNumberOfFiles: function() {
return 2;
},
singleFileUploads: false,
- processalways: function (e, data) {
+ processalways: function(e, data) {
processData = data;
},
- processstop: function () {
+ processstop: function() {
expect(processData.files[0].error).to.equal(
form.fileupload('option').i18n('maxNumberOfFiles')
);