@@ -38,4 +38,62 @@ describe('setup', function() {
3838 expect ( resumable . uploadNextChunk ( ) ) . toBe ( false ) ;
3939 } ) ;
4040
41+ describe ( 'assignBrowse' , function ( ) {
42+ it ( 'assign to input' , function ( ) {
43+ var input = document . createElement ( 'input' ) ;
44+ var addFiles = jasmine . createSpy ( 'addFiles' ) ;
45+ resumable . addFiles = addFiles ;
46+ input . type = 'file' ;
47+ resumable . assignBrowse ( input ) ;
48+ expect ( input . hasAttribute ( 'multiple' ) ) . toBeTruthy ( ) ;
49+ expect ( addFiles ) . not . toHaveBeenCalled ( ) ;
50+ input . dispatchEvent ( new Event ( 'change' ) ) ;
51+ expect ( addFiles ) . toHaveBeenCalled ( ) ;
52+ } ) ;
53+
54+ it ( 'assign to div' , function ( ) {
55+ var div = document . createElement ( 'div' ) ;
56+ var addFiles = jasmine . createSpy ( 'addFiles' ) ;
57+ resumable . addFiles = addFiles ;
58+ resumable . assignBrowse ( div ) ;
59+ expect ( div . children . length ) . toBe ( 1 ) ;
60+ var input = div . children [ 0 ] ;
61+ expect ( addFiles ) . not . toHaveBeenCalled ( ) ;
62+ input . dispatchEvent ( new Event ( 'change' ) ) ;
63+ expect ( addFiles ) . toHaveBeenCalled ( ) ;
64+ } ) ;
65+
66+ it ( 'single file' , function ( ) {
67+ var input = document . createElement ( 'input' ) ;
68+ input . type = 'file' ;
69+ resumable . assignBrowse ( input , false , true ) ;
70+ expect ( input . hasAttribute ( 'multiple' ) ) . toBeFalsy ( ) ;
71+ } ) ;
72+
73+ it ( 'directory' , function ( ) {
74+ var input = document . createElement ( 'input' ) ;
75+ input . type = 'file' ;
76+ resumable . assignBrowse ( input , true ) ;
77+ expect ( input . hasAttribute ( 'webkitdirectory' ) ) . toBeTruthy ( ) ;
78+ } ) ;
79+ } ) ;
80+
81+ describe ( 'assignDrop' , function ( ) {
82+ it ( 'assign to div' , function ( ) {
83+ var div = document . createElement ( 'div' ) ;
84+ var addFiles = jasmine . createSpy ( 'addFiles' ) ;
85+ resumable . addFiles = addFiles ;
86+ resumable . assignDrop ( div ) ;
87+ var event = new Event ( 'drop' ) ;
88+ event . dataTransfer = { files : [ ] } ;
89+ div . dispatchEvent ( event ) ;
90+ expect ( addFiles ) . toHaveBeenCalled ( ) ;
91+ expect ( addFiles . callCount ) . toBe ( 1 ) ;
92+
93+ resumable . unAssignDrop ( div ) ;
94+ div . dispatchEvent ( event ) ;
95+ expect ( addFiles . callCount ) . toBe ( 1 ) ;
96+ } ) ;
97+ } ) ;
98+
4199} ) ;
0 commit comments