Skip to content

Commit 143f627

Browse files
authored
Button driver - add getStyle (#3296)
* Button driver - add getStyle * remove type
1 parent 1c77d6b commit 143f627

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/components/button/Button.driver.new.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ export const ButtonDriver = (props: ComponentProps) => {
3030
return StyleSheet.flatten(iconDriver?.getElement().props.style);
3131
};
3232

33-
return {getLabel, getLabelStyle, getIconStyle, getIcon, ...driver};
33+
const getStyle = () => {
34+
return StyleSheet.flatten(driver.getElement().props.style);
35+
};
36+
37+
return {getStyle, getLabel, getLabelStyle, getIconStyle, getIcon, ...driver};
3438
};

src/components/button/__tests__/index.driver.spec.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import React, {useState} from 'react';
22
import {waitFor, render} from '@testing-library/react-native';
33
import View from '../../view';
44
import Text from '../../text';
5-
import Button from '../index';
6-
import {ImageSourcePropType} from 'react-native';
7-
import {ButtonDriver} from '../Button.driver.new';
85
import {TextDriver} from '../../text/Text.driver.new';
6+
import {ButtonDriver} from '../Button.driver.new';
7+
import Button, {ButtonProps} from '../index';
98

109
const BUTTON_ID = 'button_test_id';
1110
const CHILDREN_TEXT_ID = 'children_test_id';
@@ -19,6 +18,18 @@ describe('Button', () => {
1918
expect(await buttonDriver.exists()).toBeTruthy();
2019
});
2120

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+
2233
describe('custom button', () => {
2334
it('should render a custom button', async () => {
2435
const renderTree = render(<WrapperScreenWithCustomButton/>);
@@ -35,7 +46,7 @@ describe('Button', () => {
3546
});
3647
});
3748

38-
describe('OnPress', () => {
49+
describe('onPress', () => {
3950
let onPressCallback: jest.Mock;
4051
beforeEach(() => (onPressCallback = jest.fn()));
4152
afterEach(() => onPressCallback.mockClear());
@@ -100,7 +111,7 @@ describe('Button', () => {
100111
describe('more complicated screen', () => {
101112
//todo take it out of this file. to the demo screens maybe
102113
it('should change text values according to state changes from buttons pressing', async () => {
103-
const renderTree = render(StatefulScreenWithTextsAndButtonss());
114+
const renderTree = render(StatefulScreen());
104115
const text1Driver = TextDriver({testID: `text_1`, renderTree});
105116
const text2Driver = TextDriver({testID: `text_2`, renderTree});
106117
const button2Driver = ButtonDriver({testID: `${BUTTON_ID}2`, renderTree});
@@ -119,16 +130,10 @@ describe('Button', () => {
119130
});
120131
});
121132

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 = {}) {
129134
return (
130135
<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}/>
132137
</View>
133138
);
134139
}
@@ -144,7 +149,7 @@ function WrapperScreenWithCustomButton(buttonProps: {onPress?: () => void} = {})
144149
);
145150
}
146151

147-
const StatefulScreenWithTextsAndButtonss = () => <StatefulScreenWithTextsAndButtons/>;
152+
const StatefulScreen = () => <StatefulScreenWithTextsAndButtons/>;
148153

149154
const StatefulScreenWithTextsAndButtons = () => {
150155
const [count1, setCount1] = useState(0);

0 commit comments

Comments
 (0)