@@ -4,17 +4,17 @@ import './test-setup'
4
4
import { mount , shallow } from 'enzyme'
5
5
import toJson from 'enzyme-to-json'
6
6
import * as React from 'react'
7
- import ProgressBar from 'react-toolbox/lib/progress_bar'
8
7
import compose from 'recompose/compose'
9
8
import { withSpinner } from './index'
10
9
10
+ const Loading = ( ) => < span > Loading...</ span >
11
11
jest . useFakeTimers ( )
12
12
13
13
describe ( 'withSpinner' , ( ) => {
14
14
it ( 'should render spinner if loading is true' , ( ) => {
15
15
const Component = compose (
16
16
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : true } } /> ,
17
- withSpinner ( ) ,
17
+ withSpinner ( { spinnerComponent : Loading } ) ,
18
18
) ( ( ) => < div > </ div > )
19
19
20
20
const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -31,7 +31,7 @@ describe('withSpinner', () => {
31
31
it ( 'should not render spinner if loading is false' , ( ) => {
32
32
const Component = compose (
33
33
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false } } /> ,
34
- withSpinner ( ) ,
34
+ withSpinner ( { spinnerComponent : Loading } ) ,
35
35
) ( ( { data} ) => < div > loading: { data . loading . toString ( ) } </ div > )
36
36
37
37
const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( ) . first ( ) . shallow ( )
@@ -58,7 +58,7 @@ describe('withSpinner', () => {
58
58
return < WrappedComponent { ...this . props } data = { { loading : this . state . loading , item : this . state . item } } />
59
59
}
60
60
} ,
61
- withSpinner ( ) ,
61
+ withSpinner ( { spinnerComponent : Loading } ) ,
62
62
) ( DisplayComponent )
63
63
64
64
const wrapper = mount ( < Component /> )
@@ -69,14 +69,14 @@ describe('withSpinner', () => {
69
69
// Run timer to 100 ms since withSpinner timeout defaults to 100 ms
70
70
jest . runTimersToTime ( 100 )
71
71
// ProgressBar should now be found
72
- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 1 )
72
+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 1 )
73
73
expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 0 )
74
74
75
75
// Run timer to 1000 ms for our own timeout
76
76
jest . runTimersToTime ( 1000 )
77
77
// DisplayComponent should be found
78
78
expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 1 )
79
- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 0 )
79
+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 0 )
80
80
81
81
expect ( toJson ( wrapper ) ) . toMatchSnapshot ( )
82
82
} )
@@ -101,7 +101,7 @@ describe('withSpinner', () => {
101
101
102
102
const Component = compose (
103
103
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , error : true } } /> ,
104
- withSpinner ( { handleError : false } ) ,
104
+ withSpinner ( { spinnerComponent : Loading , handleError : false } ) ,
105
105
) ( DisplayComponent )
106
106
107
107
const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -115,7 +115,7 @@ describe('withSpinner', () => {
115
115
116
116
const Component = compose (
117
117
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , error : true } } /> ,
118
- withSpinner ( { errorComponent : ErrorComponent } ) ,
118
+ withSpinner ( { spinnerComponent : Loading , errorComponent : ErrorComponent } ) ,
119
119
) ( null )
120
120
121
121
const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -130,7 +130,7 @@ describe('withSpinner', () => {
130
130
131
131
const Component = compose (
132
132
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : true } } /> ,
133
- withSpinner ( { timeout : 500 } ) ,
133
+ withSpinner ( { spinnerComponent : Loading , timeout : 500 } ) ,
134
134
) ( DisplayComponent )
135
135
136
136
const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
@@ -141,7 +141,7 @@ describe('withSpinner', () => {
141
141
142
142
// Run timer over our timeout
143
143
jest . runTimersToTime ( 600 )
144
- expect ( wrapper . first ( ) . shallow ( ) . type ( ) ) . toBe ( ProgressBar )
144
+ expect ( wrapper . first ( ) . shallow ( ) . node ) . toEqual ( Loading ( ) )
145
145
} )
146
146
147
147
it ( 'should not render errorComponent if skipErrors returns true' , ( ) => {
@@ -153,7 +153,7 @@ describe('withSpinner', () => {
153
153
154
154
const Component = compose (
155
155
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , error : validationError } } /> ,
156
- withSpinner ( ( {
156
+ withSpinner ( ( { spinnerComponent : Loading ,
157
157
errorComponent : ErrorComponent ,
158
158
skipErrors : data => data . error . validationError && data . error . validationError . field === 'password'
159
159
} ) ) ,
@@ -184,7 +184,7 @@ describe('withSpinner', () => {
184
184
return < WrappedComponent { ...this . props } result = { { loading : this . state . loading , item : this . state . item } } />
185
185
}
186
186
} ,
187
- withSpinner ( { prop : 'result' } ) ,
187
+ withSpinner ( { spinnerComponent : Loading , prop : 'result' } ) ,
188
188
) ( DisplayComponent )
189
189
190
190
const wrapper = mount ( < Component /> )
@@ -195,14 +195,14 @@ describe('withSpinner', () => {
195
195
// Run timer to 100 ms since withSpinner timeout defaults to 100 ms
196
196
jest . runTimersToTime ( 100 )
197
197
// ProgressBar should now be found
198
- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 1 )
198
+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 1 )
199
199
expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 0 )
200
200
201
201
// Run timer to 1000 ms for our own timeout
202
202
jest . runTimersToTime ( 1000 )
203
203
// DisplayComponent should be found
204
204
expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 1 )
205
- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 0 )
205
+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 0 )
206
206
} )
207
207
208
208
it ( 'should support custom nested loading property' , ( ) => {
@@ -224,7 +224,7 @@ describe('withSpinner', () => {
224
224
return < WrappedComponent { ...this . props } result = { { nested : { loading : this . state . loading , item : this . state . item } } } />
225
225
}
226
226
} ,
227
- withSpinner ( { prop : [ 'result' , 'nested' ] } ) ,
227
+ withSpinner ( { spinnerComponent : Loading , prop : [ 'result' , 'nested' ] } ) ,
228
228
// withSpinner(),
229
229
) ( DisplayComponent )
230
230
@@ -236,14 +236,14 @@ describe('withSpinner', () => {
236
236
// Run timer to 100 ms since withSpinner timeout defaults to 100 ms
237
237
jest . runTimersToTime ( 100 )
238
238
// ProgressBar should now be found
239
- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 1 )
239
+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 1 )
240
240
expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 0 )
241
241
242
242
// Run timer to 1000 ms for our own timeout
243
243
jest . runTimersToTime ( 1000 )
244
244
// DisplayComponent should be found
245
245
expect ( wrapper . find ( DisplayComponent ) ) . toHaveLength ( 1 )
246
- expect ( wrapper . find ( ProgressBar ) ) . toHaveLength ( 0 )
246
+ expect ( wrapper . find ( Loading ) ) . toHaveLength ( 0 )
247
247
expect ( toJson ( wrapper ) ) . toMatchSnapshot ( )
248
248
} )
249
249
@@ -252,7 +252,7 @@ describe('withSpinner', () => {
252
252
253
253
const Component = compose (
254
254
WrappedComponent => props => < WrappedComponent { ...props } data = { { loading : false , value : { } } } /> ,
255
- withSpinner ( { emptyComponent : EmptyComponent , prop : [ 'data' , 'value' ] } ) ,
255
+ withSpinner ( { spinnerComponent : Loading , emptyComponent : EmptyComponent , prop : [ 'data' , 'value' ] } ) ,
256
256
) ( null )
257
257
258
258
const wrapper = shallow ( < Component /> ) . first ( ) . shallow ( )
0 commit comments