@@ -2,22 +2,18 @@ import {map} from 'lodash';
22import React from 'react' ;
33import { Text , View } from 'react-native' ;
44import { fireOnMomentumScrollEnd } from '../../../uilib-test-renderer' ;
5+ import { render } from '@testing-library/react-native' ;
56import Carousel from '../index' ;
67import { Constants } from '../../../commons/new' ;
7- import { CarouselDriver } from '../Carousel.driver' ;
8+ import { CarouselDriver } from '../Carousel.driver.new ' ;
89
910const numberOfPagesShown = 5 ;
1011const onChangePageMock = jest . fn ( ) ;
1112const onScrollMock = jest . fn ( ) ;
1213const testID = 'carousel' ;
1314const TestCase = ( props : any ) => {
1415 return (
15- < Carousel
16- testID = { testID }
17- onChangePage = { onChangePageMock }
18- onScroll = { onScrollMock }
19- { ...props }
20- >
16+ < Carousel testID = { testID } onChangePage = { onChangePageMock } onScroll = { onScrollMock } { ...props } >
2117 { map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
2218 < Page key = { index } >
2319 < Text testID = { `page-${ index } ` } > Page #{ index } </ Text >
@@ -27,7 +23,7 @@ const TestCase = (props: any) => {
2723 ) ;
2824} ;
2925
30- const Page = ( { children, ...others } :{ children : React . ReactNode , others ?: any } ) => {
26+ const Page = ( { children, ...others } : { children : React . ReactNode ; others ?: any } ) => {
3127 return (
3228 < View { ...others } style = { { flex : 1 } } >
3329 { children }
@@ -36,41 +32,43 @@ const Page = ({children, ...others}:{children: React.ReactNode, others?: any}) =
3632} ;
3733
3834describe ( 'Carousel render tests' , ( ) => {
39- afterEach ( ( ) => CarouselDriver . clear ( ) ) ;
40-
4135 describe ( 'initialPage' , ( ) => {
4236 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} ) ;
4439
4540 expect ( ( await driver . getContentOffset ( ) ) . x ) . toBe ( 0 ) ;
4641 } ) ;
4742
4843 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} ) ;
5046
5147 expect ( ( await driver . getContentOffset ( ) ) . x ) . toBe ( Constants . screenWidth * 2 ) ;
5248 } ) ;
5349 } ) ;
5450
5551 describe ( 'onScroll' , ( ) => {
5652 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} ) ;
5855
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
6057 expect ( onScrollMock ) . not . toHaveBeenCalled ( ) ;
6158
62- await driver . scroll ( Constants . screenWidth ) ;
59+ await driver . scroll ( { x : Constants . screenWidth } ) ;
6360 expect ( onScrollMock ) . toHaveBeenCalled ( ) ;
6461 } ) ;
6562 } ) ;
6663
6764 describe ( 'onChangePage' , ( ) => {
6865 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} ) ;
7068 const scrollView = await driver . getElement ( ) ;
7169
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 } ) ;
7472 expect ( onChangePageMock ) . not . toHaveBeenCalled ( ) ;
7573
7674 fireOnMomentumScrollEnd ( scrollView , { x : Constants . screenWidth } ) ;
0 commit comments