Skip to content

Commit 00daf34

Browse files
authored
WheelPicker - initialValue updates - adding render test (#1701)
1 parent 0d2701c commit 00daf34

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/incubator/WheelPicker/__tests__/index.spec.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import _ from 'lodash';
22
import React from 'react';
3-
import {WheelPicker} from '../../../incubator';
4-
import {Colors} from 'style';
53
import {render} from '@testing-library/react-native';
64
import {fireOnMomentumScrollEnd} from '../../../uilib-test-renderer';
5+
import {Colors} from 'style';
6+
import {WheelPicker} from '../../../incubator';
7+
78

89
const ITEM_HEIGHT = 50;
910
const NUM_OF_ROWS = 7;
@@ -14,10 +15,10 @@ const TestCase = props => {
1415
<WheelPicker
1516
testID={'wheel'}
1617
items={_.times(60, i => i).map(item => ({label: `${item}`, value: item}))}
18+
initialValue={0}
1719
onChange={onChangeMock}
1820
numberOfVisibleRows={NUM_OF_ROWS}
1921
itemHeight={ITEM_HEIGHT}
20-
initialIndex={0}
2122
activeTextColor={Colors.red30}
2223
inactiveTextColor={Colors.blue30}
2324
{...props}
@@ -26,17 +27,19 @@ const TestCase = props => {
2627
};
2728

2829
describe('WheelPicker', () => {
30+
beforeEach(() => {
31+
onChangeMock.mockClear();
32+
});
33+
2934
describe('FlatList', () => {
3035
it('should call onChange callback after scrolling', () => {
3136
const {getByTestId} = render(<TestCase/>);
3237
const flatList = getByTestId('wheel.list');
3338

3439
fireOnMomentumScrollEnd(flatList, {y: 200});
35-
3640
expect(onChangeMock).toHaveBeenCalledWith(4, 4);
3741

3842
fireOnMomentumScrollEnd(flatList, {y: 330});
39-
4043
expect(onChangeMock).toHaveBeenCalledWith(7, 7);
4144
});
4245

@@ -48,6 +51,15 @@ describe('WheelPicker', () => {
4851
});
4952
});
5053

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+
5163
//TODO: make this test work
5264
// describe('Item', () => {
5365
// it('should set activeColor to the selected index', () => {
@@ -61,7 +73,7 @@ describe('WheelPicker', () => {
6173
// expect(item_0).toHaveAnimatedStyle(activeStyle);
6274
// expect(item_4).toHaveAnimatedStyle(inactiveStyle);
6375

64-
// fireEvent(flatList, 'onMomentumScrollEnd', {nativeEvent: {contentOffset: {y: 200}}});
76+
// fireOnMomentumScrollEnd(flatList, {y: 200});
6577

6678
// expect(item_0).toHaveAnimatedStyle(inactiveStyle);
6779
// expect(item_4).toHaveAnimatedStyle(activeStyle);

0 commit comments

Comments
 (0)