|
1 | 1 | // @flow |
2 | 2 | import * as React from 'react'; |
3 | | -import { shallow } from 'enzyme'; |
| 3 | +import { mount } from 'enzyme'; |
4 | 4 | import GuideTooltip from '../GuideTooltip'; |
5 | 5 | import FolderShared32 from '../../../icon/content/FolderShared32'; |
6 | 6 |
|
7 | 7 | describe('components/guide-tooltip/GuideTooltip', () => { |
8 | 8 | const title = <div>title</div>; |
9 | 9 | const body = <div>body</div>; |
10 | 10 | const icon = <FolderShared32 />; |
| 11 | + const image = <img alt="test" src="test" />; |
11 | 12 | const steps = [1, 3]; |
12 | 13 | const primaryButtonProps = { children: 'Next' }; |
13 | 14 | const secondaryButtonProps = { children: 'Previous' }; |
14 | 15 |
|
15 | | - const getWrapper = props => shallow(<GuideTooltip {...props} />); |
| 16 | + const getWrapper = props => |
| 17 | + mount( |
| 18 | + <GuideTooltip {...props}> |
| 19 | + <div /> |
| 20 | + </GuideTooltip>, |
| 21 | + ); |
16 | 22 |
|
17 | 23 | test('should render with title and body', () => { |
18 | 24 | const wrapper = getWrapper({ body, title }); |
19 | | - expect(wrapper).toMatchSnapshot(); |
| 25 | + |
| 26 | + // hidden elements |
| 27 | + expect(wrapper.find('.bdl-GuideTooltip-icon').length).toEqual(0); |
| 28 | + expect(wrapper.find('.bdl-GuideTooltip-image').length).toEqual(0); |
| 29 | + expect(wrapper.find('.bdl-GuideTooltip-previousButton').length).toEqual(0); |
| 30 | + expect(wrapper.find('.bdl-GuideTooltip-nextButton').length).toEqual(0); |
| 31 | + expect(wrapper.find('.bdl-GuideTooltip-steps').length).toEqual(0); |
| 32 | + // visible elements |
| 33 | + expect(wrapper.find('.bdl-GuideTooltip-title').length).toEqual(1); |
| 34 | + expect(wrapper.find('.bdl-GuideTooltip-title').text()).toEqual('title'); |
| 35 | + expect(wrapper.find('.bdl-GuideTooltip-body').length).toEqual(1); |
| 36 | + expect(wrapper.find('.bdl-GuideTooltip-body').text()).toEqual('body'); |
20 | 37 | }); |
21 | 38 |
|
22 | 39 | test('should render with just body', () => { |
23 | 40 | const wrapper = getWrapper({ body }); |
24 | | - expect(wrapper).toMatchSnapshot(); |
| 41 | + |
| 42 | + // hidden elements |
| 43 | + expect(wrapper.find('.bdl-GuideTooltip-title').length).toEqual(0); |
| 44 | + expect(wrapper.find('.bdl-GuideTooltip-icon').length).toEqual(0); |
| 45 | + expect(wrapper.find('.bdl-GuideTooltip-image').length).toEqual(0); |
| 46 | + expect(wrapper.find('.bdl-GuideTooltip-previousButton').length).toEqual(0); |
| 47 | + expect(wrapper.find('.bdl-GuideTooltip-nextButton').length).toEqual(0); |
| 48 | + expect(wrapper.find('.bdl-GuideTooltip-steps').length).toEqual(0); |
| 49 | + // visible elements |
| 50 | + expect(wrapper.find('.bdl-GuideTooltip-body').length).toEqual(1); |
| 51 | + expect(wrapper.find('.bdl-GuideTooltip-body').text()).toEqual('body'); |
| 52 | + }); |
| 53 | + |
| 54 | + test('should render with all options but icon', () => { |
| 55 | + const wrapper = getWrapper({ body, title, image, primaryButtonProps, secondaryButtonProps, steps }); |
| 56 | + |
| 57 | + // hidden elements |
| 58 | + expect(wrapper.find('.bdl-GuideTooltip-icon').length).toEqual(0); |
| 59 | + // visible elements |
| 60 | + expect(wrapper.find('.bdl-GuideTooltip-title').length).toEqual(1); |
| 61 | + expect(wrapper.find('.bdl-GuideTooltip-title').text()).toEqual('title'); |
| 62 | + expect(wrapper.find('.bdl-GuideTooltip-image img').length).toEqual(1); |
| 63 | + expect(wrapper.find('.bdl-GuideTooltip-body').length).toEqual(1); |
| 64 | + expect(wrapper.find('.bdl-GuideTooltip-body').text()).toEqual('body'); |
| 65 | + expect(wrapper.find('Button.bdl-GuideTooltip-previousButton').length).toEqual(1); |
| 66 | + expect(wrapper.find('Button.bdl-GuideTooltip-nextButton').length).toEqual(1); |
| 67 | + expect(wrapper.find('.bdl-GuideTooltip-steps').length).toEqual(1); |
25 | 68 | }); |
26 | 69 |
|
27 | | - test('should render with all options', () => { |
28 | | - const wrapper = getWrapper({ body, title, icon, primaryButtonProps, secondaryButtonProps, steps }); |
29 | | - expect(wrapper).toMatchSnapshot(); |
| 70 | + test('should render with all options but image', () => { |
| 71 | + const wrapper = getWrapper({ body, title, icon, image, primaryButtonProps, secondaryButtonProps, steps }); |
| 72 | + |
| 73 | + // hidden elements |
| 74 | + expect(wrapper.find('.bdl-GuideTooltip-image').length).toEqual(0); |
| 75 | + // visible elements |
| 76 | + expect(wrapper.find('.bdl-GuideTooltip-title').length).toEqual(1); |
| 77 | + expect(wrapper.find('.bdl-GuideTooltip-title').text()).toEqual('title'); |
| 78 | + expect(wrapper.find('.bdl-GuideTooltip-icon FolderShared32').length).toEqual(1); |
| 79 | + expect(wrapper.find('.bdl-GuideTooltip-body').length).toEqual(1); |
| 80 | + expect(wrapper.find('.bdl-GuideTooltip-body').text()).toEqual('body'); |
| 81 | + expect(wrapper.find('Button.bdl-GuideTooltip-previousButton').length).toEqual(1); |
| 82 | + expect(wrapper.find('Button.bdl-GuideTooltip-nextButton').length).toEqual(1); |
| 83 | + expect(wrapper.find('.bdl-GuideTooltip-steps').length).toEqual(1); |
30 | 84 | }); |
31 | 85 | }); |
0 commit comments