Skip to content

Commit 0fe562b

Browse files
committed
+ 'postName' option
1 parent 17ea970 commit 0fe562b

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

tests/tests.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module('FileAPI');
22

33
(function (){
4+
var serverUrl = 'http://rubaxa.org/FileAPI/server/ctrl.php';
45
var uploadForm = document.forms.upload;
56
var base64_1px_gif = 'R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
67
var browser = (navigator.userAgent.match(/(phantomjs|safari|firefox|chrome)/i) || ['', 'chrome'])[1].toLowerCase();
@@ -216,7 +217,7 @@ module('FileAPI');
216217
stop();
217218

218219
FileAPI.upload({
219-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
220+
url: serverUrl,
220221
data: { str: 'foo', num: 1, array: [1, 2, 3], object: { foo: 'bar' } },
221222
complete: function (err, xhr){
222223
var res = FileAPI.parseJSON(xhr.responseText).data._REQUEST;
@@ -238,29 +239,66 @@ module('FileAPI');
238239
});
239240

240241

242+
test('upload + postName (default)', function (){
243+
stop();
244+
FileAPI.upload({
245+
url: serverUrl,
246+
files: FileAPI.getFiles(uploadForm['1px.gif'])[0],
247+
complete: function (err, xhr){
248+
var res = FileAPI.parseJSON(xhr.responseText);
249+
equal(res.data._FILES['files'].name, '1px.gif', 'file.name');
250+
start();
251+
}
252+
});
253+
});
254+
255+
256+
test('upload + postName (gif)', function (){
257+
stop();
258+
FileAPI.upload({
259+
url: serverUrl,
260+
files: FileAPI.getFiles(uploadForm['1px.gif']),
261+
postName: 'gif',
262+
complete: function (err, xhr){
263+
var res = FileAPI.parseJSON(xhr.responseText);
264+
equal(res.data._FILES['gif'].name, '1px.gif', 'file.name');
265+
start();
266+
}
267+
});
268+
});
269+
241270

242271
test('upload input', function (){
243-
expect(13);
272+
var events = [];
273+
expect(12);
244274

245275
stop();
246276
FileAPI.upload({
247-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
277+
url: serverUrl,
248278
data: { foo: 'bar' },
249279
files: uploadForm['1px.gif'],
250-
upload: function (){
251-
ok(true, 'upload event');
252-
},
253280
prepare: function (file, options){
254281
options.data.bar = 'qux';
282+
events.push('prepare');
283+
},
284+
upload: function (){
285+
events.push('upload');
255286
},
256287
fileupload: function (file/**Object*/, xhr/**Object*/, options/**Object*/){
288+
events.push('fileupload');
257289
equal(file.name, '1px.gif', 'name');
258290
equal(options.data.foo, 'bar', 'data.foo');
259291
equal(options.data.bar, 'qux', 'data.qux');
260292
},
293+
fileprogress: function (evt){
294+
if( evt.loaded == evt.total ){
295+
events.push('fileprogress');
296+
}
297+
},
261298
filecomplete: function (err, xhr){
262299
var res = FileAPI.parseJSON(xhr.responseText);
263300

301+
events.push('filecomplete');
264302
equal(res.data._REQUEST.foo, 'bar');
265303
equal(res.data._REQUEST.bar, 'qux');
266304

@@ -269,16 +307,23 @@ module('FileAPI');
269307
equal(res.data._FILES['1px_gif'].name, '1px.gif', 'file.name');
270308
equal(type, /application/.test(type) ? 'application/octet-stream' : 'image/gif', 'file.type');
271309
}
310+
else {
311+
ok(false, '1px_gif files');
312+
}
272313

273314
if( res.images['1px_gif'] ){
274315
equal(res.images['1px_gif'].dataURL, 'data:image/gif;base64,' + base64_1px_gif, 'dataURL');
275316
equal(res.images['1px_gif'].mime, 'image/gif', 'mime');
276317
equal(res.images['1px_gif'].width, 1, 'width');
277318
equal(res.images['1px_gif'].height, 1, 'height');
278319
}
320+
else {
321+
ok(false, '1px_gif images');
322+
}
279323
},
280324
complete: function (err, xhr){
281-
ok(true, 'complete event');
325+
events.push('complete');
326+
equal(events.join('->'), 'prepare->upload->fileupload->fileprogress->filecomplete->complete');
282327
start();
283328
}
284329
});
@@ -289,7 +334,7 @@ module('FileAPI');
289334
test('upload file', function (){
290335
stop();
291336
FileAPI.upload({
292-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
337+
url: serverUrl,
293338
files: { text: FileAPI.getFiles(uploadForm['hello.txt']) },
294339
complete: function (err, res){
295340
start();
@@ -314,7 +359,7 @@ module('FileAPI');
314359
;
315360

316361
FileAPI.upload({
317-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
362+
url: serverUrl,
318363
files: uploadForm['multiple'],
319364
fileupload: function (){
320365
_start++;
@@ -354,7 +399,7 @@ module('FileAPI');
354399

355400
stop();
356401
FileAPI.upload({
357-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
402+
url: serverUrl,
358403
files: { image: image },
359404
complete: function (err, res){
360405
var res = FileAPI.parseJSON(res.responseText);
@@ -373,7 +418,7 @@ module('FileAPI');
373418

374419
stop();
375420
FileAPI.upload({
376-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
421+
url: serverUrl,
377422
files: { image: file },
378423
imageTransform: {
379424
width: 100,
@@ -398,7 +443,7 @@ module('FileAPI');
398443

399444
stop();
400445
FileAPI.upload({
401-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
446+
url: serverUrl,
402447
files: { image: file },
403448
imageTransform: {
404449
'jpeg': {
@@ -435,7 +480,7 @@ module('FileAPI');
435480

436481
stop();
437482
FileAPI.upload({
438-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
483+
url: serverUrl,
439484
files: { image: file },
440485
imageTransform: {
441486
'180deg': {
@@ -468,7 +513,7 @@ module('FileAPI');
468513
var shot = cam.shot();
469514

470515
FileAPI.upload({
471-
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
516+
url: serverUrl,
472517
files: { shot: shot },
473518
complete: function (err, res){
474519
var res = FileAPI.parseJSON(res.responseText);

0 commit comments

Comments
 (0)