File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { View , Text , StyleSheet , TouchableOpacity } from 'react-native' ;
3+ import { ViewProps } from 'react-native' ;
34import Icon from '../Icon' ;
45
56type 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
1920export 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 } >
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments