index.js
82 lines
| 1 | import { render } from '@testing-library/react'; |
| 2 | import IconWrapper from '../index'; |
| 3 | import generalSvgs from '../../icon-picker/svgs-general'; |
| 4 | |
| 5 | const ChildrenComponent = () => ( <h2> { 'My children component' } </h2> ); |
| 6 | |
| 7 | describe( 'IconWrapper', () => { |
| 8 | it( 'should render children elements', () => { |
| 9 | const wrapper = render( |
| 10 | <IconWrapper> |
| 11 | <ChildrenComponent /> |
| 12 | </IconWrapper> |
| 13 | ); |
| 14 | |
| 15 | expect( wrapper ).toMatchSnapshot(); |
| 16 | } ); |
| 17 | |
| 18 | it( 'should render left icon', () => { |
| 19 | const wrapper = render( |
| 20 | <IconWrapper icon={ generalSvgs.clock.icon }> |
| 21 | <ChildrenComponent /> |
| 22 | </IconWrapper> |
| 23 | ); |
| 24 | |
| 25 | expect( wrapper ).toMatchSnapshot(); |
| 26 | } ); |
| 27 | |
| 28 | it( 'should render right icon', () => { |
| 29 | const wrapper = render( |
| 30 | <IconWrapper icon={ generalSvgs.clock.icon } direction={ 'right' }> |
| 31 | <ChildrenComponent /> |
| 32 | </IconWrapper> |
| 33 | ); |
| 34 | |
| 35 | expect( wrapper ).toMatchSnapshot(); |
| 36 | } ); |
| 37 | |
| 38 | it( 'should hide children elements', () => { |
| 39 | const wrapper = render( |
| 40 | <IconWrapper icon={ generalSvgs.clock.icon } hideChildren={ true }> |
| 41 | <ChildrenComponent /> |
| 42 | </IconWrapper> |
| 43 | ); |
| 44 | |
| 45 | expect( wrapper ).toMatchSnapshot(); |
| 46 | } ); |
| 47 | |
| 48 | it( 'should render multiple children', () => { |
| 49 | const wrapper = render( |
| 50 | <IconWrapper icon={ generalSvgs.clock.icon }> |
| 51 | <ChildrenComponent /> |
| 52 | <ChildrenComponent /> |
| 53 | <ChildrenComponent /> |
| 54 | </IconWrapper> |
| 55 | ); |
| 56 | |
| 57 | expect( wrapper ).toMatchSnapshot(); |
| 58 | } ); |
| 59 | |
| 60 | it( 'should render without children', () => { |
| 61 | const wrapper = render( |
| 62 | <IconWrapper icon={ generalSvgs.clock.icon } /> |
| 63 | ); |
| 64 | |
| 65 | expect( wrapper ).toMatchSnapshot(); |
| 66 | } ); |
| 67 | |
| 68 | it( 'should render with wrapper element', () => { |
| 69 | const wrapper = render( |
| 70 | <IconWrapper |
| 71 | icon={ generalSvgs.clock.icon } |
| 72 | hideWrapper={ false } |
| 73 | wrapperClassname={ 'my-wrapper-class' } |
| 74 | > |
| 75 | <ChildrenComponent /> |
| 76 | </IconWrapper> |
| 77 | ); |
| 78 | |
| 79 | expect( wrapper ).toMatchSnapshot(); |
| 80 | } ); |
| 81 | } ); |
| 82 |