1
1
import React , { useState } from 'react' ;
2
2
import { render , waitFor } from '@testing-library/react-native' ;
3
- import Button from '../index' ;
4
3
import View from '../../view' ;
5
- import ButtonTestKit from '../Button.driver' ;
6
4
import Text from '../../text' ;
7
- import TextTestKit from '../../text/Text.driver' ;
5
+ import Button from '../index' ;
6
+ import { ButtonDriver } from '../Button.driver' ;
7
+ import { TextDriver } from '../../text/Text.driver' ;
8
8
9
9
const BUTTON_ID = 'button_test_id' ;
10
10
const CHILDREN_TEXT_ID = 'children_test_id' ;
@@ -14,22 +14,22 @@ const CHILDREN_TEXT = 'custom button text';
14
14
describe . skip ( 'Button' , ( ) => {
15
15
it ( 'should render a button' , async ( ) => {
16
16
const wrapperComponent = renderWrapperScreenWithButton ( { } ) ;
17
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
17
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
18
18
expect ( buttonDriver . exists ( ) ) . toBeTruthy ( ) ;
19
19
} ) ;
20
20
21
21
describe ( 'custom button' , ( ) => {
22
22
it ( 'should render a custom button' , async ( ) => {
23
23
const wrapperComponent = renderWrapperScreenWithCustomButton ( { } ) ;
24
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
24
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
25
25
expect ( buttonDriver . exists ( ) ) . toBeTruthy ( ) ;
26
26
} ) ;
27
27
28
28
it ( 'should render the children with correct text' , async ( ) => {
29
29
const wrapperComponent = renderWrapperScreenWithCustomButton ( { } ) ;
30
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
30
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
31
31
expect ( buttonDriver . exists ( ) ) . toBeTruthy ( ) ;
32
- const childrenTextDriver = await TextTestKit ( { wrapperComponent, testID : CHILDREN_TEXT_ID } ) ;
32
+ const childrenTextDriver = await TextDriver ( { wrapperComponent, testID : CHILDREN_TEXT_ID } ) ;
33
33
expect ( childrenTextDriver . getTextContent ( ) ) . toEqual ( CHILDREN_TEXT ) ;
34
34
} ) ;
35
35
} ) ;
@@ -41,14 +41,14 @@ describe.skip('Button', () => {
41
41
42
42
it ( 'should trigger onPress callback' , async ( ) => {
43
43
const wrapperComponent = renderWrapperScreenWithButton ( { onPress : onPressCallback } ) ;
44
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
44
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
45
45
buttonDriver . click ( ) ;
46
46
await waitFor ( ( ) => expect ( onPressCallback ) . toHaveBeenCalledTimes ( 1 ) ) ;
47
47
} ) ;
48
48
49
49
it ( 'should not trigger onPress callback if button disabled' , async ( ) => {
50
50
const wrapperComponent = renderWrapperScreenWithButton ( { onPress : onPressCallback , disabled : true } ) ;
51
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
51
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
52
52
buttonDriver . click ( ) ;
53
53
await waitFor ( ( ) => expect ( onPressCallback ) . toHaveBeenCalledTimes ( 0 ) ) ;
54
54
} ) ;
@@ -58,35 +58,35 @@ describe.skip('Button', () => {
58
58
const LABEL = 'mock label' ;
59
59
it ( 'should render a button with correct content' , async ( ) => {
60
60
const wrapperComponent = renderWrapperScreenWithButton ( { label : LABEL } ) ;
61
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
61
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
62
62
expect ( buttonDriver . getLabelContent ( ) ) . toEqual ( LABEL ) ;
63
63
} ) ;
64
64
65
65
xit ( 'should render a button with correct label content. ' , async ( ) => {
66
66
// todo import @testing -library/jest-native(/extend-expect)
67
67
const wrapperComponent = renderWrapperScreenWithButton ( { label : LABEL } ) ;
68
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
68
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
69
69
expect ( buttonDriver . getLabelRootElement ( ) ) . toHaveTextContent ( LABEL ) ;
70
70
} ) ;
71
71
72
72
it ( 'should render a button without label. ' , async ( ) => {
73
73
const wrapperComponent = renderWrapperScreenWithButton ( { } ) ;
74
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
74
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
75
75
expect ( buttonDriver . isLabelExists ( ) ) . toBeFalsy ( ) ;
76
76
} ) ;
77
77
} ) ;
78
78
79
79
describe ( 'icon' , ( ) => {
80
80
it ( 'should render a button without an icon. ' , async ( ) => {
81
81
const wrapperComponent = renderWrapperScreenWithButton ( { } ) ;
82
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
82
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
83
83
expect ( buttonDriver . isIconExists ( ) ) . toBeFalsy ( ) ;
84
84
} ) ;
85
85
86
86
it ( 'should render a button with icon. ' , async ( ) => {
87
87
const ICON = 12 ;
88
88
const wrapperComponent = renderWrapperScreenWithButton ( { iconSource : ICON } ) ;
89
- const buttonDriver = await ButtonTestKit ( { wrapperComponent, testID : BUTTON_ID } ) ;
89
+ const buttonDriver = await ButtonDriver ( { wrapperComponent, testID : BUTTON_ID } ) ;
90
90
expect ( buttonDriver . isIconExists ( ) ) . toBeTruthy ( ) ;
91
91
} ) ;
92
92
} ) ;
@@ -95,10 +95,10 @@ describe.skip('Button', () => {
95
95
//todo take it out of this file. to the demo screens maybe
96
96
it ( 'should change text values according to state changes from buttons pressing' , async ( ) => {
97
97
const wrapperComponent = renderMoreComplicatedScreen ( ) ;
98
- const text1Driver = await TextTestKit ( { wrapperComponent, testID : `text_1` } ) ;
99
- const text2Driver = await TextTestKit ( { wrapperComponent, testID : `text_2` } ) ;
100
- const button1Driver = await ButtonTestKit ( { wrapperComponent, testID : `${ BUTTON_ID } 1` } ) ;
101
- const button2Driver = await ButtonTestKit ( { wrapperComponent, testID : `${ BUTTON_ID } 2` } ) ;
98
+ const text1Driver = await TextDriver ( { wrapperComponent, testID : `text_1` } ) ;
99
+ const text2Driver = await TextDriver ( { wrapperComponent, testID : `text_2` } ) ;
100
+ const button1Driver = await ButtonDriver ( { wrapperComponent, testID : `${ BUTTON_ID } 1` } ) ;
101
+ const button2Driver = await ButtonDriver ( { wrapperComponent, testID : `${ BUTTON_ID } 2` } ) ;
102
102
expect ( text1Driver . getTextContent ( ) ) . toBe ( 'button 1 pressed 0 times' ) ;
103
103
expect ( text2Driver . getTextContent ( ) ) . toBe ( 'button 2 pressed 0 times' ) ;
104
104
button1Driver . click ( ) ;
0 commit comments