Skip to content

WheelPicker - render tests #1688

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 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {NativeModules, AccessibilityInfo} from 'react-native';

require('./node_modules/react-native-reanimated/src/reanimated2/jestUtils').setUpTests();

NativeModules.StatusBarManager = {getHeight: jest.fn()};
jest.spyOn(AccessibilityInfo, 'isScreenReaderEnabled').mockImplementation(() => new Promise.resolve(false));

Expand Down
1 change: 1 addition & 0 deletions src/incubator/WheelPicker/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const WheelPickerItem = memo(({
>
<AnimatedText
text60R
testID={`${testID}.text`}
style={[animatedColorStyle, style, fakeLabel ? styles.textWithLabelPadding : styles.textPadding]}
>
{label}
Expand Down
62 changes: 62 additions & 0 deletions src/incubator/WheelPicker/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import _ from 'lodash';
import React from 'react';
import {WheelPicker} from '../../../incubator';
import {fireEvent, render} from '@testing-library/react-native';

const ITEM_HEIGHT = 50;
const NUM_OF_ROWS = 7;
const onChange = jest.fn();
const props = {
testID: 'wheel',
items: _.times(60, i => i).map(item => ({label: `${item}`, value: item})),
onChange,
numberOfVisibleRows: NUM_OF_ROWS,
itemHeight: ITEM_HEIGHT,
initialIndex: 0,
activeTextColor: 'red',
inactiveTextColor: 'blue'
};

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

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

expect(onChange).toHaveBeenCalled();
expect(onChange).toHaveBeenCalledWith(4, 4);

fireEvent(flatList, 'onMomentumScrollEnd', {nativeEvent: {contentOffset: {y: 330}}});

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

it('should present 7 rows', () => {
const {getByTestId} = render(<WheelPicker {...props}/>);
const flatList = getByTestId('wheel.list');

expect(flatList.props.height).toBe(NUM_OF_ROWS * ITEM_HEIGHT);
});
});

// describe('Item', () => {
// it('should color selected index with activeColor', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is not very clear on what you want to test (where is the verb in this sentence?)

// const {getByTestId} = render(<WheelPicker {...props}/>);
// const flatList = getByTestId('wheel.list');
// const item_0 = getByTestId('wheel.item_0.text');
// const item_4 = getByTestId('wheel.item_4.text');
// const activeStyle = {color: 'red'};
// const inactiveStyle = {color: 'blue'};

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

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

// expect(item_0).toHaveAnimatedStyle(inactiveStyle);
// expect(item_4).toHaveAnimatedStyle(activeStyle);
// });
// });
});