Skip to content

WheelPicker - initialValue prop updates - adding render test #1701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/incubator/WheelPicker/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import _ from 'lodash';
import React from 'react';
import {WheelPicker} from '../../../incubator';
import {Colors} from 'style';
import {render} from '@testing-library/react-native';
import {fireOnMomentumScrollEnd} from '../../../uilib-test-renderer';
import {Colors} from 'style';
import {WheelPicker} from '../../../incubator';


const ITEM_HEIGHT = 50;
const NUM_OF_ROWS = 7;
Expand All @@ -14,10 +15,10 @@ const TestCase = props => {
<WheelPicker
testID={'wheel'}
items={_.times(60, i => i).map(item => ({label: `${item}`, value: item}))}
initialValue={0}
onChange={onChangeMock}
numberOfVisibleRows={NUM_OF_ROWS}
itemHeight={ITEM_HEIGHT}
initialIndex={0}
activeTextColor={Colors.red30}
inactiveTextColor={Colors.blue30}
{...props}
Expand All @@ -26,17 +27,19 @@ const TestCase = props => {
};

describe('WheelPicker', () => {
beforeEach(() => {
onChangeMock.mockClear();
});

describe('FlatList', () => {
it('should call onChange callback after scrolling', () => {
const {getByTestId} = render(<TestCase/>);
const flatList = getByTestId('wheel.list');

fireOnMomentumScrollEnd(flatList, {y: 200});

expect(onChangeMock).toHaveBeenCalledWith(4, 4);

fireOnMomentumScrollEnd(flatList, {y: 330});

expect(onChangeMock).toHaveBeenCalledWith(7, 7);
});

Expand All @@ -48,6 +51,15 @@ describe('WheelPicker', () => {
});
});

describe('initialValue', () => {
it('should not call onChange when initialValue is updated', () => {
const {update} = render(<TestCase/>);

update(<TestCase initialValue={2}/>);
expect(onChangeMock).not.toHaveBeenCalled();
});
});

//TODO: make this test work
// describe('Item', () => {
// it('should set activeColor to the selected index', () => {
Expand All @@ -61,7 +73,7 @@ describe('WheelPicker', () => {
// expect(item_0).toHaveAnimatedStyle(activeStyle);
// expect(item_4).toHaveAnimatedStyle(inactiveStyle);

// fireEvent(flatList, 'onMomentumScrollEnd', {nativeEvent: {contentOffset: {y: 200}}});
// fireOnMomentumScrollEnd(flatList, {y: 200});

// expect(item_0).toHaveAnimatedStyle(inactiveStyle);
// expect(item_4).toHaveAnimatedStyle(activeStyle);
Expand Down