@@ -2,10 +2,9 @@ import React, {useState} from 'react';
2
2
import { waitFor , render } from '@testing-library/react-native' ;
3
3
import View from '../../view' ;
4
4
import Text from '../../text' ;
5
- import Button from '../index' ;
6
- import { ImageSourcePropType } from 'react-native' ;
7
- import { ButtonDriver } from '../Button.driver.new' ;
8
5
import { TextDriver } from '../../text/Text.driver.new' ;
6
+ import { ButtonDriver } from '../Button.driver.new' ;
7
+ import Button , { ButtonProps } from '../index' ;
9
8
10
9
const BUTTON_ID = 'button_test_id' ;
11
10
const CHILDREN_TEXT_ID = 'children_test_id' ;
@@ -19,6 +18,18 @@ describe('Button', () => {
19
18
expect ( await buttonDriver . exists ( ) ) . toBeTruthy ( ) ;
20
19
} ) ;
21
20
21
+ describe ( 'style' , ( ) => {
22
+ it ( 'should render a button with custom style' , async ( ) => {
23
+ const style = { borderWidth : 2 , borderColor : 'green' } ;
24
+ const renderTree = render ( < WrapperScreenWithButton style = { style } /> ) ;
25
+ const buttonDriver = ButtonDriver ( { renderTree, testID : 'button_test_id' } ) ;
26
+
27
+ expect ( buttonDriver . exists ( ) ) . toBeTruthy ( ) ;
28
+ expect ( await buttonDriver . getStyle ( ) . borderWidth ) . toEqual ( style . borderWidth ) ;
29
+ expect ( await buttonDriver . getStyle ( ) . borderColor ) . toEqual ( style . borderColor ) ;
30
+ } ) ;
31
+ } ) ;
32
+
22
33
describe ( 'custom button' , ( ) => {
23
34
it ( 'should render a custom button' , async ( ) => {
24
35
const renderTree = render ( < WrapperScreenWithCustomButton /> ) ;
@@ -35,7 +46,7 @@ describe('Button', () => {
35
46
} ) ;
36
47
} ) ;
37
48
38
- describe ( 'OnPress ' , ( ) => {
49
+ describe ( 'onPress ' , ( ) => {
39
50
let onPressCallback : jest . Mock ;
40
51
beforeEach ( ( ) => ( onPressCallback = jest . fn ( ) ) ) ;
41
52
afterEach ( ( ) => onPressCallback . mockClear ( ) ) ;
@@ -100,7 +111,7 @@ describe('Button', () => {
100
111
describe ( 'more complicated screen' , ( ) => {
101
112
//todo take it out of this file. to the demo screens maybe
102
113
it ( 'should change text values according to state changes from buttons pressing' , async ( ) => {
103
- const renderTree = render ( StatefulScreenWithTextsAndButtonss ( ) ) ;
114
+ const renderTree = render ( StatefulScreen ( ) ) ;
104
115
const text1Driver = TextDriver ( { testID : `text_1` , renderTree} ) ;
105
116
const text2Driver = TextDriver ( { testID : `text_2` , renderTree} ) ;
106
117
const button2Driver = ButtonDriver ( { testID : `${ BUTTON_ID } 2` , renderTree} ) ;
@@ -119,16 +130,10 @@ describe('Button', () => {
119
130
} ) ;
120
131
} ) ;
121
132
122
- function WrapperScreenWithButton ( buttonProps : {
123
- onPress ?: ( ) => void ;
124
- label ?: string ;
125
- iconSource ?: ImageSourcePropType ;
126
- disabled ?: boolean ;
127
- } = { } ) {
128
- const { onPress, label, iconSource, disabled} = buttonProps ;
133
+ function WrapperScreenWithButton ( buttonProps : ButtonProps = { } ) {
129
134
return (
130
135
< View testID = { 'wrapper_screen_test_id' } >
131
- < Button testID = { BUTTON_ID } onPress = { onPress } label = { label } iconSource = { iconSource } disabled = { disabled } />
136
+ < Button { ... buttonProps } testID = { BUTTON_ID } />
132
137
</ View >
133
138
) ;
134
139
}
@@ -144,7 +149,7 @@ function WrapperScreenWithCustomButton(buttonProps: {onPress?: () => void} = {})
144
149
) ;
145
150
}
146
151
147
- const StatefulScreenWithTextsAndButtonss = ( ) => < StatefulScreenWithTextsAndButtons /> ;
152
+ const StatefulScreen = ( ) => < StatefulScreenWithTextsAndButtons /> ;
148
153
149
154
const StatefulScreenWithTextsAndButtons = ( ) => {
150
155
const [ count1 , setCount1 ] = useState ( 0 ) ;
0 commit comments