forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSidebarLinks.perf-test.tsx
More file actions
115 lines (97 loc) · 3.8 KB
/
Copy pathSidebarLinks.perf-test.tsx
File metadata and controls
115 lines (97 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {fireEvent, screen, waitFor} from '@testing-library/react-native';
import Onyx from 'react-native-onyx';
import {measureRenders} from 'reassure';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import * as LHNTestUtils from '../utils/LHNTestUtils';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import wrapInAct from '../utils/wrapInActHelper';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';
jest.mock('@libs/Permissions');
jest.mock('../../src/libs/Navigation/Navigation', () => ({
navigate: jest.fn(),
isActiveRoute: jest.fn(),
getTopmostReportId: jest.fn(),
getActiveRoute: jest.fn(),
getTopmostReportActionId: jest.fn(),
isNavigationReady: jest.fn(() => Promise.resolve()),
isDisplayedInModal: jest.fn(() => false),
}));
jest.mock('../../src/libs/Navigation/navigationRef', () => ({
getState: () => ({
routes: [{name: 'Report'}],
}),
getRootState: () => ({
routes: [],
}),
addListener: () => () => {},
}));
jest.mock('@components/Icon/Expensicons');
jest.mock('@react-navigation/native');
jest.mock('@src/hooks/useLHNEstimatedListSize/index.native.ts');
const getMockedReportsMap = (length = 100) => {
const mockReports = Object.fromEntries(
Array.from({length}, (value, index) => {
const reportID = index + 1;
const participants = [1, 2];
const reportKey = `${ONYXKEYS.COLLECTION.REPORT}${reportID}`;
const report = {...LHNTestUtils.getFakeReport(participants, 1, true), lastMessageText: 'hey'};
return [reportKey, report];
}),
);
return mockReports;
};
const mockedResponseMap = getMockedReportsMap(500);
describe('SidebarLinks', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
});
});
beforeEach(() => {
global.fetch = TestHelper.getGlobalFetchMock();
wrapOnyxWithWaitForBatchedUpdates(Onyx);
// Initialize the network key for OfflineWithFeedback
Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false});
TestHelper.signInWithTestUser(1, 'email1@test.com', undefined, undefined, 'One').then(waitForBatchedUpdates);
});
afterEach(() => {
Onyx.clear();
});
test('[SidebarLinks] should render Sidebar with 500 reports stored', async () => {
const scenario = async () => {
await waitFor(async () => {
// Query for the sidebar
await screen.findByTestId('lhn-options-list');
});
};
await waitForBatchedUpdates();
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
...mockedResponseMap,
});
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
});
test('[SidebarLinks] should click on list item', async () => {
const scenario = async () => {
await waitFor(async () => {
const button = await screen.findByTestId('1');
await wrapInAct(() => {
fireEvent.press(button);
});
});
};
await waitForBatchedUpdates();
Onyx.multiSet({
[ONYXKEYS.PERSONAL_DETAILS_LIST]: LHNTestUtils.fakePersonalDetails,
[ONYXKEYS.BETAS]: [CONST.BETAS.DEFAULT_ROOMS],
[ONYXKEYS.NVP_PRIORITY_MODE]: CONST.PRIORITY_MODE.GSD,
...mockedResponseMap,
});
await measureRenders(<LHNTestUtils.MockedSidebarLinks />, {scenario});
});
});