@@ -8,6 +8,10 @@ import { Checkbox, Radio, Switch } from './checkbox';
8
8
afterEach ( cleanup ) ;
9
9
10
10
describe ( 'Checkbox, Radio & Switch components ' , ( ) => {
11
+ const CHECKBOX_LABEL = 'checkbox-label' ;
12
+ const AGREE_TERMS = 'I agree to terms and conditions' ;
13
+ const RADIO_LABEL = 'radio-label' ;
14
+ const SWITCH_LABEL = 'switch-label' ;
11
15
it ( '<Checkbox /> renders correctly and call on change on Press' , ( ) => {
12
16
const mockOnChange = jest . fn ( ( checked ) => checked ) ;
13
17
render (
@@ -19,7 +23,7 @@ describe('Checkbox, Radio & Switch components ', () => {
19
23
/>
20
24
) ;
21
25
expect ( screen . getByTestId ( 'checkbox' ) ) . toBeOnTheScreen ( ) ;
22
- expect ( screen . queryByTestId ( 'checkbox-label' ) ) . not . toBeOnTheScreen ( ) ;
26
+ expect ( screen . queryByTestId ( CHECKBOX_LABEL ) ) . not . toBeOnTheScreen ( ) ;
23
27
expect ( screen . getByTestId ( 'checkbox' ) ) . toBeEnabled ( ) ;
24
28
25
29
expect ( screen . getByTestId ( 'checkbox' ) ) . not . toBeChecked ( ) ;
@@ -64,7 +68,7 @@ describe('Checkbox, Radio & Switch components ', () => {
64
68
/>
65
69
) ;
66
70
expect ( screen . getByTestId ( 'checkbox' ) ) . toBeOnTheScreen ( ) ;
67
- expect ( screen . getByTestId ( 'checkbox-label' ) ) . toBeOnTheScreen ( ) ;
71
+ expect ( screen . getByTestId ( CHECKBOX_LABEL ) ) . toBeOnTheScreen ( ) ;
68
72
expect (
69
73
screen . getByTestId ( 'checkbox' ) . props . accessibilityState . checked
70
74
) . toBe ( false ) ;
@@ -75,9 +79,7 @@ describe('Checkbox, Radio & Switch components ', () => {
75
79
expect ( screen . getByTestId ( 'checkbox' ) . props . accessibilityLabel ) . toBe (
76
80
'agree'
77
81
) ;
78
- expect ( screen . getByTestId ( 'checkbox-label' ) ) . toHaveTextContent (
79
- 'I agree to terms and conditions'
80
- ) ;
82
+ expect ( screen . getByTestId ( CHECKBOX_LABEL ) ) . toHaveTextContent ( AGREE_TERMS ) ;
81
83
fireEvent . press ( screen . getByTestId ( 'checkbox' ) ) ;
82
84
expect ( mockOnChange ) . toHaveBeenCalledTimes ( 0 ) ;
83
85
} ) ;
@@ -93,7 +95,7 @@ describe('Checkbox, Radio & Switch components ', () => {
93
95
/>
94
96
) ;
95
97
expect ( screen . getByTestId ( 'radio' ) ) . toBeOnTheScreen ( ) ;
96
- expect ( screen . queryByTestId ( 'radio-label' ) ) . not . toBeOnTheScreen ( ) ;
98
+ expect ( screen . queryByTestId ( RADIO_LABEL ) ) . not . toBeOnTheScreen ( ) ;
97
99
expect ( screen . getByTestId ( 'radio' ) ) . toBeEnabled ( ) ;
98
100
expect ( screen . getByTestId ( 'radio' ) ) . not . toBeChecked ( ) ;
99
101
expect ( screen . getByTestId ( 'radio' ) . props . accessibilityRole ) . toBe ( 'radio' ) ;
@@ -115,17 +117,15 @@ describe('Checkbox, Radio & Switch components ', () => {
115
117
/>
116
118
) ;
117
119
expect ( screen . getByTestId ( 'radio' ) ) . toBeOnTheScreen ( ) ;
118
- expect ( screen . getByTestId ( 'radio-label' ) ) . toBeOnTheScreen ( ) ;
119
- expect ( screen . getByTestId ( 'radio-label' ) ) . toHaveTextContent (
120
- 'I agree to terms and conditions'
121
- ) ;
120
+ expect ( screen . getByTestId ( RADIO_LABEL ) ) . toBeOnTheScreen ( ) ;
121
+ expect ( screen . getByTestId ( RADIO_LABEL ) ) . toHaveTextContent ( AGREE_TERMS ) ;
122
122
123
123
expect ( screen . getByTestId ( 'radio' ) . props . accessibilityState . checked ) . toBe (
124
124
false
125
125
) ;
126
126
expect ( screen . getByTestId ( 'radio' ) . props . accessibilityRole ) . toBe ( 'radio' ) ;
127
127
expect ( screen . getByTestId ( 'radio' ) . props . accessibilityLabel ) . toBe ( 'agree' ) ;
128
- fireEvent . press ( screen . getByTestId ( 'radio-label' ) ) ;
128
+ fireEvent . press ( screen . getByTestId ( RADIO_LABEL ) ) ;
129
129
expect ( mockOnChange ) . toHaveBeenCalledTimes ( 1 ) ;
130
130
expect ( mockOnChange ) . toHaveBeenCalledWith ( true ) ;
131
131
} ) ;
@@ -158,7 +158,7 @@ describe('Checkbox, Radio & Switch components ', () => {
158
158
/>
159
159
) ;
160
160
expect ( screen . getByTestId ( 'switch' ) ) . toBeOnTheScreen ( ) ;
161
- expect ( screen . queryByTestId ( 'switch-label' ) ) . not . toBeOnTheScreen ( ) ;
161
+ expect ( screen . queryByTestId ( SWITCH_LABEL ) ) . not . toBeOnTheScreen ( ) ;
162
162
expect ( screen . getByTestId ( 'switch' ) ) . toBeEnabled ( ) ;
163
163
expect ( screen . getByTestId ( 'switch' ) . props . accessibilityState . checked ) . toBe (
164
164
false
@@ -182,16 +182,14 @@ describe('Checkbox, Radio & Switch components ', () => {
182
182
/>
183
183
) ;
184
184
expect ( screen . getByTestId ( 'switch' ) ) . toBeOnTheScreen ( ) ;
185
- expect ( screen . getByTestId ( 'switch-label' ) ) . toBeOnTheScreen ( ) ;
186
- expect ( screen . getByTestId ( 'switch-label' ) ) . toHaveTextContent (
187
- 'I agree to terms and conditions'
188
- ) ;
185
+ expect ( screen . getByTestId ( SWITCH_LABEL ) ) . toBeOnTheScreen ( ) ;
186
+ expect ( screen . getByTestId ( SWITCH_LABEL ) ) . toHaveTextContent ( AGREE_TERMS ) ;
189
187
expect ( screen . getByTestId ( 'switch' ) . props . accessibilityState . checked ) . toBe (
190
188
false
191
189
) ;
192
190
expect ( screen . getByTestId ( 'switch' ) . props . accessibilityRole ) . toBe ( 'switch' ) ;
193
191
expect ( screen . getByTestId ( 'switch' ) . props . accessibilityLabel ) . toBe ( 'agree' ) ;
194
- fireEvent . press ( screen . getByTestId ( 'switch-label' ) ) ;
192
+ fireEvent . press ( screen . getByTestId ( SWITCH_LABEL ) ) ;
195
193
expect ( mockOnChange ) . toHaveBeenCalledTimes ( 1 ) ;
196
194
expect ( mockOnChange ) . toHaveBeenCalledWith ( true ) ;
197
195
} ) ;
0 commit comments