Skip to content

Commit 7f3cefa

Browse files
committed
Merge branch 'master' of github.com:beanloop/react-with-spinner
2 parents 0b535af + 7015655 commit 7f3cefa

File tree

5 files changed

+2746
-1772
lines changed

5 files changed

+2746
-1772
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"ramda": "^0.23.0",
2929
"react": "^15.4.2",
3030
"react-dom": "^15.4.2",
31-
"react-toolbox": "^1.3.4",
3231
"recompose": "^0.22.0"
3332
}
3433
}

src/__snapshots__/index.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ exports[`withSpinner should render passed spinnerComponent 1`] = `
6060
`;
6161

6262
exports[`withSpinner should render spinner if loading is true 1`] = `
63-
<ToolboxSpinner
63+
<Loading
6464
data={
6565
Object {
6666
"loading": true,

src/index.test.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import './test-setup'
44
import {mount, shallow} from 'enzyme'
55
import toJson from 'enzyme-to-json'
66
import * as React from 'react'
7-
import ProgressBar from 'react-toolbox/lib/progress_bar'
87
import compose from 'recompose/compose'
98
import {withSpinner} from './index'
109

10+
const Loading = () => <span>Loading...</span>
1111
jest.useFakeTimers()
1212

1313
describe('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()

src/index.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import path from 'ramda/src/path'
22
import * as React from 'react'
33
import {Component, ReactType} from 'react'
4-
import ProgressBar from 'react-toolbox/lib/progress_bar'
54
import wrapDisplayName from 'recompose/wrapDisplayName'
65

7-
const ToolboxSpinner = props => <ProgressBar {...props} />
8-
96
export type Properties = {
107
/**
118
* Property to look for, if prop.loading is true then the [spinnerComponent]
@@ -38,7 +35,7 @@ export type Properties = {
3835
* Component that should be rendered while loading.
3936
* Defaults to a React Toolbox ProgressBar component.
4037
*/
41-
spinnerComponent?: ReactType
38+
spinnerComponent: ReactType
4239
/**
4340
* Extra props that should be passed to the [spinnerComponent].
4441
*/
@@ -65,9 +62,9 @@ export const withSpinner = ({
6562
handleError = true, partial = false,
6663
skipErrors, spinnerProps,
6764
errorComponent: ErrorComponent = null,
68-
spinnerComponent: Spinner = ToolboxSpinner,
65+
spinnerComponent: Spinner,
6966
emptyComponent: EmptyComponent = null,
70-
}: Properties = {}): any => WrappedComponent =>
67+
}: Properties): any => WrappedComponent =>
7168
class extends Component<Properties, {showSpinner: boolean}> {
7269
static displayName = wrapDisplayName(WrappedComponent, 'withSpinner')
7370

0 commit comments

Comments
 (0)