@@ -4,17 +4,17 @@ import './test-setup'
44import { mount , shallow } from 'enzyme'
55import toJson from 'enzyme-to-json'
66import * as React from 'react'
7- import ProgressBar from 'react-toolbox/lib/progress_bar'
87import compose from 'recompose/compose'
98import { withSpinner } from './index'
109
10+ const Loading = ( ) => < span > Loading...</ span >
1111jest . useFakeTimers ( )
1212
1313describe ( 'withSpinner' , ( ) => {
1414 it ( 'should render spinner if loading is true' , ( ) => {
1515 const Component = compose (
1616 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : true } } /> ,
17- withSpinner ( ) ,
17+ withSpinner ( { spinnerComponent : Loading } ) ,
1818 ) ( ( ) => < div > </ div > )
1919
2020 const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -31,7 +31,7 @@ describe('withSpinner', () => {
3131 it ( 'should not render spinner if loading is false' , ( ) => {
3232 const Component = compose (
3333 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false } } /> ,
34- withSpinner ( ) ,
34+ withSpinner ( { spinnerComponent : Loading } ) ,
3535 ) ( ( { data} ) => < div > loading: { data . loading . toString ( ) } </ div > )
3636
3737 const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( ) . first ( ) . shallow ( )
@@ -58,7 +58,7 @@ describe('withSpinner', () => {
5858 return < WrappedComponent { ...this . props } data = { { loading : this . state . loading , item : this . state . item } } />
5959 }
6060 } ,
61- withSpinner ( ) ,
61+ withSpinner ( { spinnerComponent : Loading } ) ,
6262 ) ( DisplayComponent )
6363
6464 const wrapper = mount ( < Component /> )
@@ -69,14 +69,14 @@ describe('withSpinner', () => {
6969 // Run timer to 100 ms since withSpinner timeout defaults to 100 ms
7070 jest . runTimersToTime ( 100 )
7171 // ProgressBar should now be found
72- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 1 )
72+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 1 )
7373 expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 0 )
7474
7575 // Run timer to 1000 ms for our own timeout
7676 jest . runTimersToTime ( 1000 )
7777 // DisplayComponent should be found
7878 expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 1 )
79- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 0 )
79+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 0 )
8080
8181 expect ( toJson ( wrapper ) ) . toMatchSnapshot ( )
8282 } )
@@ -101,7 +101,7 @@ describe('withSpinner', () => {
101101
102102 const Component = compose (
103103 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , error : true } } /> ,
104- withSpinner ( { handleError : false } ) ,
104+ withSpinner ( { spinnerComponent : Loading , handleError : false } ) ,
105105 ) ( DisplayComponent )
106106
107107 const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -115,7 +115,7 @@ describe('withSpinner', () => {
115115
116116 const Component = compose (
117117 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , error : true } } /> ,
118- withSpinner ( { errorComponent : ErrorComponent } ) ,
118+ withSpinner ( { spinnerComponent : Loading , errorComponent : ErrorComponent } ) ,
119119 ) ( null )
120120
121121 const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -130,7 +130,7 @@ describe('withSpinner', () => {
130130
131131 const Component = compose (
132132 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : true } } /> ,
133- withSpinner ( { timeout : 500 } ) ,
133+ withSpinner ( { spinnerComponent : Loading , timeout : 500 } ) ,
134134 ) ( DisplayComponent )
135135
136136 const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -141,7 +141,7 @@ describe('withSpinner', () => {
141141
142142 // Run timer over our timeout
143143 jest . runTimersToTime ( 600 )
144- expect ( wrapper . first ( ) . shallow ( ) . type ( ) ) . toBe ( ProgressBar )
144+ expect ( wrapper . first ( ) . shallow ( ) . node ) . toEqual ( Loading ( ) )
145145 } )
146146
147147 it ( 'should not render errorComponent if skipErrors returns true' , ( ) => {
@@ -153,7 +153,7 @@ describe('withSpinner', () => {
153153
154154 const Component = compose (
155155 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , error : validationError } } /> ,
156- withSpinner ( ( {
156+ withSpinner ( ( { spinnerComponent : Loading ,
157157 errorComponent : ErrorComponent ,
158158 skipErrors : data => data . error . validationError && data . error . validationError . field === 'password'
159159 } ) ) ,
@@ -184,7 +184,7 @@ describe('withSpinner', () => {
184184 return < WrappedComponent { ...this . props } result = { { loading : this . state . loading , item : this . state . item } } />
185185 }
186186 } ,
187- withSpinner ( { prop : 'result' } ) ,
187+ withSpinner ( { spinnerComponent : Loading , prop : 'result' } ) ,
188188 ) ( DisplayComponent )
189189
190190 const wrapper = mount ( < Component /> )
@@ -195,14 +195,14 @@ describe('withSpinner', () => {
195195 // Run timer to 100 ms since withSpinner timeout defaults to 100 ms
196196 jest . runTimersToTime ( 100 )
197197 // ProgressBar should now be found
198- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 1 )
198+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 1 )
199199 expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 0 )
200200
201201 // Run timer to 1000 ms for our own timeout
202202 jest . runTimersToTime ( 1000 )
203203 // DisplayComponent should be found
204204 expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 1 )
205- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 0 )
205+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 0 )
206206 } )
207207
208208 it ( 'should support custom nested loading property' , ( ) => {
@@ -224,7 +224,7 @@ describe('withSpinner', () => {
224224 return < WrappedComponent { ...this . props } result = { { nested : { loading : this . state . loading , item : this . state . item } } } />
225225 }
226226 } ,
227- withSpinner ( { prop : [ 'result' , 'nested' ] } ) ,
227+ withSpinner ( { spinnerComponent : Loading , prop : [ 'result' , 'nested' ] } ) ,
228228 // withSpinner(),
229229 ) ( DisplayComponent )
230230
@@ -236,14 +236,14 @@ describe('withSpinner', () => {
236236 // Run timer to 100 ms since withSpinner timeout defaults to 100 ms
237237 jest . runTimersToTime ( 100 )
238238 // ProgressBar should now be found
239- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 1 )
239+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 1 )
240240 expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 0 )
241241
242242 // Run timer to 1000 ms for our own timeout
243243 jest . runTimersToTime ( 1000 )
244244 // DisplayComponent should be found
245245 expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 1 )
246- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 0 )
246+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 0 )
247247 expect ( toJson ( wrapper ) ) . toMatchSnapshot ( )
248248 } )
249249
@@ -252,7 +252,7 @@ describe('withSpinner', () => {
252252
253253 const Component = compose (
254254 WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , value : { } } } /> ,
255- withSpinner ( { emptyComponent : EmptyComponent , prop : [ 'data' , 'value' ] } ) ,
255+ withSpinner ( { spinnerComponent : Loading , emptyComponent : EmptyComponent , prop : [ 'data' , 'value' ] } ) ,
256256 ) ( null )
257257
258258 const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
0 commit comments