-
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] [Reassure] SearchPage perf tests #33872
Merged
mountiny
merged 9 commits into
Expensify:main
from
callstack-internal:feat/SearchPage-reassure-perf-tests
Jan 19, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d6159ca
feat: initial SearchPage reassure tests setup
rinej 2e5041e
feat: added reassure tests for SearchPage
rinej e840140
feat: add reassure tests for SearchPage, mock navigation
rinej e13f88e
Merge branch 'main' into feat/SearchPage-reassure-perf-tests
rinej db3f77d
refactor: fix prettier and typo
rinej c8b23a5
refactor: use different method for mocking personal data
rinej e1a73ab
feat: create larger personal detail list
rinej bddd3b6
refactor: use createCollection for mocking colections
rinej 34b2c49
refactor: move createAddListenerMock to separate file, add comments
rinej 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import {act, fireEvent, screen} from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import Onyx from 'react-native-onyx'; | ||
import {measurePerformance} from 'reassure'; | ||
import _ from 'underscore'; | ||
import SearchPage from '@pages/SearchPage'; | ||
import ComposeProviders from '../../src/components/ComposeProviders'; | ||
import {LocaleContextProvider} from '../../src/components/LocaleContextProvider'; | ||
import OnyxProvider from '../../src/components/OnyxProvider'; | ||
import {CurrentReportIDContextProvider} from '../../src/components/withCurrentReportID'; | ||
import {KeyboardStateProvider} from '../../src/components/withKeyboardState'; | ||
import {WindowDimensionsProvider} from '../../src/components/withWindowDimensions'; | ||
import CONST from '../../src/CONST'; | ||
import ONYXKEYS from '../../src/ONYXKEYS'; | ||
import createCollection from '../utils/collections/createCollection'; | ||
import createPersonalDetails from '../utils/collections/personalDetails'; | ||
import createRandomReport from '../utils/collections/reports'; | ||
import PusherHelper from '../utils/PusherHelper'; | ||
import * as TestHelper from '../utils/TestHelper'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; | ||
|
||
jest.mock('../../src/libs/Navigation/Navigation'); | ||
|
||
const mockedNavigate = jest.fn(); | ||
jest.mock('@react-navigation/native', () => { | ||
const actualNav = jest.requireActual('@react-navigation/native'); | ||
return { | ||
...actualNav, | ||
useFocusEffect: jest.fn(), | ||
useIsFocused: () => ({ | ||
navigate: mockedNavigate, | ||
}), | ||
useRoute: () => jest.fn(), | ||
useNavigation: () => ({ | ||
navigate: jest.fn(), | ||
addListener: () => jest.fn(), | ||
}), | ||
createNavigationContainerRef: jest.fn(), | ||
}; | ||
}); | ||
|
||
const getMockedReports = (length = 100) => | ||
createCollection( | ||
(item) => `${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`, | ||
(index) => createRandomReport(index), | ||
length, | ||
); | ||
|
||
const getMockedPersonalDetails = (length = 100) => | ||
createCollection( | ||
(item) => item.accountID, | ||
(index) => createPersonalDetails(index), | ||
length, | ||
); | ||
|
||
const mockedReports = getMockedReports(600); | ||
const mockedBetas = _.values(CONST.BETAS); | ||
const mockedPersonalDetails = getMockedPersonalDetails(100); | ||
|
||
beforeAll(() => | ||
Onyx.init({ | ||
keys: ONYXKEYS, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT], | ||
registerStorageEventListener: () => {}, | ||
}), | ||
); | ||
|
||
// Initialize the network key for OfflineWithFeedback | ||
beforeEach(() => { | ||
global.fetch = TestHelper.getGlobalFetchMock(); | ||
wrapOnyxWithWaitForBatchedUpdates(Onyx); | ||
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); | ||
}); | ||
|
||
// Clear out Onyx after each test so that each test starts with a clean state | ||
afterEach(() => { | ||
Onyx.clear(); | ||
PusherHelper.teardown(); | ||
}); | ||
|
||
function SearchPageWrapper(args) { | ||
return ( | ||
<ComposeProviders components={[OnyxProvider, CurrentReportIDContextProvider, KeyboardStateProvider, WindowDimensionsProvider, LocaleContextProvider]}> | ||
<SearchPage | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...args} | ||
navigation={args.navigation} | ||
/> | ||
</ComposeProviders> | ||
); | ||
} | ||
|
||
const runs = CONST.PERFORMANCE_TESTS.RUNS; | ||
|
||
test('[Search Page] should interact when text input changes', async () => { | ||
const {addListener} = TestHelper.createAddListenerMock(); | ||
|
||
const scenario = async () => { | ||
await screen.findByTestId('SearchPage'); | ||
|
||
const input = screen.getByTestId('options-selector-input'); | ||
fireEvent.changeText(input, 'Email Four'); | ||
fireEvent.changeText(input, 'Report'); | ||
fireEvent.changeText(input, 'Email Five'); | ||
}; | ||
|
||
const navigation = {addListener}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
...mockedReports, | ||
[ONYXKEYS.IS_SIDEBAR_LOADED]: true, | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, | ||
[ONYXKEYS.BETAS]: mockedBetas, | ||
[ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, | ||
}), | ||
) | ||
.then(() => measurePerformance(<SearchPageWrapper navigation={navigation} />, {scenario, runs})); | ||
}); | ||
|
||
test('[Search Page] should render options list', async () => { | ||
const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); | ||
const smallMockedPersonalDetails = getMockedPersonalDetails(5); | ||
|
||
const scenario = async () => { | ||
await screen.findByTestId('SearchPage'); | ||
await act(triggerTransitionEnd); | ||
await screen.findByText(smallMockedPersonalDetails['1'].login); | ||
await screen.findByText(smallMockedPersonalDetails['2'].login); | ||
}; | ||
|
||
const navigation = {addListener}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
...mockedReports, | ||
[ONYXKEYS.IS_SIDEBAR_LOADED]: true, | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: smallMockedPersonalDetails, | ||
[ONYXKEYS.BETAS]: mockedBetas, | ||
[ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, | ||
}), | ||
) | ||
.then(() => measurePerformance(<SearchPageWrapper navigation={navigation} />, {scenario, runs})); | ||
}); | ||
|
||
test('[Search Page] should search in options list', async () => { | ||
const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); | ||
|
||
const scenario = async () => { | ||
await screen.findByTestId('SearchPage'); | ||
const input = screen.getByTestId('options-selector-input'); | ||
|
||
fireEvent.changeText(input, mockedPersonalDetails['88'].login); | ||
await act(triggerTransitionEnd); | ||
await screen.findByText(mockedPersonalDetails['88'].login); | ||
|
||
fireEvent.changeText(input, mockedPersonalDetails['45'].login); | ||
await act(triggerTransitionEnd); | ||
await screen.findByText(mockedPersonalDetails['45'].login); | ||
}; | ||
|
||
const navigation = {addListener}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
...mockedReports, | ||
[ONYXKEYS.IS_SIDEBAR_LOADED]: true, | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, | ||
[ONYXKEYS.BETAS]: mockedBetas, | ||
[ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, | ||
}), | ||
) | ||
.then(() => measurePerformance(<SearchPageWrapper navigation={navigation} />, {scenario, runs})); | ||
}); | ||
|
||
test('[Search Page] should click on list item', async () => { | ||
const {triggerTransitionEnd, addListener} = TestHelper.createAddListenerMock(); | ||
|
||
const scenario = async () => { | ||
await screen.findByTestId('SearchPage'); | ||
const input = screen.getByTestId('options-selector-input'); | ||
|
||
fireEvent.changeText(input, mockedPersonalDetails['6'].login); | ||
await act(triggerTransitionEnd); | ||
const optionButton = await screen.findByText(mockedPersonalDetails['6'].login); | ||
|
||
fireEvent.press(optionButton); | ||
}; | ||
|
||
const navigation = {addListener}; | ||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
...mockedReports, | ||
[ONYXKEYS.IS_SIDEBAR_LOADED]: true, | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: mockedPersonalDetails, | ||
[ONYXKEYS.BETAS]: mockedBetas, | ||
[ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: true, | ||
}), | ||
) | ||
.then(() => measurePerformance(<SearchPageWrapper navigation={navigation} />, {scenario, runs})); | ||
}); |
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
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.
Can you please add a comment here to adhere with the style rules. Thanks!
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.
ideally noting this is for automated tests
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.
sure, will do