Skip to content

Commit a50498c

Browse files
authored
Automation gap - WOAUILIB-3704 (#2902)
* Added test for automation gap bug on android * Added resetModules in order to test both platforms * Added test with mocking. Doesn't work * Added test for automation gap * Removed comment * Change constant import * Added getDriver * Added ltr tests and reorded tests * removed renderTree from driver
1 parent 6d50abc commit a50498c

File tree

2 files changed

+66
-23
lines changed

2 files changed

+66
-23
lines changed
Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,91 @@
11
import React from 'react';
22
import {render} from '@testing-library/react-native';
3-
import View from '../../view';
4-
import Text from '../index';
53
import {TextDriver} from '../Text.driver.new';
4+
import {StyleSheet} from 'react-native';
65

76
const TEXT_ID = 'text_test_id';
87
const TEXT_CONTENT = 'text content';
98

109
function WrapperScreenWithText(textProps: {onPress?: jest.Mock} = {}) {
1110
const {onPress} = textProps;
11+
const Text = require('../index').default;
1212
return (
13-
<View>
14-
<Text testID={TEXT_ID} onPress={onPress}>
15-
{TEXT_CONTENT}
16-
</Text>
17-
</View>
13+
<Text testID={TEXT_ID} onPress={onPress}>
14+
{TEXT_CONTENT}
15+
</Text>
1816
);
1917
}
2018

19+
const getDriver = (textProps: {onPress?: jest.Mock} = {}) => {
20+
const {onPress} = textProps;
21+
const renderTree = render(<WrapperScreenWithText onPress={onPress}/>);
22+
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
23+
return {textDriver};
24+
};
25+
2126
describe('Text', () => {
2227
it('should render Text Component', () => {
23-
const renderTree = render(<WrapperScreenWithText/>);
24-
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
28+
const {textDriver} = getDriver();
2529
const content = textDriver.getText();
2630
expect(content).toEqual(TEXT_CONTENT);
2731
});
2832

2933
describe('onPress', () => {
3034
it('should press the text, and run callback', () => {
3135
const onPressCallback = jest.fn();
32-
const renderTree = render(<WrapperScreenWithText onPress={onPressCallback}/>);
33-
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
34-
36+
const {textDriver} = getDriver({onPress: onPressCallback});
3537
textDriver.press();
36-
3738
expect(onPressCallback).toHaveBeenCalledTimes(1);
3839
});
3940

4041
it('should not be pressable if onPress prop is not supplied', () => {
41-
const renderTree = render(<WrapperScreenWithText/>);
42-
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
42+
const {textDriver} = getDriver();
4343
expect(textDriver.hasOnPress()).toBeFalsy();
4444
});
4545
});
46+
const setConstants = (isAndroid: boolean, isRTL: boolean) => {
47+
const {Constants} = require('../../../commons/new');
48+
Constants.isAndroid = isAndroid;
49+
Constants.isIOS = !isAndroid;
50+
Constants.isRTL = isRTL;
51+
};
52+
53+
describe('Automation gap', () => {
54+
describe('Both RTL and LTR', () => {
55+
it('Should always align text to left on Android', () => {
56+
jest.isolateModules(() => {
57+
setConstants(true, true);
58+
const {textDriver} = getDriver();
59+
const textStyle = textDriver.getProps().style;
60+
expect(StyleSheet.flatten(textStyle).textAlign).toEqual('left');
61+
});
62+
jest.isolateModules(() => {
63+
setConstants(true, false);
64+
const {textDriver} = getDriver();
65+
const textStyle = textDriver.getProps().style;
66+
expect(StyleSheet.flatten(textStyle).textAlign).toEqual('left');
67+
});
68+
});
69+
});
70+
describe('RTL', () => {
71+
it('Should have text of left on iOS', () => {
72+
jest.isolateModules(() => {
73+
setConstants(false, true);
74+
const {textDriver} = getDriver();
75+
const textStyle = textDriver.getProps().style;
76+
expect(StyleSheet.flatten(textStyle).writingDirection).toEqual('rtl');
77+
});
78+
});
79+
});
80+
describe('LTR', () => {
81+
it('Should have text of right on iOS', () => {
82+
jest.isolateModules(() => {
83+
setConstants(false, false);
84+
const {textDriver} = getDriver();
85+
const textStyle = textDriver.getProps().style;
86+
expect(StyleSheet.flatten(textStyle).writingDirection).toEqual('ltr');
87+
});
88+
});
89+
});
90+
});
4691
});

src/components/text/index.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
TextProps as RNTextProps,
77
TextStyle,
88
Animated,
9-
StyleProp,
10-
Platform
9+
StyleProp
1110
} from 'react-native';
1211
import {
1312
asBaseComponent,
@@ -192,14 +191,13 @@ const styles = StyleSheet.create({
192191
container: {
193192
backgroundColor: 'transparent',
194193
color: Colors.$textDefault,
195-
...Platform.select({
196-
ios: {
194+
...(Constants.isIOS
195+
? {
197196
writingDirection: Constants.isRTL ? writingDirectionTypes.RTL : writingDirectionTypes.LTR
198-
},
199-
android: {
200-
textAlign: 'left'
201197
}
202-
})
198+
: {
199+
textAlign: 'left'
200+
})
203201
},
204202
centered: {
205203
textAlign: 'center'

0 commit comments

Comments
 (0)