|
1 | 1 | import React from 'react';
|
2 | 2 | import {render} from '@testing-library/react-native';
|
3 |
| -import View from '../../view'; |
4 |
| -import Text from '../index'; |
5 | 3 | import {TextDriver} from '../Text.driver.new';
|
| 4 | +import {StyleSheet} from 'react-native'; |
6 | 5 |
|
7 | 6 | const TEXT_ID = 'text_test_id';
|
8 | 7 | const TEXT_CONTENT = 'text content';
|
9 | 8 |
|
10 | 9 | function WrapperScreenWithText(textProps: {onPress?: jest.Mock} = {}) {
|
11 | 10 | const {onPress} = textProps;
|
| 11 | + const Text = require('../index').default; |
12 | 12 | 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> |
18 | 16 | );
|
19 | 17 | }
|
20 | 18 |
|
| 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 | + |
21 | 26 | describe('Text', () => {
|
22 | 27 | it('should render Text Component', () => {
|
23 |
| - const renderTree = render(<WrapperScreenWithText/>); |
24 |
| - const textDriver = TextDriver({renderTree, testID: TEXT_ID}); |
| 28 | + const {textDriver} = getDriver(); |
25 | 29 | const content = textDriver.getText();
|
26 | 30 | expect(content).toEqual(TEXT_CONTENT);
|
27 | 31 | });
|
28 | 32 |
|
29 | 33 | describe('onPress', () => {
|
30 | 34 | it('should press the text, and run callback', () => {
|
31 | 35 | 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}); |
35 | 37 | textDriver.press();
|
36 |
| - |
37 | 38 | expect(onPressCallback).toHaveBeenCalledTimes(1);
|
38 | 39 | });
|
39 | 40 |
|
40 | 41 | 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(); |
43 | 43 | expect(textDriver.hasOnPress()).toBeFalsy();
|
44 | 44 | });
|
45 | 45 | });
|
| 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 | + }); |
46 | 91 | });
|
0 commit comments