@@ -122,41 +122,53 @@ describe "Dropzone", ->
122
122
Dropzone .discover ()
123
123
expect (element3 .dropzone ).to .not .be .ok
124
124
125
- describe " Dropzone.isValidMimeType ()" , ->
126
- it " should return true if called without acceptedMimeTypes " , ->
127
- Dropzone .isValidMimeType ( " some/type" , null ).should .be .ok
125
+ describe " Dropzone.isValidFile ()" , ->
126
+ it " should return true if called without acceptedFiles " , ->
127
+ Dropzone .isValidFile ({ type : " some/type" } , null ).should .be .ok
128
128
129
129
it " should properly validate if called with concrete mime types" , ->
130
130
acceptedMimeTypes = " text/html,image/jpeg,application/json"
131
131
132
- Dropzone .isValidMimeType ( " text/html" , acceptedMimeTypes).should .be .ok
133
- Dropzone .isValidMimeType ( " image/jpeg" , acceptedMimeTypes).should .be .ok
134
- Dropzone .isValidMimeType ( " application/json" , acceptedMimeTypes).should .be .ok
135
- Dropzone .isValidMimeType ( " image/bmp" , acceptedMimeTypes).should .not .be .ok
132
+ Dropzone .isValidFile ({ type : " text/html" } , acceptedMimeTypes).should .be .ok
133
+ Dropzone .isValidFile ({ type : " image/jpeg" } , acceptedMimeTypes).should .be .ok
134
+ Dropzone .isValidFile ({ type : " application/json" } , acceptedMimeTypes).should .be .ok
135
+ Dropzone .isValidFile ({ type : " image/bmp" } , acceptedMimeTypes).should .not .be .ok
136
136
137
137
it " should properly validate if called with base mime types" , ->
138
138
acceptedMimeTypes = " text/*,image/*,application/*"
139
139
140
- Dropzone .isValidMimeType ( " text/html" , acceptedMimeTypes).should .be .ok
141
- Dropzone .isValidMimeType ( " image/jpeg" , acceptedMimeTypes).should .be .ok
142
- Dropzone .isValidMimeType ( " application/json" , acceptedMimeTypes).should .be .ok
143
- Dropzone .isValidMimeType ( " image/bmp" , acceptedMimeTypes).should .be .ok
144
- Dropzone .isValidMimeType ( " some/type" , acceptedMimeTypes).should .not .be .ok
140
+ Dropzone .isValidFile ({ type : " text/html" } , acceptedMimeTypes).should .be .ok
141
+ Dropzone .isValidFile ({ type : " image/jpeg" } , acceptedMimeTypes).should .be .ok
142
+ Dropzone .isValidFile ({ type : " application/json" } , acceptedMimeTypes).should .be .ok
143
+ Dropzone .isValidFile ({ type : " image/bmp" } , acceptedMimeTypes).should .be .ok
144
+ Dropzone .isValidFile ({ type : " some/type" } , acceptedMimeTypes).should .not .be .ok
145
145
146
146
it " should properly validate if called with mixed mime types" , ->
147
147
acceptedMimeTypes = " text/*,image/jpeg,application/*"
148
148
149
- Dropzone .isValidMimeType ( " text/html" , acceptedMimeTypes).should .be .ok
150
- Dropzone .isValidMimeType ( " image/jpeg" , acceptedMimeTypes).should .be .ok
151
- Dropzone .isValidMimeType ( " image/bmp" , acceptedMimeTypes).should .not .be .ok
152
- Dropzone .isValidMimeType ( " application/json" , acceptedMimeTypes).should .be .ok
153
- Dropzone .isValidMimeType ( " some/type" , acceptedMimeTypes).should .not .be .ok
149
+ Dropzone .isValidFile ({ type : " text/html" } , acceptedMimeTypes).should .be .ok
150
+ Dropzone .isValidFile ({ type : " image/jpeg" } , acceptedMimeTypes).should .be .ok
151
+ Dropzone .isValidFile ({ type : " image/bmp" } , acceptedMimeTypes).should .not .be .ok
152
+ Dropzone .isValidFile ({ type : " application/json" } , acceptedMimeTypes).should .be .ok
153
+ Dropzone .isValidFile ({ type : " some/type" } , acceptedMimeTypes).should .not .be .ok
154
154
155
155
it " should properly validate even with spaces in between" , ->
156
156
acceptedMimeTypes = " text/html , image/jpeg, application/json"
157
157
158
- Dropzone .isValidMimeType (" text/html" , acceptedMimeTypes).should .be .ok
159
- Dropzone .isValidMimeType (" image/jpeg" , acceptedMimeTypes).should .be .ok
158
+ Dropzone .isValidFile ({ type : " text/html" }, acceptedMimeTypes).should .be .ok
159
+ Dropzone .isValidFile ({ type : " image/jpeg" }, acceptedMimeTypes).should .be .ok
160
+
161
+ it " should properly validate extensions" , ->
162
+ acceptedMimeTypes = " text/html , image/jpeg, .pdf ,.png"
163
+
164
+ Dropzone .isValidFile ({ name : " somxsfsd" , type : " text/html" }, acceptedMimeTypes).should .be .ok
165
+ Dropzone .isValidFile ({ name : " somesdfsdf" , type : " image/jpeg" }, acceptedMimeTypes).should .be .ok
166
+ Dropzone .isValidFile ({ name : " somesdfadfadf" , type : " application/json" }, acceptedMimeTypes).should .not .be .ok
167
+ Dropzone .isValidFile ({ name : " some-file file.pdf" , type : " random/type" }, acceptedMimeTypes).should .be .ok
168
+ # .pdf has to be in the end
169
+ Dropzone .isValidFile ({ name : " some-file.pdf file.gif" , type : " random/type" }, acceptedMimeTypes).should .not .be .ok
170
+ Dropzone .isValidFile ({ name : " some-file file.png" , type : " random/type" }, acceptedMimeTypes).should .be .ok
171
+
160
172
161
173
describe " Dropzone.getElement() / getElements()" , ->
162
174
tmpElements = [ ]
@@ -221,9 +233,9 @@ describe "Dropzone", ->
221
233
dropzone = new Dropzone element, url : " url"
222
234
expect (-> new Dropzone element, url : " url" ).to .throw " Dropzone already attached."
223
235
224
- it " should throw an exception if both acceptParameter and acceptedMimeTypes are specified" , ->
236
+ it " should throw an exception if both acceptedFiles and acceptedMimeTypes are specified" , ->
225
237
element = document .createElement " div"
226
- expect (-> dropzone = new Dropzone element, url : " test" , acceptParameter : " param" , acceptedMimeTypes : " types" ).to .throw " You can't provide both 'acceptParameter ' and 'acceptedMimeTypes'. 'acceptParameter ' is deprecated."
238
+ expect (-> dropzone = new Dropzone element, url : " test" , acceptedFiles : " param" , acceptedMimeTypes : " types" ).to .throw " You can't provide both 'acceptedFiles ' and 'acceptedMimeTypes'. 'acceptedMimeTypes ' is deprecated."
227
239
228
240
it " should set itself as element.dropzone" , ->
229
241
element = document .createElement " div"
@@ -260,6 +272,12 @@ describe "Dropzone", ->
260
272
forceFallback : on
261
273
fallback : -> done ()
262
274
275
+ it " should set acceptedFiles if deprecated acceptedMimetypes option has been passed" , ->
276
+ dropzone = new Dropzone element,
277
+ url : " /some/other/url"
278
+ acceptedMimeTypes : " my/type"
279
+ dropzone .options .acceptedFiles .should .equal " my/type"
280
+
263
281
describe " options.clickable" , ->
264
282
clickableElement = null
265
283
dropzone = null
@@ -293,7 +311,7 @@ describe "Dropzone", ->
293
311
describe " clickable" , ->
294
312
295
313
dropzones =
296
- " using acceptParameter " : new Dropzone (Dropzone .createElement (""" <form action="/"></form>""" ), { clickable : yes , acceptParameter : " audio/*,video/*" })
314
+ " using acceptedFiles " : new Dropzone (Dropzone .createElement (""" <form action="/"></form>""" ), { clickable : yes , acceptedFiles : " audio/*,video/*" })
297
315
" using acceptedMimeTypes" : new Dropzone (Dropzone .createElement (""" <form action="/"></form>""" ), { clickable : yes , acceptedMimeTypes : " audio/*,video/*" })
298
316
299
317
it " should not add an accept attribute if no acceptParameter" , ->
@@ -414,13 +432,13 @@ describe "Dropzone", ->
414
432
it " shouldn't pass if the filesize is too big" , ->
415
433
dropzone .accept { size : 10 * 1024 * 1024 , type : " audio/mp3" }, (err ) -> err .should .eql " File is too big (10MB). Max filesize: 4MB."
416
434
417
- it " should properly accept files which mime types are listed in acceptedMimeTypes " , ->
435
+ it " should properly accept files which mime types are listed in acceptedFiles " , ->
418
436
419
437
dropzone .accept { type : " audio/mp3" }, (err ) -> expect (err).to .be .undefined
420
438
dropzone .accept { type : " image/png" }, (err ) -> expect (err).to .be .undefined
421
439
dropzone .accept { type : " audio/wav" }, (err ) -> expect (err).to .be .undefined
422
440
423
- it " should properly reject files when the mime type isn't listed in acceptedMimeTypes " , ->
441
+ it " should properly reject files when the mime type isn't listed in acceptedFiles " , ->
424
442
425
443
dropzone .accept { type : " image/jpeg" }, (err ) -> err .should .eql " You can't upload files of this type."
426
444
0 commit comments