Skip to content
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

[NoQA] add perf tests to OptionsSelector #33491

Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/components/OptionsList/BaseOptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ function BaseOptionsList({
onViewableItemsChanged={onViewableItemsChanged}
bounces={bounces}
ListFooterComponent={renderFooterContent}
testID="options-list"
/>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ class BaseOptionsSelector extends Component {
spellCheck={false}
shouldInterceptSwipe={this.props.shouldTextInputInterceptSwipe}
isLoading={this.props.isLoadingNewOptions}
testID="options-selector-input"
/>
);
const optionsList = (
Expand Down
130 changes: 130 additions & 0 deletions tests/perf-test/OptionsSelector.perf-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {fireEvent} from '@testing-library/react-native';
import React from 'react';
import {measurePerformance} from 'reassure';
import _ from 'underscore';
import OptionsSelector from '@src/components/OptionsSelector';
import CONST from '@src/CONST';
import variables from '@src/styles/variables';

jest.mock('../../src/components/withLocalize', () => (Component) => {
function WrappedComponent(props) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
translate={() => ''}
/>
);
}
WrappedComponent.displayName = `WrappedComponent`;
return WrappedComponent;
});

jest.mock('../../src/components/withNavigationFocus', () => (Component) => {
function WithNavigationFocus(props) {
return (
<Component
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
isFocused={false}
/>
);
}

WithNavigationFocus.displayName = 'WithNavigationFocus';

return WithNavigationFocus;
});

const generateSections = (sectionConfigs) =>
_.map(sectionConfigs, ({numItems, indexOffset, shouldShow = true}) => ({
data: Array.from({length: numItems}, (_v, i) => ({
text: `Item ${i + indexOffset}`,
keyForList: `item-${i + indexOffset}`,
})),
indexOffset,
shouldShow,
}));

const singleSectionSConfig = [{numItems: 1000, indexOffset: 0}];

const mutlipleSectionsConfig = [
{numItems: 1000, indexOffset: 0},
{numItems: 100, indexOffset: 70},
];

function OptionsSelectorWrapper(args) {
const sections = generateSections(singleSectionSConfig);
return (
<OptionsSelector
value="test"
sections={sections}
// eslint-disable-next-line react/jsx-props-no-spreading
{...args}
/>
);
}

const runs = CONST.PERFORMANCE_TESTS.RUNS;

test('[OptionsSelector] should render text input with interactions', () => {
const scenario = (screen) => {
const textInput = screen.getByTestId('options-selector-input');
fireEvent.changeText(textInput, 'test');
fireEvent.changeText(textInput, 'test2');
fireEvent.changeText(textInput, 'test3');
};

measurePerformance(<OptionsSelectorWrapper />, {scenario, runs});
});

test('[OptionsSelector] should render 1 section', () => {
measurePerformance(<OptionsSelectorWrapper />, {runs});
});

test('[OptionsSelector] should render mutliple sections', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
test('[OptionsSelector] should render mutliple sections', () => {
test('[OptionsSelector] should render multiple sections', () => {

const sections = generateSections(mutlipleSectionsConfig);
measurePerformance(<OptionsSelectorWrapper sections={sections} />, {runs});
});

test('[OptionsSelector] should press a list items', () => {
const scenario = (screen) => {
fireEvent.press(screen.getByText('Item 1'));
fireEvent.press(screen.getByText('Item 5'));
fireEvent.press(screen.getByText('Item 10'));
};

measurePerformance(<OptionsSelectorWrapper />, {scenario, runs});
});

test('[OptionsSelector] should scroll and press few items', () => {
const sections = generateSections(mutlipleSectionsConfig);

const generateEventData = (numOptions, optionRowHeight) => ({
nativeEvent: {
contentOffset: {
y: optionRowHeight * numOptions,
},
contentSize: {
height: optionRowHeight * 10,
width: 100,
},
layoutMeasurement: {
height: optionRowHeight * 5,
width: 100,
},
},
});

const eventData = generateEventData(100, variables.optionRowHeight);
const eventData2 = generateEventData(200, variables.optionRowHeight);
const scenario = (screen) => {
fireEvent.press(screen.getByText('Item 10'));
fireEvent.scroll(screen.getByTestId('options-list'), eventData);
fireEvent.press(screen.getByText('Item 100'));
fireEvent.scroll(screen.getByTestId('options-list'), eventData2);
fireEvent.press(screen.getByText('Item 200'));
};

measurePerformance(<OptionsSelectorWrapper sections={sections} />, {scenario, runs});
});
Loading