@@ -26,6 +26,8 @@ class PoUploadComponent extends PoUploadBaseComponent {
2626 constructor ( uploadService : PoUploadService ) {
2727 super ( uploadService ) ;
2828 }
29+
30+ sendFeedback ( ) { }
2931}
3032
3133describe ( 'PoUploadBaseComponent:' , ( ) => {
@@ -291,6 +293,32 @@ describe('PoUploadBaseComponent:', () => {
291293 expect ( component [ 'parseFiles' ] ( < any > files ) ) . toEqual ( < any > files ) ;
292294 } ) ;
293295
296+ it ( 'should set `quantityNotAllowed` with `filesLength - fileRestrictions.maxFiles` if `isExceededFileLimit` returns `true`' , ( ) => {
297+
298+ const files = [
299+ { name : 'file1' } ,
300+ { name : 'file2' } ,
301+ { name : 'file3' }
302+ ] ;
303+
304+ component . fileRestrictions = { maxFiles : 2 } ;
305+
306+ spyOn ( component , < any > 'isExceededFileLimit' ) . and . returnValue ( true ) ;
307+
308+ component [ 'parseFiles' ] ( < any > files ) ;
309+
310+ expect ( component [ 'quantityNotAllowed' ] ) . toBe ( 1 ) ;
311+ } ) ;
312+
313+ it ( 'should call `sendFeedback`' , ( ) => {
314+
315+ spyOn ( component , 'sendFeedback' ) ;
316+
317+ component [ 'parseFiles' ] ( < any > [ { name : 'file1' } ] ) ;
318+
319+ expect ( component . sendFeedback ) . toHaveBeenCalled ( ) ;
320+ } ) ;
321+
294322 } ) ;
295323
296324 it ( 'checkRestrictions: should be check restrictions' , ( ) => {
@@ -323,6 +351,48 @@ describe('PoUploadBaseComponent:', () => {
323351 expect ( restrictionsOk ) . toBeTruthy ( ) ;
324352 } ) ;
325353
354+ it ( 'checkRestrictions: should sum `sizeNotAllowed` if `file.size` is less than `minFileSize`' , ( ) => {
355+
356+ const mockFile = {
357+ size : 2
358+ } ;
359+
360+ component [ 'sizeNotAllowed' ] = 2 ;
361+ component [ 'fileRestrictions' ] = { minFileSize : 3 } ;
362+
363+ component [ 'checkRestrictions' ] ( < any > mockFile ) ;
364+
365+ expect ( component [ 'sizeNotAllowed' ] ) . toBe ( 3 ) ;
366+ } ) ;
367+
368+ it ( 'checkRestrictions: should sum `sizeNotAllowed` if `file.size` is greater than `maxFileSize`' , ( ) => {
369+
370+ const mockFile = {
371+ size : 3
372+ } ;
373+
374+ component [ 'sizeNotAllowed' ] = 2 ;
375+ component [ 'fileRestrictions' ] = { maxFileSize : 2 } ;
376+
377+ component [ 'checkRestrictions' ] ( < any > mockFile ) ;
378+
379+ expect ( component [ 'sizeNotAllowed' ] ) . toBe ( 3 ) ;
380+ } ) ;
381+
382+ it ( 'checkRestrictions: shouldn`t sum `sizeNotAllowed` if `isAcceptSize` is `true`' , ( ) => {
383+
384+ const mockFile = {
385+ size : 2
386+ } ;
387+
388+ component [ 'sizeNotAllowed' ] = 2 ;
389+ component [ 'fileRestrictions' ] = { maxFileSize : 2 } ;
390+
391+ component [ 'checkRestrictions' ] ( < any > mockFile ) ;
392+
393+ expect ( component [ 'sizeNotAllowed' ] ) . toBe ( 2 ) ;
394+ } ) ;
395+
326396 it ( 'existsFileSameName: ' , ( ) => {
327397 expect ( component [ 'existsFileSameName' ] ( file , [ file ] ) ) . toBeTruthy ( ) ;
328398 } ) ;
@@ -377,6 +447,36 @@ describe('PoUploadBaseComponent:', () => {
377447 expect ( files . splice ) . not . toHaveBeenCalled ( ) ;
378448 } ) ;
379449
450+ describe ( 'initRestrictions:' , ( ) => {
451+
452+ it ( 'should return falsy if restrictions is undefined' , ( ) => {
453+ const restrictions = undefined ;
454+
455+ expect ( component [ 'initRestrictions' ] ( restrictions ) ) . toBeFalsy ( ) ;
456+ } ) ;
457+
458+ it ( 'should return default `minFileSize`' , ( ) => {
459+ const restrictions = { maxFileSize : 1 } ;
460+ const expectedResult = { maxFileSize : 1 , minFileSize : 0 } ;
461+
462+ expect ( component [ 'initRestrictions' ] ( restrictions ) ) . toEqual ( expectedResult ) ;
463+ } ) ;
464+
465+ it ( 'should return default `maxFileSize`' , ( ) => {
466+ const restrictions = { minFileSize : 2 } ;
467+ const expectedResult = { minFileSize : 2 , maxFileSize : 31457280 } ;
468+
469+ expect ( component [ 'initRestrictions' ] ( restrictions ) ) . toEqual ( expectedResult ) ;
470+ } ) ;
471+
472+ it ( 'should concat default values with file restrictions' , ( ) => {
473+ const restrictions = { allowedExtensions : [ 'pdf' ] , maxFiles : 2 } ;
474+ const expectedResult = { ...restrictions , minFileSize : 0 , maxFileSize : 31457280 } ;
475+
476+ expect ( component [ 'initRestrictions' ] ( restrictions ) ) . toEqual ( expectedResult ) ;
477+ } ) ;
478+ } ) ;
479+
380480 it ( 'isAllowedExtension: should allowed extensions' , ( ) => {
381481 const isAllowed = component [ 'isAllowedExtension' ] ( '.pdf' , [ '.txt' , '.PDF' ] ) ;
382482 expect ( isAllowed ) . toBeTruthy ( ) ;
@@ -448,6 +548,33 @@ describe('PoUploadBaseComponent:', () => {
448548 expectPropertiesValues ( component , 'disabled' , invalidValues , false ) ;
449549 } ) ;
450550
551+ it ( 'fileRestrictions: should set `fileRestrictions` calling `initRestrictions` and call `setAllowedExtensions`' , ( ) => {
552+
553+ const restrictions = { minFileSize : 2 } ;
554+ const expectedResult = { minFileSize : 2 , maxFileSize : 31457280 } ;
555+
556+ spyOn ( component , < any > 'initRestrictions' ) . and . callThrough ( ) ;
557+ spyOn ( component , < any > 'setAllowedExtensions' ) ;
558+
559+ component . fileRestrictions = restrictions ;
560+
561+ expect ( component . fileRestrictions ) . toEqual ( expectedResult ) ;
562+ expect ( component [ 'initRestrictions' ] ) . toHaveBeenCalled ( ) ;
563+ expect ( component [ 'setAllowedExtensions' ] ) . toHaveBeenCalled ( ) ;
564+ } ) ;
565+
566+ it ( 'hideRestrictionsInfo: should set `hideRestrictionsInfo` with valid values' , ( ) => {
567+ const validValues = [ '' , true , 1 , [ ] , { } , 'true' ] ;
568+
569+ expectPropertiesValues ( component , 'hideRestrictionsInfo' , validValues , true ) ;
570+ } ) ;
571+
572+ it ( 'hideRestrictionsInfo: should set `hideRestrictionsInfo` to false with invalid values' , ( ) => {
573+ const invalidValues = [ null , undefined , NaN , false , 0 , 'false' , 'teste' ] ;
574+
575+ expectPropertiesValues ( component , 'hideRestrictionsInfo' , invalidValues , false ) ;
576+ } ) ;
577+
451578 it ( 'p-literals: should be in portuguese if browser is setted with an unsupported language' , ( ) => {
452579 spyOn ( utilsFunctions , < any > 'browserLanguage' ) . and . returnValue ( 'ru' ) ;
453580
0 commit comments