@@ -2,22 +2,18 @@ import {map} from 'lodash';
2
2
import React from 'react' ;
3
3
import { Text , View } from 'react-native' ;
4
4
import { fireOnMomentumScrollEnd } from '../../../uilib-test-renderer' ;
5
+ import { render } from '@testing-library/react-native' ;
5
6
import Carousel from '../index' ;
6
7
import { Constants } from '../../../commons/new' ;
7
- import { CarouselDriver } from '../Carousel.driver' ;
8
+ import { CarouselDriver } from '../Carousel.driver.new ' ;
8
9
9
10
const numberOfPagesShown = 5 ;
10
11
const onChangePageMock = jest . fn ( ) ;
11
12
const onScrollMock = jest . fn ( ) ;
12
13
const testID = 'carousel' ;
13
14
const TestCase = ( props : any ) => {
14
15
return (
15
- < Carousel
16
- testID = { testID }
17
- onChangePage = { onChangePageMock }
18
- onScroll = { onScrollMock }
19
- { ...props }
20
- >
16
+ < Carousel testID = { testID } onChangePage = { onChangePageMock } onScroll = { onScrollMock } { ...props } >
21
17
{ map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
22
18
< Page key = { index } >
23
19
< Text testID = { `page-${ index } ` } > Page #{ index } </ Text >
@@ -27,7 +23,7 @@ const TestCase = (props: any) => {
27
23
) ;
28
24
} ;
29
25
30
- const Page = ( { children, ...others } :{ children : React . ReactNode , others ?: any } ) => {
26
+ const Page = ( { children, ...others } : { children : React . ReactNode ; others ?: any } ) => {
31
27
return (
32
28
< View { ...others } style = { { flex : 1 } } >
33
29
{ children }
@@ -36,41 +32,43 @@ const Page = ({children, ...others}:{children: React.ReactNode, others?: any}) =
36
32
} ;
37
33
38
34
describe ( 'Carousel render tests' , ( ) => {
39
- afterEach ( ( ) => CarouselDriver . clear ( ) ) ;
40
-
41
35
describe ( 'initialPage' , ( ) => {
42
36
it ( 'should be set to default initialPage' , async ( ) => {
43
- const driver = new CarouselDriver ( { component : < TestCase /> , testID} ) ;
37
+ const renderTree = render ( < TestCase /> ) ;
38
+ const driver = CarouselDriver ( { renderTree, testID} ) ;
44
39
45
40
expect ( ( await driver . getContentOffset ( ) ) . x ) . toBe ( 0 ) ;
46
41
} ) ;
47
42
48
43
it ( 'should be set to initialPage = 2' , async ( ) => {
49
- const driver = new CarouselDriver ( { component : < TestCase initialPage = { 2 } /> , testID} ) ;
44
+ const renderTree = render ( < TestCase initialPage = { 2 } /> ) ;
45
+ const driver = CarouselDriver ( { renderTree, testID} ) ;
50
46
51
47
expect ( ( await driver . getContentOffset ( ) ) . x ) . toBe ( Constants . screenWidth * 2 ) ;
52
48
} ) ;
53
49
} ) ;
54
50
55
51
describe ( 'onScroll' , ( ) => {
56
52
it ( 'should trigger onScroll from the second scroll' , async ( ) => {
57
- const driver = new CarouselDriver ( { component : < TestCase /> , testID} ) ;
53
+ const renderTree = render ( < TestCase /> ) ;
54
+ const driver = CarouselDriver ( { renderTree, testID} ) ;
58
55
59
- await driver . scroll ( Constants . screenWidth ) ; //NOTE: first scroll doesn't fire onScroll
56
+ await driver . scroll ( { x : Constants . screenWidth } ) ; //NOTE: first scroll doesn't fire onScroll
60
57
expect ( onScrollMock ) . not . toHaveBeenCalled ( ) ;
61
58
62
- await driver . scroll ( Constants . screenWidth ) ;
59
+ await driver . scroll ( { x : Constants . screenWidth } ) ;
63
60
expect ( onScrollMock ) . toHaveBeenCalled ( ) ;
64
61
} ) ;
65
62
} ) ;
66
63
67
64
describe ( 'onChangePage' , ( ) => {
68
65
it ( 'should trigger onChangePage with current page' , async ( ) => {
69
- const driver = new CarouselDriver ( { component : < TestCase /> , testID} ) ;
66
+ const renderTree = render ( < TestCase /> ) ;
67
+ const driver = CarouselDriver ( { renderTree, testID} ) ;
70
68
const scrollView = await driver . getElement ( ) ;
71
69
72
- await driver . scroll ( Constants . screenWidth ) ; //NOTE: first scroll doesn't fire onScroll
73
- await driver . scroll ( Constants . screenWidth ) ;
70
+ await driver . scroll ( { x : Constants . screenWidth } ) ; //NOTE: first scroll doesn't fire onScroll
71
+ await driver . scroll ( { x : Constants . screenWidth } ) ;
74
72
expect ( onChangePageMock ) . not . toHaveBeenCalled ( ) ;
75
73
76
74
fireOnMomentumScrollEnd ( scrollView , { x : Constants . screenWidth } ) ;
0 commit comments