@@ -8,6 +8,10 @@ import { Checkbox, Radio, Switch } from './checkbox';
88afterEach ( cleanup ) ;
99
1010describe ( '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' ;
1115 it ( '<Checkbox /> renders correctly and call on change on Press' , ( ) => {
1216 const mockOnChange = jest . fn ( ( checked ) => checked ) ;
1317 render (
@@ -19,7 +23,7 @@ describe('Checkbox, Radio & Switch components ', () => {
1923 />
2024 ) ;
2125 expect ( screen . getByTestId ( 'checkbox' ) ) . toBeOnTheScreen ( ) ;
22- expect ( screen . queryByTestId ( 'checkbox-label' ) ) . not . toBeOnTheScreen ( ) ;
26+ expect ( screen . queryByTestId ( CHECKBOX_LABEL ) ) . not . toBeOnTheScreen ( ) ;
2327 expect ( screen . getByTestId ( 'checkbox' ) ) . toBeEnabled ( ) ;
2428
2529 expect ( screen . getByTestId ( 'checkbox' ) ) . not . toBeChecked ( ) ;
@@ -64,7 +68,7 @@ describe('Checkbox, Radio & Switch components ', () => {
6468 />
6569 ) ;
6670 expect ( screen . getByTestId ( 'checkbox' ) ) . toBeOnTheScreen ( ) ;
67- expect ( screen . getByTestId ( 'checkbox-label' ) ) . toBeOnTheScreen ( ) ;
71+ expect ( screen . getByTestId ( CHECKBOX_LABEL ) ) . toBeOnTheScreen ( ) ;
6872 expect (
6973 screen . getByTestId ( 'checkbox' ) . props . accessibilityState . checked
7074 ) . toBe ( false ) ;
@@ -75,9 +79,7 @@ describe('Checkbox, Radio & Switch components ', () => {
7579 expect ( screen . getByTestId ( 'checkbox' ) . props . accessibilityLabel ) . toBe (
7680 'agree'
7781 ) ;
78- expect ( screen . getByTestId ( 'checkbox-label' ) ) . toHaveTextContent (
79- 'I agree to terms and conditions'
80- ) ;
82+ expect ( screen . getByTestId ( CHECKBOX_LABEL ) ) . toHaveTextContent ( AGREE_TERMS ) ;
8183 fireEvent . press ( screen . getByTestId ( 'checkbox' ) ) ;
8284 expect ( mockOnChange ) . toHaveBeenCalledTimes ( 0 ) ;
8385 } ) ;
@@ -93,7 +95,7 @@ describe('Checkbox, Radio & Switch components ', () => {
9395 />
9496 ) ;
9597 expect ( screen . getByTestId ( 'radio' ) ) . toBeOnTheScreen ( ) ;
96- expect ( screen . queryByTestId ( 'radio-label' ) ) . not . toBeOnTheScreen ( ) ;
98+ expect ( screen . queryByTestId ( RADIO_LABEL ) ) . not . toBeOnTheScreen ( ) ;
9799 expect ( screen . getByTestId ( 'radio' ) ) . toBeEnabled ( ) ;
98100 expect ( screen . getByTestId ( 'radio' ) ) . not . toBeChecked ( ) ;
99101 expect ( screen . getByTestId ( 'radio' ) . props . accessibilityRole ) . toBe ( 'radio' ) ;
@@ -115,17 +117,15 @@ describe('Checkbox, Radio & Switch components ', () => {
115117 />
116118 ) ;
117119 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 ) ;
122122
123123 expect ( screen . getByTestId ( 'radio' ) . props . accessibilityState . checked ) . toBe (
124124 false
125125 ) ;
126126 expect ( screen . getByTestId ( 'radio' ) . props . accessibilityRole ) . toBe ( 'radio' ) ;
127127 expect ( screen . getByTestId ( 'radio' ) . props . accessibilityLabel ) . toBe ( 'agree' ) ;
128- fireEvent . press ( screen . getByTestId ( 'radio-label' ) ) ;
128+ fireEvent . press ( screen . getByTestId ( RADIO_LABEL ) ) ;
129129 expect ( mockOnChange ) . toHaveBeenCalledTimes ( 1 ) ;
130130 expect ( mockOnChange ) . toHaveBeenCalledWith ( true ) ;
131131 } ) ;
@@ -158,7 +158,7 @@ describe('Checkbox, Radio & Switch components ', () => {
158158 />
159159 ) ;
160160 expect ( screen . getByTestId ( 'switch' ) ) . toBeOnTheScreen ( ) ;
161- expect ( screen . queryByTestId ( 'switch-label' ) ) . not . toBeOnTheScreen ( ) ;
161+ expect ( screen . queryByTestId ( SWITCH_LABEL ) ) . not . toBeOnTheScreen ( ) ;
162162 expect ( screen . getByTestId ( 'switch' ) ) . toBeEnabled ( ) ;
163163 expect ( screen . getByTestId ( 'switch' ) . props . accessibilityState . checked ) . toBe (
164164 false
@@ -182,16 +182,14 @@ describe('Checkbox, Radio & Switch components ', () => {
182182 />
183183 ) ;
184184 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 ) ;
189187 expect ( screen . getByTestId ( 'switch' ) . props . accessibilityState . checked ) . toBe (
190188 false
191189 ) ;
192190 expect ( screen . getByTestId ( 'switch' ) . props . accessibilityRole ) . toBe ( 'switch' ) ;
193191 expect ( screen . getByTestId ( 'switch' ) . props . accessibilityLabel ) . toBe ( 'agree' ) ;
194- fireEvent . press ( screen . getByTestId ( 'switch-label' ) ) ;
192+ fireEvent . press ( screen . getByTestId ( SWITCH_LABEL ) ) ;
195193 expect ( mockOnChange ) . toHaveBeenCalledTimes ( 1 ) ;
196194 expect ( mockOnChange ) . toHaveBeenCalledWith ( true ) ;
197195 } ) ;
0 commit comments