forked from react-native-elements/react-native-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckBox.js
More file actions
109 lines (93 loc) · 2.78 KB
/
Copy pathCheckBox.js
File metadata and controls
109 lines (93 loc) · 2.78 KB
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
100
101
102
103
104
105
106
107
108
109
import React from 'react';
import { Image } from 'react-native';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import CheckBox from '../CheckBox';
describe('CheckBox Component', () => {
it('should render without issues', () => {
const component = shallow(<CheckBox />);
expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});
it('should use TouchableOpacity as default component', () => {
const component = shallow(<CheckBox />);
expect(component.find('TouchableOpacity').length).toBe(1);
});
it('should allow to pass custom component', () => {
const View = jest.fn();
const component = shallow(<CheckBox component={View} />);
expect(component.find('View').length).toBe(1);
});
it('should render title in Text', () => {
const component = shallow(<CheckBox title="Custom Text" checked />);
expect(component.props().children.props.children[1].props.children).toBe(
'Custom Text'
);
});
it('should render with icon and checked', () => {
const component = shallow(
<CheckBox
iconType="font-awesome"
checkedColor="red"
containerStyle={{ backgroundColor: 'red' }}
/>
);
expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});
it('should render with icon and iconRight', () => {
const component = shallow(
<CheckBox
iconType="font-awesome"
iconRight
uncheckedColor="blue"
center
right
/>
);
expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});
it('should allow custom checked Icon', () => {
const component = shallow(
<CheckBox
checked={true}
checkedIcon={
<Image
source={{ uri: 'https://image.ibb.co/jcY95H/checked.png' }}
style={{ width: 30, height: 30 }}
/>
}
uncheckedIcon={
<Image
source={{ uri: 'https://image.ibb.co/fda0Cx/no_check.png' }}
style={{ width: 30, height: 30 }}
/>
}
/>
);
expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});
it('should allow custom checked Icon', () => {
const component = shallow(
<CheckBox
checked={false}
checkedIcon={
<Image
source={{ uri: 'https://image.ibb.co/jcY95H/checked.png' }}
style={{ width: 30, height: 30 }}
/>
}
uncheckedIcon={
<Image
source={{ uri: 'https://image.ibb.co/fda0Cx/no_check.png' }}
style={{ width: 30, height: 30 }}
/>
}
/>
);
expect(component.length).toBe(1);
expect(toJson(component)).toMatchSnapshot();
});
});