Skip to content

Automation gap - WOAUILIB-3704 #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions src/components/text/__tests__/index.driver.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,71 @@
import React from 'react';
import {render} from '@testing-library/react-native';
import View from '../../view';
import Text from '../index';
import {TextDriver} from '../Text.driver.new';
import {StyleSheet} from 'react-native';

const TEXT_ID = 'text_test_id';
const TEXT_CONTENT = 'text content';

function WrapperScreenWithText(textProps: {onPress?: jest.Mock} = {}) {
const {onPress} = textProps;
const Text = require('../../text').default;
return (
<View>
<Text testID={TEXT_ID} onPress={onPress}>
{TEXT_CONTENT}
</Text>
</View>
<Text testID={TEXT_ID} onPress={onPress}>
{TEXT_CONTENT}
</Text>
);
}

const getDriver = (textProps: {onPress?: jest.Mock} = {}) => {
const {onPress} = textProps;
const renderTree = render(<WrapperScreenWithText onPress={onPress}/>);
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
return {renderTree, textDriver};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need to return renderTree here

};

describe('Text', () => {
it('should render Text Component', () => {
const renderTree = render(<WrapperScreenWithText/>);
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
const {textDriver} = getDriver();
const content = textDriver.getText();
expect(content).toEqual(TEXT_CONTENT);
});

describe('onPress', () => {
it('should press the text, and run callback', () => {
const onPressCallback = jest.fn();
const renderTree = render(<WrapperScreenWithText onPress={onPressCallback}/>);
const textDriver = TextDriver({renderTree, testID: TEXT_ID});

const {textDriver} = getDriver({onPress: onPressCallback});
textDriver.press();

expect(onPressCallback).toHaveBeenCalledTimes(1);
});

it('should not be pressable if onPress prop is not supplied', () => {
const renderTree = render(<WrapperScreenWithText/>);
const textDriver = TextDriver({renderTree, testID: TEXT_ID});
const {textDriver} = getDriver();
expect(textDriver.hasOnPress()).toBeFalsy();
});
});
});
const setConstants = (isAndroid: boolean, isRTL: boolean) => {
const {Constants} = require('../../../commons/new');
Constants.isAndroid = isAndroid;
Constants.isIOS = !isAndroid;
Constants.isRTL = isRTL;
};

describe('Automation gap', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding tests for LTR as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For text? Or in general?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same tests but with LTR

it('Should render text on right on rtl - Android', () => {
jest.isolateModules(() => {
setConstants(true, true);
const {textDriver} = getDriver();
const textStyle = textDriver.getProps().style;
expect(StyleSheet.flatten(textStyle).textAlign).toEqual('left');
});
});
it('Should render text on right on rtl - IOS', () => {
jest.isolateModules(() => {
setConstants(false, true);
const {textDriver} = getDriver();
const textStyle = textDriver.getProps().style;
expect(StyleSheet.flatten(textStyle).writingDirection).toEqual('rtl');
});
});
});
14 changes: 6 additions & 8 deletions src/components/text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
TextProps as RNTextProps,
TextStyle,
Animated,
StyleProp,
Platform
StyleProp
} from 'react-native';
import {
asBaseComponent,
Expand Down Expand Up @@ -192,14 +191,13 @@ const styles = StyleSheet.create({
container: {
backgroundColor: 'transparent',
color: Colors.$textDefault,
...Platform.select({
ios: {
...(Constants.isIOS
? {
writingDirection: Constants.isRTL ? writingDirectionTypes.RTL : writingDirectionTypes.LTR
},
android: {
textAlign: 'left'
}
})
: {
textAlign: 'left'
})
},
centered: {
textAlign: 'center'
Expand Down