@@ -17,7 +17,7 @@ describe('Downloader', function() {
1717 setLabel : function ( label ) { } ,
1818 setComplete : function ( ) { } ,
1919 setTotalDownloadSize : function ( size ) { } ,
20- downloaded : function ( amt , time ) { }
20+ downloaded : function ( amt , time ) { } ,
2121 } ;
2222 let sandbox ;
2323 let succ = function ( ) { } ;
@@ -39,24 +39,38 @@ describe('Downloader', function() {
3939 it ( 'responseHandler should set the total download size' , function ( ) {
4040 downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } ) ;
4141 let response = { headers : { 'content-length' : 1024 } } ;
42- let spy = sandbox . spy ( fakeProgress , 'setTotalDownloadSize' ) ;
4342
4443 downloader . responseHandler ( response ) ;
4544
4645 expect ( downloader . downloadSize ) . to . equal ( 1024 ) ;
47- expect ( spy ) . to . have . been . calledOnce ;
48- expect ( spy ) . to . have . been . calledWith ( 1024 ) ;
4946 } ) ;
5047
51- it ( 'dataHandler should update the progress' , function ( ) {
48+ it ( 'dataHandler should update the progress once time threshold is reached ' , function ( ) {
5249 downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } ) ;
53- let data = { length : 1024 } ;
54- let spy = sandbox . spy ( fakeProgress , 'downloaded' ) ;
50+ fakeProgress . totalSize = 1024 ;
51+
52+ let data = { length : 512 } ;
53+ let spy = sandbox . spy ( fakeProgress , 'setCurrent' ) ;
5554
55+ downloader . received = 1 ;
5656 downloader . dataHandler ( data ) ;
5757
5858 expect ( spy ) . to . have . been . calledOnce ;
59- expect ( spy ) . to . have . been . calledWith ( 1024 ) ;
59+ expect ( spy ) . to . have . been . calledWith ( data . length ) ;
60+ } ) ;
61+
62+ it ( 'dataHandler should not update the progress before time threshold is reached' , function ( ) {
63+ downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } ) ;
64+ fakeProgress . totalSize = 1024 ;
65+
66+ let data = { length : 512 } ;
67+ let spy = sandbox . spy ( fakeProgress , 'setCurrent' ) ;
68+
69+ downloader . received = 1 ;
70+ downloader . lastTime = Date . now ( ) + 9999999999 ;
71+ downloader . dataHandler ( data ) ;
72+
73+ expect ( spy ) . not . called ;
6074 } ) ;
6175
6276 it ( 'errorHandler should close the stream' , function ( ) {
@@ -213,7 +227,7 @@ describe('Downloader', function() {
213227 let error = new Error ( 'something bad happened' ) ;
214228
215229 let stream = new Writable ( ) ;
216- downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } , 1 , 2 ) ;
230+ downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } , 2 ) ;
217231 downloader . setWriteStream ( stream ) ;
218232 let errorHandler = sandbox . stub ( downloader , 'errorHandler' ) ;
219233 let successSpy = sandbox . spy ( downloader , 'success' ) ;
@@ -232,7 +246,7 @@ describe('Downloader', function() {
232246 let error = new Error ( 'something bad happened' ) ;
233247
234248 let stream = new Writable ( ) ;
235- downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } , 1 , 2 ) ;
249+ downloader = new Downloader ( fakeProgress , function ( ) { } , function ( ) { } , 2 ) ;
236250 downloader . setWriteStream ( stream ) ;
237251 let successHandler = sandbox . stub ( downloader , 'success' ) ;
238252 downloader . download ( options ) ;
0 commit comments