|
| 1 | +import React from 'react'; |
| 2 | +import createShallowSnapshotTest from 'test-utils/createShallowSnapshotTest'; |
| 3 | +import { mount, shallow } from 'enzyme'; |
| 4 | + |
| 5 | +import ArticleGroup from '../ArticleGroup'; |
| 6 | + |
| 7 | +describe('ArticleGroup', () => { |
| 8 | + test('should render properly with required props', () => |
| 9 | + createShallowSnapshotTest( |
| 10 | + <ArticleGroup |
| 11 | + region="test" |
| 12 | + articles={[{ title: 'Example', url: 'https://example.com' }]} |
| 13 | + numberOfInitiallyVisibleLinks={1} |
| 14 | + />, |
| 15 | + )); |
| 16 | + |
| 17 | + test('should render properly with required props and 3 links and a button', () => |
| 18 | + createShallowSnapshotTest( |
| 19 | + <ArticleGroup |
| 20 | + region="test" |
| 21 | + articles={[ |
| 22 | + { title: 'Example', url: 'https://example.com' }, |
| 23 | + { title: 'Example', url: 'https://example.com' }, |
| 24 | + { title: 'Example', url: 'https://example.com' }, |
| 25 | + ]} |
| 26 | + numberOfInitiallyVisibleLinks={1} |
| 27 | + />, |
| 28 | + )); |
| 29 | + |
| 30 | + test('should setState when clicking Show All button', () => { |
| 31 | + const ArticleGroupShallowInstance = shallow( |
| 32 | + <ArticleGroup |
| 33 | + region="test" |
| 34 | + articles={[ |
| 35 | + { title: 'Example', url: 'https://example.com' }, |
| 36 | + { title: 'Example', url: 'https://example.com' }, |
| 37 | + { title: 'Example', url: 'https://example.com' }, |
| 38 | + ]} |
| 39 | + numberOfInitiallyVisibleLinks={1} |
| 40 | + />, |
| 41 | + ); |
| 42 | + |
| 43 | + ArticleGroupShallowInstance.instance().clickHandler(); |
| 44 | + |
| 45 | + expect(ArticleGroupShallowInstance.state().areAllLinksVisible).toEqual(true); |
| 46 | + }); |
| 47 | + |
| 48 | + test('should not create a button if not enough links', () => { |
| 49 | + const wrap = mount( |
| 50 | + <ArticleGroup |
| 51 | + region="test" |
| 52 | + articles={[{ title: 'Example', url: 'https://example.com' }]} |
| 53 | + numberOfInitiallyVisibleLinks={5} |
| 54 | + />, |
| 55 | + ); |
| 56 | + |
| 57 | + expect(wrap.find('button').exists()).toEqual(false); |
| 58 | + }); |
| 59 | + |
| 60 | + test('should create a button if enough links are available', () => { |
| 61 | + const wrap = mount( |
| 62 | + <ArticleGroup |
| 63 | + region="test" |
| 64 | + articles={[ |
| 65 | + { title: 'Example', url: 'https://example.com' }, |
| 66 | + { title: 'Example', url: 'https://example.com' }, |
| 67 | + { title: 'Example', url: 'https://example.com' }, |
| 68 | + ]} |
| 69 | + numberOfInitiallyVisibleLinks={1} |
| 70 | + />, |
| 71 | + ); |
| 72 | + |
| 73 | + expect(wrap.find('button').exists()).toEqual(true); |
| 74 | + }); |
| 75 | +}); |
0 commit comments