-
Notifications
You must be signed in to change notification settings - Fork 3k
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
mountiny
merged 1 commit into
Expensify:main
from
callstack-internal:feat/33229/OptionsSelector-reassure-perf-tests
Dec 27, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', () => { | ||
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}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.