@@ -79,5 +79,55 @@ describe('support #141 breakpoint download', (report, done) => {
7979} )
8080
8181describe ( 'support download/upload progress interval and division #140 ' , ( report , done ) => {
82+ let tick = 0
83+ let records = [ ]
84+ let last = Date . now ( )
85+ RNFetchBlob . config ( {
86+ timeout : 30000
87+ } ) . fetch ( 'GET' , `${ TEST_SERVER_URL } /10s-download` , {
88+ 'Cache-Control' : 'no-store'
89+ } )
90+ . progress ( { interval : 1000 } , ( current , total ) => {
91+ records . push ( Date . now ( ) - last )
92+ last = Date . now ( )
93+ console . log ( current , '/' , total , current / total )
94+ tick ++
95+ } )
96+ . then ( ( ) => {
97+ let avg = 0
98+ for ( let i in records ) {
99+ avg += records [ i ]
100+ }
101+ avg /= records . length
102+ report ( < Assert key = "interval > 900" expect = { 900 } comparer = { Comparer . smaller } actual = { avg } /> )
103+ report ( < Assert key = "interval < 1200" expect = { 1200 } comparer = { Comparer . greater } actual = { avg } /> )
104+ upload ( )
105+ } )
106+
107+ function upload ( ) {
108+ let count = 0
109+ let image = RNTest . prop ( 'image' )
110+ RNFetchBlob . config ( {
111+ fileCache : true
112+ } )
113+ . fetch ( 'GET' , `${ TEST_SERVER_URL } /public/6mb-dummy` )
114+ . then ( ( res ) => {
115+ return RNFetchBlob . fetch ( 'POST' , 'https://content.dropboxapi.com/2/files/upload' , {
116+ Authorization : `Bearer ${ DROPBOX_TOKEN } ` ,
117+ 'Dropbox-API-Arg' : '{\"path\": \"/rn-upload/intervalTest.png\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}' ,
118+ 'Content-Type' : 'application/octet-stream' ,
119+ } , RNFetchBlob . wrap ( res . path ( ) ) )
120+ . uploadProgress ( { count : 10 , interval : - 1 } , ( current , total ) => {
121+ count ++
122+ console . log ( current , total )
123+ } )
124+ } )
125+ . then ( ( ) => {
126+ report ( < Assert key = "count is correct" expect = { 10 } actual = { count } /> )
127+ done ( )
128+ } )
129+
130+ }
131+
82132
83133} )
0 commit comments