|
1 | 1 | import * as React from 'react'; |
2 | | -import Button from 'box-ui-elements/es/components/button'; |
3 | | -import PrimaryButton from 'box-ui-elements/es/components/primary-button'; |
4 | 2 | import { EditorState } from 'draft-js'; |
5 | 3 | import { Form } from 'formik'; |
6 | 4 | import { KEYS } from 'box-ui-elements/es/constants'; |
7 | 5 | import { shallow, ShallowWrapper } from 'enzyme'; |
| 6 | +import ReplyButton from '../ReplyButton'; |
8 | 7 | import ReplyForm, { Props } from '../ReplyForm'; |
9 | 8 | import ReplyField from '../../ReplyField'; |
10 | 9 | import { mockEvent } from '../../../common/__mocks__/events'; |
@@ -32,28 +31,31 @@ describe('components/ReplyForm/ReplyForm', () => { |
32 | 31 | const getWrapper = (props = {}): ShallowWrapper<Props, undefined> => |
33 | 32 | shallow(<ReplyForm {...defaults} {...props} />); |
34 | 33 |
|
35 | | - test('should render Form with ReplyField and Buttons in the footer', () => { |
| 34 | + test('should render Form with ReplyField and buttons in the footer', () => { |
36 | 35 | const wrapper = getWrapper(); |
37 | 36 |
|
38 | 37 | expect(wrapper.exists(Form)).toBe(true); |
39 | 38 | expect(wrapper.exists(ReplyField)).toBe(true); |
40 | | - expect(wrapper.exists(Button)).toBe(true); |
41 | | - expect(wrapper.exists(PrimaryButton)).toBe(true); |
| 39 | + expect(wrapper.find(ReplyButton).length).toBe(2); |
42 | 40 | }); |
43 | 41 |
|
44 | | - test('should have buttons be disabled if isPending is true', () => { |
| 42 | + test('should disable the buttons and form if isPending is true', () => { |
45 | 43 | const wrapper = getWrapper({ isPending: true }); |
| 44 | + const cancel = wrapper.find(ReplyButton).at(0); |
| 45 | + const submit = wrapper.find(ReplyButton).at(1); |
46 | 46 |
|
47 | 47 | expect(wrapper.find(ReplyField).prop('isDisabled')).toBe(true); |
48 | | - expect(wrapper.find(Button).prop('isDisabled')).toBe(true); |
49 | | - expect(wrapper.find(PrimaryButton).prop('isDisabled')).toBe(true); |
| 48 | + expect(cancel.prop('isDisabled')).toBe(true); |
| 49 | + expect(submit.prop('isDisabled')).toBe(true); |
50 | 50 | }); |
51 | 51 |
|
52 | | - test('should disable PrimaryButton if has errors', () => { |
| 52 | + test('should disable the submit button if the form has errors', () => { |
53 | 53 | const wrapper = getWrapper({ errors: { foo: 'bar' } }); |
| 54 | + const cancel = wrapper.find(ReplyButton).at(0); |
| 55 | + const submit = wrapper.find(ReplyButton).at(1); |
54 | 56 |
|
55 | | - expect(wrapper.find(Button).prop('isDisabled')).toBe(false); |
56 | | - expect(wrapper.find(PrimaryButton).prop('isDisabled')).toBe(true); |
| 57 | + expect(cancel.prop('isDisabled')).toBe(false); |
| 58 | + expect(submit.prop('isDisabled')).toBe(true); |
57 | 59 | }); |
58 | 60 |
|
59 | 61 | test('should call the handleChange callback when change event occurs on ReplyField', () => { |
|
0 commit comments