|
| 1 | +import React from 'react'; |
| 2 | +import { mount } from 'enzyme'; |
| 3 | +import Grid from '@material-ui/core/Grid'; |
| 4 | +import Typography from '@material-ui/core/Typography'; |
| 5 | + |
| 6 | +import Subform from '../form-fields/sub-form'; |
| 7 | + |
| 8 | +describe('subform', () => { |
| 9 | + const props = { |
| 10 | + fields: [ |
| 11 | + { |
| 12 | + key: 'cosiKey', |
| 13 | + title: 'cosiTitle', |
| 14 | + name: 'cosiName', |
| 15 | + fields: [], |
| 16 | + }, |
| 17 | + { |
| 18 | + key: 'cosiKey2', |
| 19 | + title: 'cosiTitle2', |
| 20 | + name: 'cosiName2', |
| 21 | + fields: [], |
| 22 | + }, |
| 23 | + ], |
| 24 | + formOptions: { |
| 25 | + renderForm: jest.fn().mockImplementation(() => <h1>Content</h1>), |
| 26 | + }, |
| 27 | + }; |
| 28 | + |
| 29 | + const TITLE = 'TIIIITLE'; |
| 30 | + const DESCRIPTION = 'THIS IS DESCRIPTION'; |
| 31 | + |
| 32 | + it('should render correctly', () => { |
| 33 | + const wrapper = mount(<Subform { ...props } />); |
| 34 | + |
| 35 | + expect(wrapper.find(Grid)).toHaveLength(2); |
| 36 | + expect(wrapper.find(Typography)).toHaveLength(0); |
| 37 | + expect(wrapper.find('h1')).toHaveLength(1); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should render correctly with title', () => { |
| 41 | + const wrapper = mount(<Subform { ...props } title={ TITLE }/>); |
| 42 | + |
| 43 | + expect(wrapper.find(Grid)).toHaveLength(3); |
| 44 | + expect(wrapper.find(Typography)).toHaveLength(1); |
| 45 | + expect(wrapper.find(Typography).text().includes(TITLE)).toEqual(true); |
| 46 | + expect(wrapper.find('h1')).toHaveLength(1); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should render correctly with description', () => { |
| 50 | + const wrapper = mount(<Subform { ...props } description={ DESCRIPTION }/>); |
| 51 | + |
| 52 | + expect(wrapper.find(Grid)).toHaveLength(3); |
| 53 | + expect(wrapper.find(Typography)).toHaveLength(1); |
| 54 | + expect(wrapper.find(Typography).text().includes(DESCRIPTION)).toEqual(true); |
| 55 | + expect(wrapper.find('h1')).toHaveLength(1); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should render correctly with title and description', () => { |
| 59 | + const wrapper = mount(<Subform { ...props } title={ TITLE } description={ DESCRIPTION }/>); |
| 60 | + |
| 61 | + expect(wrapper.find(Grid)).toHaveLength(4); |
| 62 | + expect(wrapper.find(Typography)).toHaveLength(2); |
| 63 | + expect(wrapper.find(Typography).first().text().includes(TITLE)).toEqual(true); |
| 64 | + expect(wrapper.find(Typography).last().text().includes(DESCRIPTION)).toEqual(true); |
| 65 | + expect(wrapper.find('h1')).toHaveLength(1); |
| 66 | + }); |
| 67 | +}); |
0 commit comments