diff --git a/app/components/UI/Notification.js b/app/components/UI/Notification.js new file mode 100644 index 00000000..3273069e --- /dev/null +++ b/app/components/UI/Notification.js @@ -0,0 +1,49 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { Card, Flex, Text } from 'rebass' +import MdClose from 'react-icons/lib/md/close' +import SystemSuccess from 'components/Icon/SystemSuccess' +import SystemWarning from 'components/Icon/SystemWarning' +import SystemError from 'components/Icon/SystemError' +import Spinner from './Spinner' + +/** + * @render react + * @name Notification + * @example + * Success message + */ +class Notification extends React.Component { + static displayName = 'Notification' + + static defaultProps = { + processing: false, + variant: 'success' + } + + static propTypes = { + children: PropTypes.node, + processing: PropTypes.bool, + variant: PropTypes.string + } + + render() { + const { children, processing, variant } = this.props + return ( + + + + {processing && } + {!processing && variant === 'success' && } + {!processing && variant === 'warning' && } + {!processing && variant === 'error' && } + {children} + + + + + ) + } +} + +export default Notification diff --git a/stories/components/notification.stories.js b/stories/components/notification.stories.js new file mode 100644 index 00000000..e8e9cebe --- /dev/null +++ b/stories/components/notification.stories.js @@ -0,0 +1,9 @@ +import React from 'react' +import { storiesOf } from '@storybook/react' +import Notification from 'components/UI/Notification' + +storiesOf('Components.Notification', module) + .add('Success', () => Success message) + .add('Warning', () => Warning message) + .add('Error', () => Error message) + .add('Processing', () => Processing message) diff --git a/test/unit/components/UI/Notification.spec.js b/test/unit/components/UI/Notification.spec.js new file mode 100644 index 00000000..117f1b51 --- /dev/null +++ b/test/unit/components/UI/Notification.spec.js @@ -0,0 +1,46 @@ +import React from 'react' +import Notification from 'components/UI/Notification' +import renderer from 'react-test-renderer' +import { configure, shallow } from 'enzyme' +import Adapter from 'enzyme-adapter-react-16' +import SystemSuccess from 'components/Icon/SystemSuccess' +import SystemWarning from 'components/Icon/SystemWarning' +import SystemError from 'components/Icon/SystemError' +import Spinner from 'components/UI/Spinner' + +configure({ adapter: new Adapter() }) + +describe('component.UI.Notification', () => { + it('should render correctly', () => { + const tree = renderer.create().toJSON() + expect(tree).toMatchSnapshot() + }) + + describe('variant = success', () => { + it('should render with the success icon', () => { + const wrapper = shallow() + expect(wrapper.find(SystemSuccess)).toHaveLength(1) + }) + }) + + describe('variant = warning', () => { + it('should render with the warning icon', () => { + const wrapper = shallow() + expect(wrapper.find(SystemWarning)).toHaveLength(1) + }) + }) + + describe('variant = error', () => { + it('should render with the error icon', () => { + const wrapper = shallow() + expect(wrapper.find(SystemError)).toHaveLength(1) + }) + }) + + describe('processing', () => { + it('should render with the spinner', () => { + const wrapper = shallow() + expect(wrapper.find(Spinner)).toHaveLength(1) + }) + }) +}) diff --git a/test/unit/components/UI/__snapshots__/Notification.spec.js.snap b/test/unit/components/UI/__snapshots__/Notification.spec.js.snap new file mode 100644 index 00000000..204bb8f9 --- /dev/null +++ b/test/unit/components/UI/__snapshots__/Notification.spec.js.snap @@ -0,0 +1,87 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`component.UI.Notification should render correctly 1`] = ` +.c1 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + -ms-flex-pack: justify; + justify-content: space-between; +} + +.c2 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; +} + +.c3 { + margin-left: 8px; +} + +.c0 { + padding-left: 16px; + padding-right: 16px; + padding-top: 16px; + padding-bottom: 16px; + border-radius: 5px; +} + +
+
+
+ + + + + +
+
+ + + + + +
+
+`;