-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29083 from adhorodyski/feat/27641/reassure-lhn
feat(27641): Performance tests of LHN with Reassure
- Loading branch information
Showing
9 changed files
with
140 additions
and
161 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,57 +1,122 @@ | ||
import {measurePerformance} from 'reassure'; | ||
import Onyx from 'react-native-onyx'; | ||
import {fireEvent, screen} from '@testing-library/react-native'; | ||
import _ from 'underscore'; | ||
import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
import CONST from '../../src/CONST'; | ||
import ONYXKEYS from '../../src/ONYXKEYS'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; | ||
import variables from '../../src/styles/variables'; | ||
|
||
jest.setTimeout(10000); | ||
|
||
jest.mock('../../src/libs/Permissions'); | ||
jest.mock('../../src/libs/Navigation/Navigation'); | ||
jest.mock('../../src/components/Icon/Expensicons'); | ||
|
||
const ONYXKEYS = { | ||
PERSONAL_DETAILS: 'personalDetails', | ||
NVP_PRIORITY_MODE: 'nvp_priorityMode', | ||
SESSION: 'session', | ||
BETAS: 'betas', | ||
COLLECTION: { | ||
REPORT: 'report_', | ||
REPORT_ACTIONS: 'reportActions_', | ||
}, | ||
NETWORK: 'network', | ||
}; | ||
jest.mock('@react-navigation/native'); | ||
|
||
beforeAll(() => | ||
Onyx.init({ | ||
keys: ONYXKEYS, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
registerStorageEventListener: () => {}, | ||
}), | ||
); | ||
|
||
// Initialize the network key for OfflineWithFeedback | ||
beforeEach(() => Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false})); | ||
beforeEach(() => { | ||
wrapOnyxWithWaitForBatchedUpdates(Onyx); | ||
return Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); | ||
}); | ||
|
||
// Clear out Onyx after each test so that each test starts with a clean slate | ||
afterEach(() => { | ||
Onyx.clear(); | ||
}); | ||
|
||
test('simple Sidebar render with hundred of reports', () => { | ||
const mockReports = Array.from({length: 100}, (__, i) => { | ||
const getMockedReportsMap = (length = 100) => { | ||
const mockReports = Array.from({length}, (__, i) => { | ||
const reportID = i + 1; | ||
const emails = [`email${reportID}@test.com`]; | ||
const participants = [1, 2]; | ||
const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; | ||
const report = LHNTestUtils.getFakeReport(emails, 1, false); | ||
const report = LHNTestUtils.getFakeReport(participants, 1, true); | ||
|
||
return {[reportKey]: report}; | ||
}); | ||
const mockOnyxReports = _.assign({}, ...mockReports); | ||
|
||
return _.assign({}, ...mockReports); | ||
}; | ||
|
||
const mockedResponseMap = getMockedReportsMap(500); | ||
|
||
test('should render Sidebar with 500 reports stored', () => { | ||
const scenario = async () => { | ||
// Query for the sidebar | ||
await screen.findByTestId('lhn-options-list'); | ||
/** | ||
* Query for display names of participants [1, 2]. | ||
* This will ensure that the sidebar renders a list of items. | ||
*/ | ||
await screen.findAllByText('One, Two'); | ||
}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, | ||
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS], | ||
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD, | ||
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false, | ||
...mockedResponseMap, | ||
}), | ||
) | ||
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />, {scenario})); | ||
}); | ||
|
||
test('should scroll and click some of the items', () => { | ||
const scenario = async () => { | ||
const eventData = { | ||
nativeEvent: { | ||
contentOffset: { | ||
y: variables.optionRowHeight * 5, | ||
}, | ||
contentSize: { | ||
// Dimensions of the scrollable content | ||
height: variables.optionRowHeight * 10, | ||
width: 100, | ||
}, | ||
layoutMeasurement: { | ||
// Dimensions of the device | ||
height: variables.optionRowHeight * 5, | ||
width: 100, | ||
}, | ||
}, | ||
}; | ||
|
||
const lhnOptionsList = await screen.findByTestId('lhn-options-list'); | ||
expect(lhnOptionsList).toBeDefined(); | ||
|
||
fireEvent.scroll(lhnOptionsList, eventData); | ||
|
||
const button1 = await screen.findByTestId('1'); | ||
const button2 = await screen.findByTestId('2'); | ||
fireEvent.press(button1); | ||
fireEvent.press(button2); | ||
}; | ||
|
||
return waitForBatchedUpdates() | ||
.then(() => | ||
Onyx.multiSet({ | ||
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.DEFAULT, | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails, | ||
...mockOnyxReports, | ||
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS, CONST.BETAS.POLICY_ROOMS], | ||
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD, | ||
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false, | ||
...mockedResponseMap, | ||
}), | ||
) | ||
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />)); | ||
.then(() => measurePerformance(<LHNTestUtils.MockedSidebarLinks />, {scenario})); | ||
}); |
Oops, something went wrong.