Skip to content

Commit c2d3bc0

Browse files
authored
Merge pull request #483 from huqiaoli/dev
test(Radio):添加Radio测试用例
2 parents 4ab8166 + 7798cab commit c2d3bc0

File tree

3 files changed

+70
-23
lines changed

3 files changed

+70
-23
lines changed

packages/core/src/Badge/README.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,11 @@ export default Demo;
4747

4848
继承 [View](https://facebook.github.io/react-native/docs/view#props) 组件。
4949

50-
```ts
51-
import { ViewProps } from 'react-native';
52-
53-
export interface BadgeProps extends ViewProps {
54-
children?: React.ReactNode;
55-
/** 标记颜色 */
56-
color?: colors.Colors | string;
57-
/** 文本内容 */
58-
text?: string | Element;
59-
/**
60-
* 设置圆角,默认 `12`
61-
*/
62-
rounded?: number;
63-
/** 设置类型 */
64-
type?: 'dot' | 'text';
65-
/** 文本样式 */
66-
textStyles?: StyleProp<TextStyle>;
67-
}
68-
```
50+
| 属性 | 说明 | 类型 | 默认值 |
51+
| --- | --- | --- | --- |
52+
| color | 标记颜色 | `colors.Colors \| string` | - |
53+
| text | 文本内容 | `string \| Element` | - |
54+
| rounded | 设置圆角 | `boolean \| number` | `12` |
55+
| textStyles | 文本样式 | `StyleProp<TextStyle>` | - |
56+
| type | 设置类型 | `'dot' \| 'text'` | - |
57+
| children | 更多内容 | `React.ReactNode` | - |

packages/core/src/Radio/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,21 @@ export default class Radio extends Component<RadioProps, RadioState> {
132132
const backgroundColor = disabled ? color : checkedColor;
133133
const borderColor = disabled ? color : bdColor;
134134
return (
135-
<View style={[styles.defalut, style]} {...otherProps}>
136-
<TouchableOpacity disabled={disabled} style={[styles.touch]} onPress={this.handlePress}>
137-
<Animated.View style={[styles.checkBg, { width: circleSize, height: circleSize, borderColor }]}>
138-
<Animated.View style={[styles.check, { width: sizeValue, height: sizeValue, backgroundColor }]} />
135+
<View testID="RNE__Radio__wrap" style={[styles.defalut, style]} {...otherProps}>
136+
<TouchableOpacity
137+
disabled={disabled}
138+
style={[styles.touch]}
139+
onPress={this.handlePress}
140+
testID="RNE__Radio__view"
141+
>
142+
<Animated.View
143+
style={[styles.checkBg, { width: circleSize, height: circleSize, borderColor }]}
144+
testID="RNE__Radio__border"
145+
>
146+
<Animated.View
147+
style={[styles.check, { width: sizeValue, height: sizeValue, backgroundColor }]}
148+
testID="RNE__Radio__box"
149+
/>
139150
</Animated.View>
140151
{this.props.children && (
141152
<MaybeTextOrView

test-ci/src/__tests__/radio.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'react-native';
2+
import React from 'react';
3+
import Radio from '../lib/Radio';
4+
import { render, fireEvent } from '@testing-library/react-native';
5+
6+
describe('Radio', () => {
7+
it('disabled', () => {
8+
const { getByTestId } = render(<Radio disabled />);
9+
const component = getByTestId('RNE__Radio__view');
10+
expect(component.props.accessibilityState.disabled).toBe(true);
11+
});
12+
13+
it('borderColor', () => {
14+
const { getByTestId } = render(<Radio borderColor="#bdc1cc" />);
15+
const component = getByTestId('RNE__Radio__border');
16+
expect(component.props.style.borderColor).toBe('#bdc1cc');
17+
});
18+
19+
it('checkedColor', () => {
20+
const { getByTestId } = render(<Radio checkedColor="#008EF0" />);
21+
const component = getByTestId('RNE__Radio__box');
22+
expect(component.props.style.backgroundColor).toBe('#008EF0');
23+
});
24+
25+
it('circleSize', () => {
26+
const { getByTestId } = render(<Radio circleSize={21} />);
27+
const component = getByTestId('RNE__Radio__border');
28+
expect(component.props.style.width).toBe(21);
29+
expect(component.props.style.height).toBe(21);
30+
});
31+
32+
it('onPress events', () => {
33+
const fn = jest.fn();
34+
const { getByTestId } = render(<Radio onPress={fn} />);
35+
const component = getByTestId('RNE__Radio__view');
36+
fireEvent(component, 'press');
37+
expect(fn).toHaveBeenCalled();
38+
});
39+
40+
it('disabled onPress events', () => {
41+
const fn = jest.fn();
42+
const { getByTestId } = render(<Radio disabled onPress={fn} />);
43+
const component = getByTestId('RNE__Radio__view');
44+
fireEvent(component, 'press');
45+
expect(fn).not.toHaveBeenCalled();
46+
});
47+
});

0 commit comments

Comments
 (0)