@@ -5,7 +5,10 @@ import FineUploaderTraditional from 'fine-uploader-wrappers'
55import PauseResumeButton from 'src/pause-resume-button'
66
77describe ( '<PauseResumeButton />' , ( ) => {
8- let statusChangeCallback , uploadChunkCallback , uploader
8+ let resumeCallback ,
9+ statusChangeCallback ,
10+ uploadChunkSuccessCallback ,
11+ uploader
912
1013 beforeEach ( ( ) => {
1114 uploader = new FineUploaderTraditional ( { options : { } } )
@@ -14,8 +17,11 @@ describe('<PauseResumeButton />', () => {
1417 if ( type === 'statusChange' ) {
1518 statusChangeCallback = callback
1619 }
17- else if ( type === 'uploadChunk' ) {
18- uploadChunkCallback = callback
20+ else if ( type === 'uploadChunkSuccess' ) {
21+ uploadChunkSuccessCallback = callback
22+ }
23+ else if ( type === 'resume' ) {
24+ resumeCallback = callback
1925 }
2026 } )
2127 } )
@@ -25,11 +31,10 @@ describe('<PauseResumeButton />', () => {
2531 < PauseResumeButton id = { 0 } uploader = { uploader } />
2632 )
2733
28- uploadChunkCallback ( 0 , 'foo.jpeg' , { partIndex : 0 } )
2934 let button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-button' ) [ 0 ]
3035 expect ( button ) . toBeFalsy ( )
3136
32- uploadChunkCallback ( 0 , 'foo.jpeg' , { partIndex : 1 } )
37+ uploadChunkSuccessCallback ( 0 , { partIndex : 3 } )
3338 button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-button' ) [ 0 ]
3439 expect ( button ) . toBeTruthy ( )
3540 } )
@@ -39,9 +44,9 @@ describe('<PauseResumeButton />', () => {
3944 < PauseResumeButton id = { 0 } uploader = { uploader } />
4045 )
4146
42- uploadChunkCallback ( 0 , 'foo.jpeg' , { partIndex : 1 } )
47+ uploadChunkSuccessCallback ( 0 , { partIndex : 1 } )
4348 statusChangeCallback ( 0 , null , 'deleted' )
44- let button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-button' ) [ 0 ]
49+ const button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-button' ) [ 0 ]
4550 expect ( button ) . toBeFalsy ( )
4651 } )
4752
@@ -50,17 +55,42 @@ describe('<PauseResumeButton />', () => {
5055 < PauseResumeButton id = { 0 } uploader = { uploader } />
5156 )
5257
58+ uploadChunkSuccessCallback ( 0 , { partIndex : 7 } )
59+
5360 statusChangeCallback ( 0 , null , 'paused' )
5461 let button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-resume-button' ) [ 0 ]
5562 expect ( button ) . toBeTruthy ( )
5663
5764 const resumeUploadMethod = spyOn ( uploader . methods , 'continueUpload' )
5865 TestUtils . Simulate . click ( button )
5966 expect ( resumeUploadMethod ) . toHaveBeenCalledWith ( 0 )
67+
6068 statusChangeCallback ( 0 , null , 'uploading' )
6169 button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-resume-button' ) [ 0 ]
6270 expect ( button ) . toBeTruthy ( )
6371 expect ( button . className . indexOf ( 'react-fine-uploader-pause-button' ) ) . not . toBe ( - 1 )
6472 expect ( button . className . indexOf ( 'react-fine-uploader-resume-button' ) ) . toBe ( - 1 )
73+
74+ const pauseUploadMethod = spyOn ( uploader . methods , 'pauseUpload' )
75+ TestUtils . Simulate . click ( button )
76+ expect ( pauseUploadMethod ) . toHaveBeenCalledWith ( 0 )
77+ statusChangeCallback ( 0 , null , 'paused' )
78+ button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-resume-button' ) [ 0 ]
79+ expect ( button ) . toBeTruthy ( )
80+ expect ( button . className . indexOf ( 'react-fine-uploader-pause-button' ) ) . toBe ( - 1 )
81+ expect ( button . className . indexOf ( 'react-fine-uploader-resume-button' ) ) . not . toBe ( - 1 )
82+ } )
83+
84+ it ( 'allows a resumed file to be paused immediately' , ( ) => {
85+ const PauseResumeButtonComponent = TestUtils . renderIntoDocument (
86+ < PauseResumeButton id = { 0 } uploader = { uploader } />
87+ )
88+
89+ resumeCallback ( 0 , { partIndex : 3 } )
90+
91+ let button = TestUtils . scryRenderedDOMComponentsWithClass ( PauseResumeButtonComponent , 'react-fine-uploader-pause-button' ) [ 0 ]
92+ expect ( button ) . toBeTruthy ( )
93+ expect ( button . className . indexOf ( 'react-fine-uploader-pause-button' ) ) . not . toBe ( - 1 )
94+ expect ( button . className . indexOf ( 'react-fine-uploader-resume-button' ) ) . toBe ( - 1 )
6595 } )
6696} )
0 commit comments