1
1
import _ from 'lodash' ;
2
2
import React from 'react' ;
3
- import { WheelPicker } from '../../../incubator' ;
4
- import { Colors } from 'style' ;
5
3
import { render } from '@testing-library/react-native' ;
6
4
import { fireOnMomentumScrollEnd } from '../../../uilib-test-renderer' ;
5
+ import { Colors } from 'style' ;
6
+ import { WheelPicker } from '../../../incubator' ;
7
+
7
8
8
9
const ITEM_HEIGHT = 50 ;
9
10
const NUM_OF_ROWS = 7 ;
@@ -14,10 +15,10 @@ const TestCase = props => {
14
15
< WheelPicker
15
16
testID = { 'wheel' }
16
17
items = { _ . times ( 60 , i => i ) . map ( item => ( { label : `${ item } ` , value : item } ) ) }
18
+ initialValue = { 0 }
17
19
onChange = { onChangeMock }
18
20
numberOfVisibleRows = { NUM_OF_ROWS }
19
21
itemHeight = { ITEM_HEIGHT }
20
- initialIndex = { 0 }
21
22
activeTextColor = { Colors . red30 }
22
23
inactiveTextColor = { Colors . blue30 }
23
24
{ ...props }
@@ -26,17 +27,19 @@ const TestCase = props => {
26
27
} ;
27
28
28
29
describe ( 'WheelPicker' , ( ) => {
30
+ beforeEach ( ( ) => {
31
+ onChangeMock . mockClear ( ) ;
32
+ } ) ;
33
+
29
34
describe ( 'FlatList' , ( ) => {
30
35
it ( 'should call onChange callback after scrolling' , ( ) => {
31
36
const { getByTestId} = render ( < TestCase /> ) ;
32
37
const flatList = getByTestId ( 'wheel.list' ) ;
33
38
34
39
fireOnMomentumScrollEnd ( flatList , { y : 200 } ) ;
35
-
36
40
expect ( onChangeMock ) . toHaveBeenCalledWith ( 4 , 4 ) ;
37
41
38
42
fireOnMomentumScrollEnd ( flatList , { y : 330 } ) ;
39
-
40
43
expect ( onChangeMock ) . toHaveBeenCalledWith ( 7 , 7 ) ;
41
44
} ) ;
42
45
@@ -48,6 +51,15 @@ describe('WheelPicker', () => {
48
51
} ) ;
49
52
} ) ;
50
53
54
+ describe ( 'initialValue' , ( ) => {
55
+ it ( 'should not call onChange when initialValue is updated' , ( ) => {
56
+ const { update} = render ( < TestCase /> ) ;
57
+
58
+ update ( < TestCase initialValue = { 2 } /> ) ;
59
+ expect ( onChangeMock ) . not . toHaveBeenCalled ( ) ;
60
+ } ) ;
61
+ } ) ;
62
+
51
63
//TODO: make this test work
52
64
// describe('Item', () => {
53
65
// it('should set activeColor to the selected index', () => {
@@ -61,7 +73,7 @@ describe('WheelPicker', () => {
61
73
// expect(item_0).toHaveAnimatedStyle(activeStyle);
62
74
// expect(item_4).toHaveAnimatedStyle(inactiveStyle);
63
75
64
- // fireEvent (flatList, 'onMomentumScrollEnd', {nativeEvent: {contentOffset: { y: 200}} });
76
+ // fireOnMomentumScrollEnd (flatList, { y: 200});
65
77
66
78
// expect(item_0).toHaveAnimatedStyle(inactiveStyle);
67
79
// expect(item_4).toHaveAnimatedStyle(activeStyle);
0 commit comments