@@ -244,7 +244,7 @@ if (qqtest.canDownloadFileAsBlob) {
244
244
} ) ;
245
245
246
246
describe ( "file rejection via internal validation" , function ( ) {
247
- function setupUploader ( limits , numBlobs , statusChangeLogic ) {
247
+ function setupUploader ( limits , numBlobsOrTheBlob , statusChangeLogic ) {
248
248
var uploader = new qq . FineUploaderBasic ( {
249
249
autoUpload : false ,
250
250
validation : limits ,
@@ -255,19 +255,24 @@ if (qqtest.canDownloadFileAsBlob) {
255
255
}
256
256
} ) ;
257
257
258
- qqtest . downloadFileAsBlob ( testImgKey , testImgType ) . then ( function ( blob ) {
259
- numBlobs = [ ] . concat ( numBlobs ) ;
260
- qq . each ( numBlobs , function ( idx , num ) {
261
- var blobs = [ ] ,
262
- i ;
263
-
264
- for ( i = 0 ; i < num ; i ++ ) {
265
- blobs . push ( blob ) ;
266
- }
258
+ if ( qq . isBlob ( numBlobsOrTheBlob ) ) {
259
+ uploader . addFiles ( numBlobsOrTheBlob ) ;
260
+ }
261
+ else {
262
+ qqtest . downloadFileAsBlob ( testImgKey , testImgType ) . then ( function ( blob ) {
263
+ numBlobsOrTheBlob = [ ] . concat ( numBlobsOrTheBlob ) ;
264
+ qq . each ( numBlobsOrTheBlob , function ( idx , num ) {
265
+ var blobs = [ ] ,
266
+ i ;
267
+
268
+ for ( i = 0 ; i < num ; i ++ ) {
269
+ blobs . push ( blob ) ;
270
+ }
267
271
268
- uploader . addFiles ( blobs ) ;
272
+ uploader . addFiles ( blobs ) ;
273
+ } ) ;
269
274
} ) ;
270
- } ) ;
275
+ }
271
276
}
272
277
273
278
it ( "prevents too many items from being submitted at once" , function ( done ) {
@@ -318,6 +323,18 @@ if (qqtest.canDownloadFileAsBlob) {
318
323
} ) ;
319
324
} ) ;
320
325
326
+ it ( "prevents empty files from being submitted" , function ( done ) {
327
+ qqtest . downloadFileAsBlob ( "empty.txt" , "text/plain" ) . then ( function ( emptyFile ) {
328
+ setupUploader ( { } , emptyFile , function ( id , oldStatus , newStatus ) {
329
+ if ( newStatus === qq . status . REJECTED ) {
330
+ assert . equal ( this . getUploads ( ) . length , 1 ) ;
331
+ assert . equal ( this . getUploads ( { status : qq . status . REJECTED } ) . length , 1 ) ;
332
+ done ( ) ;
333
+ }
334
+ } ) ;
335
+ } ) ;
336
+ } ) ;
337
+
321
338
it ( "prevents files that are too large from being submitted" , function ( done ) {
322
339
setupUploader ( { sizeLimit : 3265 } , 1 , function ( id , oldStatus , newStatus ) {
323
340
if ( newStatus === qq . status . REJECTED ) {
0 commit comments