@@ -27,6 +27,18 @@ const props = {
27
27
//animatedScrollOffset: // set to check Animated
28
28
} ;
29
29
30
+ const TestCase = props => {
31
+ return (
32
+ < Carousel { ...props } >
33
+ { map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
34
+ < Page key = { index } >
35
+ < Text testID = { `page-${ index } ` } > Page #{ index } </ Text >
36
+ </ Page >
37
+ ) ) }
38
+ </ Carousel >
39
+ ) ;
40
+ } ;
41
+
30
42
const Page = ( { children, ...others } ) => {
31
43
return (
32
44
< View { ...others } style = { { flex : 1 } } >
@@ -35,29 +47,17 @@ const Page = ({children, ...others}) => {
35
47
) ;
36
48
} ;
37
49
38
- describe ( 'Carousel tests' , ( ) => {
50
+ describe ( 'Carousel render tests' , ( ) => {
51
+
39
52
describe ( 'default setup' , ( ) => {
40
53
it ( 'should be set to default' , ( ) => {
41
- const component = render ( < Carousel { ...props } >
42
- { map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
43
- < Page key = { index } >
44
- < Text testID = { `page-${ index } ` } > Page #{ index } </ Text >
45
- </ Page >
46
- ) ) }
47
- </ Carousel > ) ;
54
+ const component = render ( < TestCase { ...props } /> ) ;
48
55
49
56
component . getByText ( 'Page #0' ) ; // Validates that the text is there
50
57
} ) ;
51
58
52
59
it ( 'should trigger onScroll from the second scroll' , ( ) => {
53
- const component = render ( < Carousel { ...props } >
54
- { map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
55
- < Page key = { index } >
56
- < Text testID = { `page-${ index } ` } > Page #{ index } </ Text >
57
- </ Page >
58
- ) ) }
59
- </ Carousel > ) ;
60
-
60
+ const component = render ( < TestCase { ...props } /> ) ;
61
61
const scrollView = component . getByTestId ( 'carousel.scrollView' ) ;
62
62
63
63
fireEvent . scroll ( scrollView , eventData ) ; //NOTE: first scroll will no fire onScroll
@@ -68,14 +68,7 @@ describe('Carousel tests', () => {
68
68
} ) ;
69
69
70
70
it ( 'should trigger onChangePage with current page' , async ( ) => {
71
- const component = render ( < Carousel { ...props } >
72
- { map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
73
- < Page key = { index } >
74
- < Text testID = { `page-${ index } ` } > Page #{ index } </ Text >
75
- </ Page >
76
- ) ) }
77
- </ Carousel > ) ;
78
-
71
+ const component = render ( < TestCase { ...props } /> ) ;
79
72
const scrollView = component . getByTestId ( 'carousel.scrollView' ) ;
80
73
81
74
fireEvent . scroll ( scrollView , eventData ) ; //NOTE: first scroll will no fire onScroll
0 commit comments