Skip to content

Commit 0bdbe03

Browse files
committed
test(Tooltip): 增加测试用力
1 parent 6a65c94 commit 0bdbe03

File tree

4 files changed

+79
-4
lines changed

4 files changed

+79
-4
lines changed

packages/core/src/Toast/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Toast 轻提示
22
---
3+
![](https://user-images.githubusercontent.com/57083007/146734105-6e3c70bf-0d11-45d5-8bd4-c1e31738a4de.gif)<!--rehype:style=zoom: 33%;-->
4+
35

46
一种轻量级反馈/提示,可以用来显示不会打断用户操作的内容,适合用于页面转场、数据交互的等场景中。
57

68
组件基于[`react-native-root-siblings`](https://github.com/magicismight/react-native-root-siblings) 插件开发, 当 `react native >= 0.62` 时,需要在程序中插入一个装入容器
79

8-
![](https://user-images.githubusercontent.com/57083007/146734105-6e3c70bf-0d11-45d5-8bd4-c1e31738a4de.gif)<!--rehype:style=zoom: 33%;float: right; margin-left: 15px;-->
9-
1010
```jsx
1111
import { RootSiblingParent } from 'react-native-root-siblings';
1212

packages/core/src/Tooltip/Cloud.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class Cloud extends React.Component<CloudProps> {
4646
},
4747
]}
4848
/>
49-
<View style={[{ ...TextContainerStyle }]}>
49+
<View testID="RNE__Tooltip__cloud__view" style={[{ ...TextContainerStyle }]}>
5050
<Text style={[styles.cloudText]}>{title}</Text>
5151
</View>
5252
</View>

packages/core/src/Tooltip/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default class Tooltip extends React.Component<TooltipProps, TooltipState>
135135
return (
136136
<View>
137137
<Modal
138+
testID="RNE__Tooltip__wrap"
138139
animationType="fade" // slide none fade
139140
transparent={true}
140141
visible={this.state.modalVisible}
@@ -173,7 +174,7 @@ export default class Tooltip extends React.Component<TooltipProps, TooltipState>
173174
</Animated.View>
174175
</Modal>
175176

176-
<Pressable {...{ [toggleAction]: this.onOpen }} delayLongPress={250}>
177+
<Pressable testID="RNE__Tooltip__pressable" {...{ [toggleAction]: this.onOpen }} delayLongPress={250}>
177178
<View style={[styles.followView, { ...this.state.followStyle }]} ref={this.refFollow}>
178179
{children}
179180
</View>

test-ci/src/__tests__/tooltip.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)