This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
TextFieldWithLabelFormGroup.test.tsx
99 lines (89 loc) · 2.71 KB
/
TextFieldWithLabelFormGroup.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import '../../../__mocks__/matchMediaMock'
import React from 'react'
import { Label, TextField } from '@hospitalrun/components'
import { shallow } from 'enzyme'
import TextFieldWithLabelFormGroup from '../../../components/input/TextFieldWithLabelFormGroup'
describe('text field with label form group', () => {
describe('layout', () => {
it('should render a label', () => {
const expectedName = 'test'
const wrapper = shallow(
<TextFieldWithLabelFormGroup
name={expectedName}
label="test"
value=""
isEditable
onChange={jest.fn()}
/>,
)
const label = wrapper.find(Label)
expect(label).toHaveLength(1)
expect(label.prop('htmlFor')).toEqual(`${expectedName}TextField`)
expect(label.prop('text')).toEqual(expectedName)
})
it('should render a text field', () => {
const expectedName = 'test'
const wrapper = shallow(
<TextFieldWithLabelFormGroup
name={expectedName}
label="test"
value=""
isEditable
onChange={jest.fn()}
/>,
)
const input = wrapper.find(TextField)
expect(input).toHaveLength(1)
})
it('should render disabled is isDisable disabled is true', () => {
const expectedName = 'test'
const wrapper = shallow(
<TextFieldWithLabelFormGroup
name={expectedName}
label="test"
value=""
isEditable={false}
onChange={jest.fn()}
/>,
)
const input = wrapper.find(TextField)
expect(input).toHaveLength(1)
expect(input.prop('disabled')).toBeTruthy()
})
it('should render the proper value', () => {
const expectedName = 'test'
const expectedValue = 'expected value'
const wrapper = shallow(
<TextFieldWithLabelFormGroup
name={expectedName}
label="test"
value={expectedValue}
isEditable={false}
onChange={jest.fn()}
/>,
)
const input = wrapper.find(TextField)
expect(input).toHaveLength(1)
expect(input.prop('value')).toEqual(expectedValue)
})
})
describe('change handler', () => {
it('should call the change handler on change', () => {
const expectedName = 'test'
const expectedValue = 'expected value'
const handler = jest.fn()
const wrapper = shallow(
<TextFieldWithLabelFormGroup
name={expectedName}
label="test"
value={expectedValue}
isEditable={false}
onChange={handler}
/>,
)
const input = wrapper.find(TextField)
input.simulate('change')
expect(handler).toHaveBeenCalledTimes(1)
})
})
})