Skip to content

Commit cbf2933

Browse files
committed
test(Radio):添加Radio测试用例
1 parent 6a65c94 commit cbf2933

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

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)