|
| 1 | +import { View, Text } from 'react-native'; |
| 2 | +import React from 'react'; |
| 3 | +import Tooltip from '../lib/Tooltip'; |
| 4 | +import { render, fireEvent } from '@testing-library/react-native'; |
| 5 | +import { toObject } from '../utils'; |
| 6 | + |
| 7 | +describe('Tooltip', () => { |
| 8 | + it('title', () => { |
| 9 | + const { getByTestId, getByText } = render( |
| 10 | + <Tooltip title="标题"> |
| 11 | + <View> |
| 12 | + <Text>我是一个文本</Text> |
| 13 | + </View> |
| 14 | + </Tooltip>, |
| 15 | + ); |
| 16 | + const pressable = getByTestId('RNE__Tooltip__pressable'); |
| 17 | + fireEvent(pressable, 'press'); |
| 18 | + expect(getByText('标题')).toBeTruthy(); |
| 19 | + }); |
| 20 | + it('height', () => { |
| 21 | + const { getByTestId } = render( |
| 22 | + <Tooltip title="标题" height={80}> |
| 23 | + <View> |
| 24 | + <Text>我是一个文本</Text> |
| 25 | + </View> |
| 26 | + </Tooltip>, |
| 27 | + ); |
| 28 | + const pressable = getByTestId('RNE__Tooltip__pressable'); |
| 29 | + fireEvent(pressable, 'press'); |
| 30 | + const component = getByTestId('RNE__Tooltip__wrap'); |
| 31 | + expect(component.props.height).toBe(80); |
| 32 | + }); |
| 33 | + it('width', () => { |
| 34 | + const { getByTestId } = render( |
| 35 | + <Tooltip title="标题" width={100}> |
| 36 | + <View> |
| 37 | + <Text>我是一个文本</Text> |
| 38 | + </View> |
| 39 | + </Tooltip>, |
| 40 | + ); |
| 41 | + const pressable = getByTestId('RNE__Tooltip__pressable'); |
| 42 | + fireEvent(pressable, 'press'); |
| 43 | + const component = getByTestId('RNE__Tooltip__wrap'); |
| 44 | + expect(component.props.width).toBe(100); |
| 45 | + }); |
| 46 | + it('backgroundColor', () => { |
| 47 | + const { getByTestId } = render( |
| 48 | + <Tooltip backgroundColor="red" title="标题"> |
| 49 | + <View> |
| 50 | + <Text>我是一个文本</Text> |
| 51 | + </View> |
| 52 | + </Tooltip>, |
| 53 | + ); |
| 54 | + const pressable = getByTestId('RNE__Tooltip__pressable'); |
| 55 | + fireEvent(pressable, 'press'); |
| 56 | + const component = getByTestId('RNE__Tooltip__cloud__view'); |
| 57 | + const styles = toObject(component.props.style); |
| 58 | + expect(styles.backgroundColor).toBe('red'); |
| 59 | + }); |
| 60 | + it('borderRadius', () => { |
| 61 | + const { getByTestId } = render( |
| 62 | + <Tooltip borderRadius={10} title="标题"> |
| 63 | + <View> |
| 64 | + <Text>我是一个文本</Text> |
| 65 | + </View> |
| 66 | + </Tooltip>, |
| 67 | + ); |
| 68 | + const pressable = getByTestId('RNE__Tooltip__pressable'); |
| 69 | + fireEvent(pressable, 'press'); |
| 70 | + const component = getByTestId('RNE__Tooltip__cloud__view'); |
| 71 | + const styles = toObject(component.props.style); |
| 72 | + expect(styles.borderRadius).toBe(10); |
| 73 | + }); |
| 74 | +}); |
0 commit comments