Skip to content
This repository was archived by the owner on Mar 7, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Build Status](https://travis-ci.org/chrishelgert/react-handler.svg?branch=master)](https://travis-ci.org/chrishelgert/react-handler)
[![Build status](https://ci.appveyor.com/api/projects/status/c5qo9wa0n4uwakfj?svg=true)](https://ci.appveyor.com/project/chrishelgert/react-handler/branch/master)
[![codecov](https://codecov.io/gh/chrishelgert/react-handler/branch/master/graph/badge.svg)](https://codecov.io/gh/chrishelgert/react-handler)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

> A react-component for handling typical react/redux-states (loading, error, ...)

Expand Down
4 changes: 2 additions & 2 deletions __tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`react-handler should contain the Handler-Component 1`] = `[Function]`;
exports[`react-handler contains the Handler-Component 1`] = `[Function]`;

exports[`react-handler should contain the SupHandler´s 1`] = `
exports[`react-handler contains the the SupHandler´s 1`] = `
Object {
"EmptyHandler": [Function],
"ErrorEmptyHandler": [Function],
Expand Down
60 changes: 30 additions & 30 deletions __tests__/components/EmptyHandler-test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import React, { PropTypes } from 'react';
import renderer from 'react-test-renderer';
import EmptyHandler from '../../src/components/EmptyHandler';
import React, { PropTypes } from 'react'
import renderer from 'react-test-renderer'
import EmptyHandler from '../../src/components/EmptyHandler'

const TestComponent = () => <h1>Test</h1>;
const EmptyComponent = ({ children }) => <h2 className="empty">{children}</h2>;
EmptyComponent.propTypes = { children: PropTypes.string };
const componentPropsFilled = { list: ['abc', 'def'] };
const componentPropsEmpty = { list: [] };
const emptyMessage = 'no results found';
const TestComponent = () => <h1>Test</h1>
const EmptyComponent = ({ children }) => <h2 className='empty'>{children}</h2>
EmptyComponent.propTypes = { children: PropTypes.string }
const componentPropsFilled = { list: ['abc', 'def'] }
const componentPropsEmpty = { list: [] }
const emptyMessage = 'no results found'

describe('EmptyHandler', () => {
it('should return null when called without Component and is not empty', () => {
test('returns null when called without Component and is not empty', () => {
const tree = renderer.create(
<EmptyHandler
checkedProperty={componentPropsFilled.list}
message={emptyMessage}
/>,
);
expect(tree).toMatchSnapshot();
});
)
expect(tree).toMatchSnapshot()
})

it('should return the component when the element in componentProps is not empty', () => {
test('returns the component when the element in componentProps is not empty', () => {
const tree = renderer.create(
<EmptyHandler
checkedProperty={componentPropsFilled.list}
message={emptyMessage}
>
<TestComponent />
</EmptyHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return the EmptyComponent, when the list is empty and called with EmptyComponent', () => {
test('returns the EmptyComponent, when the list is empty and called with EmptyComponent', () => {
const tree = renderer.create(
<EmptyHandler
EmptyComponent={EmptyComponent}
Expand All @@ -41,26 +41,26 @@ describe('EmptyHandler', () => {
>
<TestComponent />
</EmptyHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return the EmptyMessage, when the list is empty', () => {
test('returns the EmptyMessage, when the list is empty', () => {
const tree = renderer.create(
<EmptyHandler
checkedProperty={componentPropsEmpty.list}
message={emptyMessage}
/>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return the EmptyMessage, when called without checkedProperty', () => {
test('returns the EmptyMessage, when called without checkedProperty', () => {
const tree = renderer.create(
<EmptyHandler message={emptyMessage}>
<TestComponent />
</EmptyHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
});
)
expect(tree.toJSON()).toMatchSnapshot()
})
})
44 changes: 22 additions & 22 deletions __tests__/components/ErrorEmptyHandler-test.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import React from 'react';
import renderer from 'react-test-renderer';
import ErrorEmptyHandler from '../../src/components/ErrorEmptyHandler';
import React from 'react'
import renderer from 'react-test-renderer'
import ErrorEmptyHandler from '../../src/components/ErrorEmptyHandler'

const Component = () => <div>Test</div>;
const checkedProperty = ['test'];
const Component = () => <div>Test</div>
const checkedProperty = ['test']

describe('ErrorEmptyHandler', () => {
it('should display the error-message', () => {
test('displays the error-message', () => {
const tree = renderer.create(
<ErrorEmptyHandler errorMessage="failed to load articles" emptyMessage="0 Articles found">
<ErrorEmptyHandler errorMessage='failed to load articles' emptyMessage='0 Articles found'>
<Component />
</ErrorEmptyHandler>,
);
)

expect(tree.toJSON()).toMatchSnapshot();
});
expect(tree.toJSON()).toMatchSnapshot()
})

it('should display the empty-message', () => {
test('displays the empty-message', () => {
const tree = renderer.create(
<ErrorEmptyHandler
checkedProperty={{}}
emptyPropertyKey="articles"
emptyMessage="0 Articles found"
emptyPropertyKey='articles'
emptyMessage='0 Articles found'
>
<Component />
</ErrorEmptyHandler>,
);
)

expect(tree.toJSON()).toMatchSnapshot();
});
expect(tree.toJSON()).toMatchSnapshot()
})

it('should display the Component', () => {
test('displays the Component', () => {
const tree = renderer.create(
<ErrorEmptyHandler checkedProperty={checkedProperty} emptyMessage="0 Articles found">
<ErrorEmptyHandler checkedProperty={checkedProperty} emptyMessage='0 Articles found'>
<Component />
</ErrorEmptyHandler>,
);
)

expect(tree.toJSON()).toMatchSnapshot();
});
});
expect(tree.toJSON()).toMatchSnapshot()
})
})
48 changes: 24 additions & 24 deletions __tests__/components/ErrorHandler-test.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import React, { PropTypes } from 'react';
import renderer from 'react-test-renderer';
import ErrorHandler from '../../src/components/ErrorHandler';
import React, { PropTypes } from 'react'
import renderer from 'react-test-renderer'
import ErrorHandler from '../../src/components/ErrorHandler'

const TestComponent = () => <h1>Test</h1>;
const ErrorComponent = ({ children }) => <h2 className="error">{children}</h2>;
ErrorComponent.propTypes = { children: PropTypes.string };
const errorMessage = 'failed to call api';
const TestComponent = () => <h1>Test</h1>
const ErrorComponent = ({ children }) => <h2 className='error'>{children}</h2>
ErrorComponent.propTypes = { children: PropTypes.string }
const errorMessage = 'failed to call api'

describe('ErrorHandler', () => {
it('should return the component when called without errorMessage', () => {
test('returns the component when called without errorMessage', () => {
const tree = renderer.create(
<ErrorHandler>
<TestComponent />
</ErrorHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return null when called without errorMessage and component', () => {
const tree = renderer.create(<ErrorHandler />);
expect(tree).toMatchSnapshot();
});
test('returns null when called without errorMessage and component', () => {
const tree = renderer.create(<ErrorHandler />)
expect(tree).toMatchSnapshot()
})

it('should return the ErrorComponent', () => {
test('returns the ErrorComponent', () => {
const tree = renderer.create(
<ErrorHandler
ErrorComponent={ErrorComponent}
message={errorMessage}
>
<TestComponent />
</ErrorHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return the ErrorMessage when called without ErrorComponent', () => {
test('returns the ErrorMessage when called without ErrorComponent', () => {
const tree = renderer.create(
<ErrorHandler message={errorMessage}>
<TestComponent />
</ErrorHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
});
)
expect(tree.toJSON()).toMatchSnapshot()
})
})
42 changes: 21 additions & 21 deletions __tests__/components/Handler-test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import React from 'react';
import renderer from 'react-test-renderer';
import Handler from '../../src/components/Handler';
import React from 'react'
import renderer from 'react-test-renderer'
import Handler from '../../src/components/Handler'

const Component = () => <div>Test</div>;
const checkedProperty = ['test'];
const Component = () => <div>Test</div>
const checkedProperty = ['test']

describe('Handler', () => {
it('should return the loading-message and the component', () => {
test('returns the loading-message and the component', () => {
const tree = renderer.create(
<Handler checkedProperty={checkedProperty} emptyMessage="0 Articles found">
<Handler checkedProperty={checkedProperty} emptyMessage='0 Articles found'>
<Component />
</Handler>,
);
)

expect(tree.toJSON()).toMatchSnapshot();
});
expect(tree.toJSON()).toMatchSnapshot()
})

it('should only return the loading-message, wen showComponentWhileLoading is false', () => {
test('returns only the loading-message when showComponentWhileLoading is false', () => {
const tree = renderer.create(
<Handler showComponentWhileLoading={false} checkedProperty={checkedProperty} emptyMessage="0 Articles found">
<Handler showComponentWhileLoading={false} checkedProperty={checkedProperty} emptyMessage='0 Articles found'>
<Component />
</Handler>,
);
)

expect(tree.toJSON()).toMatchSnapshot();
});
expect(tree.toJSON()).toMatchSnapshot()
})

it('should only return the Component, when loading and showComponentWhileLoading is false', () => {
test('returns the Component when loading and showComponentWhileLoading is false', () => {
const tree = renderer.create(
<Handler
showComponentWhileLoading={false}
loading={false}
checkedProperty={checkedProperty}
emptyMessage="0 Articles found"
emptyMessage='0 Articles found'
>
<Component />
</Handler>,
);
)

expect(tree.toJSON()).toMatchSnapshot();
});
});
expect(tree.toJSON()).toMatchSnapshot()
})
})
54 changes: 27 additions & 27 deletions __tests__/components/LoadingHandler-test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import React from 'react';
import renderer from 'react-test-renderer';
import LoadingHandler from '../../src/components/LoadingHandler';
import React from 'react'
import renderer from 'react-test-renderer'
import LoadingHandler from '../../src/components/LoadingHandler'

const TestComponent = () => <h1>Test</h1>;
const LoadingComponent = () => <img src="/img/spinner.svg" alt="loading..." />;
const TestComponent = () => <h1>Test</h1>
const LoadingComponent = () => <img src='/img/spinner.svg' alt='loading...' />

describe('LoadingHandler', () => {
it('should return the component when called with loading false', () => {
test('returns the component when called with loading false', () => {
const tree = renderer.create(
<LoadingHandler loading={false}>
<TestComponent />
</LoadingHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return null when called with loading false and no component', () => {
test('returns null when called with loading false and no component', () => {
const tree = renderer.create(
<LoadingHandler loading={false} />,
);
expect(tree).toMatchSnapshot();
});
)
expect(tree).toMatchSnapshot()
})

it('should return the LoadingComponent', () => {
test('returns the LoadingComponent', () => {
const tree = renderer.create(
<LoadingHandler LoadingComponent={LoadingComponent}>
<TestComponent />
</LoadingHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return the LoadingMessage with given loading message', () => {
test('returns the LoadingMessage with given loading message', () => {
const tree = renderer.create(
<LoadingHandler message="keep keep loading">
<LoadingHandler message='keep keep loading'>
<TestComponent />
</LoadingHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
)
expect(tree.toJSON()).toMatchSnapshot()
})

it('should return the LoadingMessage when called without LoadingComponent', () => {
test('returns the LoadingMessage when called without LoadingComponent', () => {
const tree = renderer.create(
<LoadingHandler>
<TestComponent />
</LoadingHandler>,
);
expect(tree.toJSON()).toMatchSnapshot();
});
});
)
expect(tree.toJSON()).toMatchSnapshot()
})
})
Loading