Skip to content

Commit 4aab5c4

Browse files
wj0990xingyuefeng
authored andcommitted
feat:(steps)新增测试用例
1 parent 9641652 commit 4aab5c4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

packages/core/src/Steps/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
3+
import { ViewProps } from 'react-native';
34
import Icon from '../Icon';
45

56
type statusType = 'success' | 'error' | string;
@@ -10,22 +11,22 @@ export interface StepsItemsProps {
1011
status?: statusType;
1112
}
1213

13-
export interface StepsProps {
14+
export interface StepsProps extends ViewProps {
1415
items: StepsItemsProps[];
1516
current?: number;
1617
onChange?: (value: number) => void;
1718
}
1819

1920
export default (props: StepsProps) => {
20-
const { items = [], current = 0, onChange } = props;
21+
const { items = [], current = 0, onChange, ...others } = props;
2122

2223
const onStepsPress = (index: number) => {
2324
// onChange?.(index);
2425
onChange && onChange(current);
2526
};
2627

2728
return (
28-
<View style={styles.steps}>
29+
<View style={styles.steps} {...others}>
2930
{items.map((item, index) => (
3031
<TouchableOpacity style={[styles.item]} key={index} onPress={() => onStepsPress(index)}>
3132
<View style={styles.wrap}>

test-ci/src/__tests__/steps.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import Steps, { StepsItemsProps } from '../lib/Steps';
8+
import TestRenderer, { act } from 'react-test-renderer';
9+
10+
describe('Steps', () => {
11+
const items: StepsItemsProps[] = [
12+
{ title: '步骤一', desc: '这里是额外的信息,这里是额外的信息' },
13+
{ title: '步骤二', desc: '这里是额外的信息,这里是额' },
14+
{ title: '步骤三', desc: '这里是' },
15+
];
16+
17+
it('Steps', () => {
18+
const testRender = TestRenderer.create(<Steps items={items} current={1} />);
19+
expect(testRender.root.props.current).toBe(1);
20+
expect(testRender.root.props.items).toMatchObject(items);
21+
});
22+
23+
it('should handle onChange event', () => {
24+
const onChange = jest.fn();
25+
const testRender = TestRenderer.create(<Steps testID="Steps" items={items} current={1} onChange={onChange} />);
26+
const testInstance = testRender.root;
27+
act(() => {
28+
testInstance.findByProps({ testID: 'Steps' }).props.onChange(1);
29+
});
30+
expect(onChange).toHaveBeenCalledTimes(1);
31+
});
32+
});

0 commit comments

Comments
 (0)