Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
|
||
import Cube from '../../components/Cube' | ||
import SimpleCircle from '../../components/SimpleCircle' | ||
|
||
import makeWithLoadingIndicator, { getSpinner } from '../makeWithLoadingIndicator' | ||
|
||
const CustomComponent = () => <h1>CustomComponent</h1> | ||
|
||
describe('getSpinner()', () => { | ||
it('should render Cube', () => { | ||
const result = getSpinner('Cube') | ||
|
||
expect(result).toEqual(Cube) | ||
}) | ||
|
||
it('should render SimpleCircle', () => { | ||
const result = getSpinner('SimpleCircle') | ||
|
||
expect(result).toEqual(SimpleCircle) | ||
}) | ||
|
||
it('should render custom component', () => { | ||
const result = getSpinner(CustomComponent) | ||
|
||
expect(result).toEqual(CustomComponent) | ||
}) | ||
}) // end getSpinner() | ||
|
||
describe('makeWithLoadingIndicator', () => { | ||
const WrappedComponent = (props) => ( | ||
<h1>WrappedComponent</h1> | ||
) | ||
|
||
it('should render wrapped component, if condition HOC returns false', () => { | ||
const condition = () => false | ||
const widthLoadingIndicator = makeWithLoadingIndicator({ condition }) | ||
|
||
const ComponentWithLoadingIndicator = widthLoadingIndicator(WrappedComponent) | ||
|
||
const wrapper = mount(<ComponentWithLoadingIndicator />) | ||
expect(wrapper.find(WrappedComponent).exists()).toBe(true) | ||
expect(wrapper.find(SimpleCircle).exists()).toBe(false) | ||
}) | ||
|
||
it('should render SimpleCircle by default if condition returns true', () => { | ||
const condition = () => true | ||
const widthLoadingIndicator = makeWithLoadingIndicator({ condition }) | ||
|
||
const ComponentWithLoadingIndicator = widthLoadingIndicator(WrappedComponent) | ||
|
||
const wrapper = mount(<ComponentWithLoadingIndicator />) | ||
expect(wrapper.find(SimpleCircle).exists()).toBe(true) | ||
expect(wrapper.find(WrappedComponent).exists()).toBe(false) | ||
}) | ||
|
||
it('should render CustomComponent if condition returns true and custom spinner was defined', () => { | ||
const condition = () => true | ||
const widthLoadingIndicator = makeWithLoadingIndicator({ | ||
condition, | ||
spinnerType: CustomComponent | ||
}) | ||
|
||
const ComponentWithLoadingIndicator = widthLoadingIndicator(WrappedComponent) | ||
|
||
const wrapper = mount(<ComponentWithLoadingIndicator />) | ||
expect(wrapper.find(SimpleCircle).exists()).toBe(false) | ||
expect(wrapper.find(WrappedComponent).exists()).toBe(false) | ||
expect(wrapper.find(CustomComponent).exists()).toBe(true) | ||
}) | ||
|
||
it('should render custom Container if condition is true', () => { | ||
const Container = () => <h1>Container</h1> | ||
const condition = () => true | ||
|
||
const widthLoadingIndicator = makeWithLoadingIndicator({ | ||
Container, | ||
condition | ||
}) | ||
|
||
const ComponentWithLoadingIndicator = widthLoadingIndicator(WrappedComponent) | ||
|
||
const wrapper = mount(<ComponentWithLoadingIndicator />) | ||
expect(wrapper.find(Container).exists()).toBe(true) | ||
expect(wrapper.find(WrappedComponent).exists()).toBe(false) | ||
}) | ||
}) // end makeWithLoadingIndicator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import HOCSpinners, { | ||
Cube, | ||
makeWithLoadingIndicator, | ||
SimpleCircle | ||
} from '../index' | ||
|
||
describe('HOCSpinners default export', () => { | ||
it('should contain makeWithLoadingIndicator', () => { | ||
expect(HOCSpinners.makeWithLoadingIndicator).toBeDefined() | ||
}) | ||
|
||
it('should contain Cube', () => { | ||
expect(HOCSpinners.Cube).toBeDefined() | ||
}) | ||
|
||
it('should contain SimpleCircle', () => { | ||
expect(HOCSpinners.SimpleCircle).toBeDefined() | ||
}) | ||
}) // end default export | ||
|
||
describe('Named exports', () => { | ||
it('should export makeWithLoadingIndicator', () => { | ||
expect(makeWithLoadingIndicator).toBeDefined() | ||
}) | ||
|
||
it('should export Cube', () => { | ||
expect(Cube).toBeDefined() | ||
}) | ||
|
||
it('should export SimpleCircle', () => { | ||
expect(SimpleCircle).toBeDefined() | ||
}) | ||
}) // end named exports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import Wrapper from '../../Wrapper' | ||
import SimpleCircle, { Circle } from '../index' | ||
|
||
describe('SimpleCircle', () => { | ||
it('should render Wrapper', () => { | ||
const wrapper = shallow(<SimpleCircle />) | ||
|
||
expect(wrapper.find(Wrapper).exists()).toBe(true) | ||
}) | ||
|
||
it('should render Circle', () => { | ||
const wrapper = shallow(<SimpleCircle />) | ||
|
||
expect(wrapper.find(Circle).exists()).toBe(true) | ||
}) | ||
}) | ||
|
||
describe('Circle', () => { | ||
it('should render <div>', () => { | ||
const wrapper = shallow(<Circle />) | ||
|
||
expect(wrapper.find('div').exists()).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
import { makeWithLoadingIndicator } from './HOCS/makeWithLoadingIndicator' | ||
import makeWithLoadingIndicator from './HOCS/makeWithLoadingIndicator' | ||
import Cube from './components/Cube' | ||
import SimpleCircle from './components/SimpleCircle' | ||
|
||
// Components | ||
export { Cube } | ||
export { SimpleCircle } | ||
|
||
// HOCs | ||
export { makeWithLoadingIndicator } | ||
|
||
export default { | ||
makeWithLoadingIndicator, | ||
Cube | ||
Cube, | ||
SimpleCircle | ||
} |