Skip to content

Commit 633ef42

Browse files
authored
uilib-test-renderer - some fixes to findStyle (#1602)
* uilib-test-renderer - some fixes to findStyle * Move to using StyleSheet.flatten * Fix hint test and change bg color
1 parent 0694456 commit 633ef42

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/components/hint/__tests__/index.spec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Hint} from 'react-native-ui-lib';
33
import {Colors} from '../../../style';
44
import {render, findStyle} from '../../../uilib-test-renderer';
55

6-
const HintTestComponent = ({showHint}) => {
6+
const HintTestComponent = ({showHint, color}) => {
77
return (
88
<Hint
99
visible={showHint}
@@ -13,7 +13,7 @@ const HintTestComponent = ({showHint}) => {
1313
key={'1'}
1414
targetFrame={{x: 1, y: 1, height: 1, width: 1}}
1515
onBackgroundPress={() => {}}
16-
color={Colors.white}
16+
color={color}
1717
removePaddings
1818
enableShadow
1919
testID={'Hint'}
@@ -28,16 +28,20 @@ describe('Hint Screen component test', () => {
2828
const expectedColor = Colors.primary;
2929
const element = <HintTestComponent showHint/>;
3030

31-
const {getByTestId} = render(element);
31+
const {getByTestId, rerender} = render(element);
3232

3333
const wrapper = getByTestId('Hint');
3434
expect(wrapper).toBeTruthy();
3535

3636
const hint = getByTestId(hintTestId);
37-
const color = findStyle('backgroundColor', hint);
37+
let color = findStyle('backgroundColor', hint);
3838

3939
expect(color).toBe(expectedColor);
4040
expect(hint).toBeTruthy();
41+
42+
rerender(<HintTestComponent showHint color={Colors.white}/>);
43+
color = findStyle('backgroundColor', hint);
44+
expect(color).toBe(Colors.white);
4145
});
4246

4347
it('Test Hint modal is not visible when showHint is false', async () => {

src/uilib-test-renderer/helper.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from 'lodash';
1+
import {StyleSheet} from 'react-native';
22

33
interface Props {
44
style: any;
@@ -9,9 +9,7 @@ interface Component {
99
}
1010

1111
const findStyle = <T>(key: string, component: Component): T => {
12-
const flat = _.flatMap(component.props.style) as Array<any | undefined>;
13-
const color = _.find(flat, key)[key];
14-
return color;
12+
return StyleSheet.flatten(component.props.style)[key];
1513
};
1614

1715
export {findStyle};

0 commit comments

Comments
 (0)