1- import type * as Navigation from '@react-navigation/native' ;
21import { fireEvent , screen , waitFor } from '@testing-library/react-native' ;
32import Onyx from 'react-native-onyx' ;
43import { measureRenders } from 'reassure' ;
54import CONST from '@src/CONST' ;
65import ONYXKEYS from '@src/ONYXKEYS' ;
7- import type { OnyxValues } from '@src/ONYXKEYS' ;
8- import type { ReportActions } from '@src/types/onyx' ;
9- import createRandomReportAction from '../utils/collections/reportActions' ;
10- import { createSidebarReportsWithActions as createReportsWithActions } from '../utils/collections/sidebarReports' ;
116import * as LHNTestUtils from '../utils/LHNTestUtils' ;
127import * as TestHelper from '../utils/TestHelper' ;
138import waitForBatchedUpdates from '../utils/waitForBatchedUpdates' ;
14- import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct' ;
159import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates' ;
1610
1711jest . mock ( '@libs/Permissions' ) ;
@@ -35,22 +29,8 @@ jest.mock('../../src/libs/Navigation/navigationRef', () => ({
3529 isReady : ( ) => true ,
3630} ) ) ;
3731jest . mock ( '@components/Icon/Expensicons' ) ;
38- jest . mock ( '@react-navigation/native' , ( ) => {
39- const actualNav = jest . requireActual < typeof Navigation > ( '@react-navigation/native' ) ;
4032
41- return {
42- ...actualNav ,
43- useNavigationState : ( ) => true ,
44- useRoute : jest . fn ( ) ,
45- useFocusEffect : jest . fn ( ) ,
46- useIsFocused : ( ) => true ,
47- useNavigation : ( ) => ( {
48- navigate : jest . fn ( ) ,
49- addListener : jest . fn ( ) ,
50- } ) ,
51- createNavigationContainerRef : jest . fn ( ) ,
52- } ;
53- } ) ;
33+ jest . mock ( '@react-navigation/native' ) ;
5434jest . mock ( '@src/hooks/useLHNEstimatedListSize/index.native.ts' ) ;
5535
5636const getMockedReportsMap = ( length = 100 ) => {
@@ -70,8 +50,6 @@ const getMockedReportsMap = (length = 100) => {
7050
7151const mockedResponseMap = getMockedReportsMap ( 500 ) ;
7252
73- const REPORTS_COUNT = 150 ;
74-
7553describe ( 'SidebarLinks' , ( ) => {
7654 beforeAll ( ( ) => {
7755 Onyx . init ( {
@@ -135,187 +113,4 @@ describe('SidebarLinks', () => {
135113
136114 await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
137115 } ) ;
138-
139- test ( '[SidebarLinks LHN] initial render with 150 reports and actions' , async ( ) => {
140- const { reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions ( REPORTS_COUNT ) ;
141-
142- const scenario = async ( ) => {
143- await screen . findByTestId ( 'lhn-options-list' ) ;
144- } ;
145-
146- await Onyx . multiSet ( {
147- [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : personalDetails ,
148- [ ONYXKEYS . BETAS ] : [ CONST . BETAS . DEFAULT_ROOMS ] ,
149- [ ONYXKEYS . NVP_PRIORITY_MODE ] : CONST . PRIORITY_MODE . GSD ,
150- [ ONYXKEYS . IS_LOADING_REPORT_DATA ] : false ,
151- ...reports ,
152- ...reportActions ,
153- ...reportNameValuePairs ,
154- ...policies ,
155- ...reportMetadata ,
156- } as Partial < OnyxValues > ) ;
157-
158- await waitForBatchedUpdatesWithAct ( ) ;
159-
160- await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
161- } ) ;
162-
163- test ( '[SidebarLinks LHN] re-render when single report action changes' , async ( ) => {
164- const { reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions ( REPORTS_COUNT ) ;
165-
166- await Onyx . multiSet ( {
167- [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : personalDetails ,
168- [ ONYXKEYS . BETAS ] : [ CONST . BETAS . DEFAULT_ROOMS ] ,
169- [ ONYXKEYS . NVP_PRIORITY_MODE ] : CONST . PRIORITY_MODE . GSD ,
170- [ ONYXKEYS . IS_LOADING_REPORT_DATA ] : false ,
171- ...reports ,
172- ...reportActions ,
173- ...reportNameValuePairs ,
174- ...policies ,
175- ...reportMetadata ,
176- } as Partial < OnyxValues > ) ;
177-
178- await waitForBatchedUpdates ( ) ;
179-
180- const scenario = async ( ) => {
181- await screen . findByTestId ( 'lhn-options-list' ) ;
182- const firstReportID = '1' ;
183- const actionsCollection = reportActions ?? { } ;
184- const firstReportActions = actionsCollection [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ firstReportID } ` ] ;
185- if ( firstReportActions ) {
186- const newAction = createRandomReportAction ( 999 ) ;
187- const updatedActions = {
188- ...firstReportActions ,
189- [ `${ firstReportID } _999` ] : newAction ,
190- } ;
191- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ firstReportID } ` , updatedActions ) ;
192- await waitForBatchedUpdatesWithAct ( ) ;
193- }
194- } ;
195-
196- await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
197- } ) ;
198-
199- test ( '[SidebarLinks LHN] re-render when multiple reports change' , async ( ) => {
200- const { reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions ( REPORTS_COUNT ) ;
201-
202- await Onyx . multiSet ( {
203- [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : personalDetails ,
204- [ ONYXKEYS . BETAS ] : [ CONST . BETAS . DEFAULT_ROOMS ] ,
205- [ ONYXKEYS . NVP_PRIORITY_MODE ] : CONST . PRIORITY_MODE . GSD ,
206- [ ONYXKEYS . IS_LOADING_REPORT_DATA ] : false ,
207- ...reports ,
208- ...reportActions ,
209- ...reportNameValuePairs ,
210- ...policies ,
211- ...reportMetadata ,
212- } as Partial < OnyxValues > ) ;
213-
214- await waitForBatchedUpdates ( ) ;
215-
216- const scenario = async ( ) => {
217- await screen . findByTestId ( 'lhn-options-list' ) ;
218- const updates : Record < string , ReportActions > = { } ;
219- const actionsCollection = reportActions ?? { } ;
220- for ( let i = 1 ; i <= 10 ; i ++ ) {
221- const reportID = String ( i ) ;
222- const existingActions = actionsCollection [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportID } ` ] ;
223- if ( existingActions ) {
224- const newAction = createRandomReportAction ( 1000 + i ) ;
225- updates [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportID } ` ] = {
226- ...existingActions ,
227- [ `${ reportID } _new` ] : newAction ,
228- } ;
229- }
230- }
231- await Onyx . multiSet ( updates as Partial < OnyxValues > ) ;
232- await waitForBatchedUpdatesWithAct ( ) ;
233- } ;
234-
235- await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
236- } ) ;
237-
238- test ( '[SidebarLinks LHN] re-render when report metadata changes' , async ( ) => {
239- const { reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions ( REPORTS_COUNT ) ;
240-
241- await Onyx . multiSet ( {
242- [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : personalDetails ,
243- [ ONYXKEYS . BETAS ] : [ CONST . BETAS . DEFAULT_ROOMS ] ,
244- [ ONYXKEYS . NVP_PRIORITY_MODE ] : CONST . PRIORITY_MODE . GSD ,
245- [ ONYXKEYS . IS_LOADING_REPORT_DATA ] : false ,
246- ...reports ,
247- ...reportActions ,
248- ...reportNameValuePairs ,
249- ...policies ,
250- ...reportMetadata ,
251- } as Partial < OnyxValues > ) ;
252-
253- await waitForBatchedUpdates ( ) ;
254-
255- const scenario = async ( ) => {
256- await screen . findByTestId ( 'lhn-options-list' ) ;
257- const firstReportID = '1' ;
258- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ firstReportID } ` , {
259- lastVisitTime : new Date ( ) . toISOString ( ) ,
260- } ) ;
261- await waitForBatchedUpdatesWithAct ( ) ;
262- } ;
263-
264- await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
265- } ) ;
266-
267- test ( '[SidebarLinks LHN] re-render when report archived status changes' , async ( ) => {
268- const { reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions ( REPORTS_COUNT ) ;
269-
270- await Onyx . multiSet ( {
271- [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : personalDetails ,
272- [ ONYXKEYS . BETAS ] : [ CONST . BETAS . DEFAULT_ROOMS ] ,
273- [ ONYXKEYS . NVP_PRIORITY_MODE ] : CONST . PRIORITY_MODE . GSD ,
274- [ ONYXKEYS . IS_LOADING_REPORT_DATA ] : false ,
275- ...reports ,
276- ...reportActions ,
277- ...reportNameValuePairs ,
278- ...policies ,
279- ...reportMetadata ,
280- } as Partial < OnyxValues > ) ;
281-
282- await waitForBatchedUpdates ( ) ;
283-
284- const scenario = async ( ) => {
285- await screen . findByTestId ( 'lhn-options-list' ) ;
286- const firstReportID = '1' ;
287- const nameValuePairsCollection = reportNameValuePairs ?? { } ;
288- const currentArchivedStatus = nameValuePairsCollection [ `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ firstReportID } ` ] ?. private_isArchived ;
289- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_NAME_VALUE_PAIRS } ${ firstReportID } ` , {
290- private_isArchived : currentArchivedStatus === 'true' ? 'false' : 'true' ,
291- } ) ;
292- await waitForBatchedUpdatesWithAct ( ) ;
293- } ;
294-
295- await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
296- } ) ;
297-
298- test ( '[SidebarLinks LHN] scaling test – initial render with 500 reports' , async ( ) => {
299- const { reports, reportActions, reportNameValuePairs, policies, personalDetails, reportMetadata} = createReportsWithActions ( 500 ) ;
300-
301- const scenario = async ( ) => {
302- await screen . findByTestId ( 'lhn-options-list' ) ;
303- } ;
304-
305- await Onyx . multiSet ( {
306- [ ONYXKEYS . PERSONAL_DETAILS_LIST ] : personalDetails ,
307- [ ONYXKEYS . BETAS ] : [ CONST . BETAS . DEFAULT_ROOMS ] ,
308- [ ONYXKEYS . NVP_PRIORITY_MODE ] : CONST . PRIORITY_MODE . GSD ,
309- [ ONYXKEYS . IS_LOADING_REPORT_DATA ] : false ,
310- ...reports ,
311- ...reportActions ,
312- ...reportNameValuePairs ,
313- ...policies ,
314- ...reportMetadata ,
315- } as Partial < OnyxValues > ) ;
316-
317- await waitForBatchedUpdatesWithAct ( ) ;
318-
319- await measureRenders ( < LHNTestUtils . MockedSidebarLinks /> , { scenario} ) ;
320- } ) ;
321116} ) ;
0 commit comments