11import { measureAsyncFunction , measureFunction } from 'reassure' ;
2- import { createCollection } from '../utils/collections/createCollection' ;
3- import createRandomReportAction from '../utils/collections/reportActions' ;
2+ import createRandomReportAction , { getRandomReportActions } from '../utils/collections/reportActions' ;
43import type { OnyxKey , Selector } from '../../lib' ;
54import Onyx from '../../lib' ;
65import StorageMock from '../../lib/storage' ;
76import OnyxUtils from '../../lib/OnyxUtils' ;
87import type GenericCollection from '../utils/GenericCollection' ;
98import type { Mapping , OnyxUpdate } from '../../lib/Onyx' ;
10- import type { WithOnyxInstance } from '../../lib/withOnyx/types' ;
119import createDeferredTask from '../../lib/createDeferredTask' ;
1210import type { OnyxInputKeyValueMapping } from '../../lib/types' ;
11+ import generateEmptyWithOnyxInstance from '../utils/generateEmptyWithOnyxInstance' ;
1312
1413const ONYXKEYS = {
1514 TEST_KEY : 'test' ,
@@ -31,18 +30,6 @@ const safeEvictionKeys = [ONYXKEYS.COLLECTION.EVICTABLE_TEST_KEY];
3130
3231const initialKeyStates = { } ;
3332
34- const collectionKey = ONYXKEYS . COLLECTION . TEST_KEY ;
35-
36- const generateEmptyWithOnyxInstance = ( ) => {
37- return new ( class {
38- // eslint-disable-next-line @typescript-eslint/no-empty-function
39- setStateProxy ( ) { }
40-
41- // eslint-disable-next-line @typescript-eslint/no-empty-function
42- setWithOnyxState ( ) { }
43- } ) ( ) as unknown as WithOnyxInstance ;
44- } ;
45-
4633// @ts -expect-error bypass
4734const generateTestSelector = ( ) : Selector < string , unknown , unknown > => ( value : Record < string , unknown > ) => {
4835 return {
@@ -51,14 +38,8 @@ const generateTestSelector = (): Selector<string, unknown, unknown> => (value: R
5138 } ;
5239} ;
5340
54- const getMockedReportActions = ( collection = collectionKey , length = 10000 ) =>
55- createCollection < Record < string , unknown > > (
56- ( item ) => `${ collection } ${ item . reportActionID } ` ,
57- ( index ) => createRandomReportAction ( index ) ,
58- length ,
59- ) ;
60-
61- const mockedReportActionsMap = getMockedReportActions ( ) ;
41+ const collectionKey = ONYXKEYS . COLLECTION . TEST_KEY ;
42+ const mockedReportActionsMap = getRandomReportActions ( collectionKey ) ;
6243const mockedReportActionsKeys = Object . keys ( mockedReportActionsMap ) ;
6344
6445const clearOnyxAfterEachMeasure = async ( ) => {
@@ -107,11 +88,11 @@ describe('OnyxUtils', () => {
10788 describe ( 'initStoreValues' , ( ) => {
10889 test ( 'one call with 50k heavy objects' , async ( ) => {
10990 const data = {
110- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY ) ,
111- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_2 ) ,
112- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_3 ) ,
113- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_4 ) ,
114- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_5 ) ,
91+ ...getRandomReportActions ( collectionKey ) ,
92+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_2 ) ,
93+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_3 ) ,
94+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_4 ) ,
95+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_5 ) ,
11596 } ;
11697
11798 await measureFunction ( ( ) => OnyxUtils . initStoreValues ( ONYXKEYS , data , safeEvictionKeys ) , {
@@ -165,12 +146,12 @@ describe('OnyxUtils', () => {
165146
166147 describe ( 'isCollectionKey' , ( ) => {
167148 test ( 'one call' , async ( ) => {
168- await measureFunction ( ( ) => OnyxUtils . isCollectionKey ( ONYXKEYS . COLLECTION . TEST_KEY ) ) ;
149+ await measureFunction ( ( ) => OnyxUtils . isCollectionKey ( collectionKey ) ) ;
169150 } ) ;
170151 } ) ;
171152
172153 describe ( 'isCollectionMemberKey' , ( ) => {
173- const collectionKeyLength = ONYXKEYS . COLLECTION . TEST_KEY . length ;
154+ const collectionKeyLength = collectionKey . length ;
174155
175156 test ( 'one call with correct key' , async ( ) => {
176157 await measureFunction ( ( ) => OnyxUtils . isCollectionMemberKey ( collectionKey , `${ collectionKey } entry1` , collectionKeyLength ) ) ;
@@ -211,8 +192,8 @@ describe('OnyxUtils', () => {
211192 const key = `${ collectionKey } 0` ;
212193 const reportAction = mockedReportActionsMap [ `${ collectionKey } 0` ] ;
213194 const collections = {
214- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_2 ) ,
215- ...getMockedReportActions ( collectionKey ) ,
195+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_2 ) ,
196+ ...getRandomReportActions ( collectionKey ) ,
216197 } ;
217198
218199 test ( 'one call passing normal key without selector' , async ( ) => {
@@ -266,7 +247,7 @@ describe('OnyxUtils', () => {
266247
267248 describe ( 'removeLastAccessedKey' , ( ) => {
268249 test ( 'one call removing one key' , async ( ) => {
269- await measureFunction ( ( ) => OnyxUtils . removeLastAccessedKey ( `${ ONYXKEYS . COLLECTION . TEST_KEY } 5000` ) , {
250+ await measureFunction ( ( ) => OnyxUtils . removeLastAccessedKey ( `${ collectionKey } 5000` ) , {
270251 beforeEach : async ( ) => {
271252 mockedReportActionsKeys . forEach ( ( key ) => OnyxUtils . addLastAccessedKey ( key ) ) ;
272253 } ,
@@ -279,7 +260,7 @@ describe('OnyxUtils', () => {
279260
280261 describe ( 'addLastAccessedKey' , ( ) => {
281262 test ( 'one call adding one key' , async ( ) => {
282- await measureFunction ( ( ) => OnyxUtils . addLastAccessedKey ( `${ ONYXKEYS . COLLECTION . TEST_KEY } 5000` ) , {
263+ await measureFunction ( ( ) => OnyxUtils . addLastAccessedKey ( `${ collectionKey } 5000` ) , {
283264 beforeEach : async ( ) => {
284265 mockedReportActionsKeys . forEach ( ( key ) => OnyxUtils . addLastAccessedKey ( key ) ) ;
285266 } ,
@@ -292,8 +273,8 @@ describe('OnyxUtils', () => {
292273
293274 describe ( 'addAllSafeEvictionKeysToRecentlyAccessedList' , ( ) => {
294275 const data = {
295- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY , 1000 ) ,
296- ...getMockedReportActions ( ONYXKEYS . COLLECTION . EVICTABLE_TEST_KEY , 1000 ) ,
276+ ...getRandomReportActions ( collectionKey , 1000 ) ,
277+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . EVICTABLE_TEST_KEY , 1000 ) ,
297278 } ;
298279
299280 test ( 'one call adding 1k keys' , async ( ) => {
@@ -309,11 +290,11 @@ describe('OnyxUtils', () => {
309290 describe ( 'getCachedCollection' , ( ) => {
310291 test ( 'one call retrieving a collection with 5k heavy objects' , async ( ) => {
311292 const data = {
312- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY , 5000 ) ,
313- ...getMockedReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_2 , 5000 ) ,
293+ ...getRandomReportActions ( collectionKey , 5000 ) ,
294+ ...getRandomReportActions ( ONYXKEYS . COLLECTION . TEST_KEY_2 , 5000 ) ,
314295 } ;
315296
316- await measureFunction ( ( ) => OnyxUtils . getCachedCollection ( ONYXKEYS . COLLECTION . TEST_KEY ) , {
297+ await measureFunction ( ( ) => OnyxUtils . getCachedCollection ( collectionKey ) , {
317298 beforeEach : async ( ) => {
318299 await Onyx . multiSet ( data ) ;
319300 } ,
@@ -807,7 +788,7 @@ describe('OnyxUtils', () => {
807788 const skippableCollectionMemberIDs = OnyxUtils . getSkippableCollectionMemberIDs ( ) ;
808789 await measureFunction ( ( ) => OnyxUtils . getSkippableCollectionMemberIDs ( ) , {
809790 beforeEach : async ( ) => {
810- OnyxUtils . setSkippableCollectionMemberIDs ( new Set ( [ ONYXKEYS . COLLECTION . TEST_KEY , ONYXKEYS . COLLECTION . TEST_KEY_2 ] ) ) ;
791+ OnyxUtils . setSkippableCollectionMemberIDs ( new Set ( [ collectionKey , ONYXKEYS . COLLECTION . TEST_KEY_2 ] ) ) ;
811792 } ,
812793 afterEach : async ( ) => {
813794 OnyxUtils . setSkippableCollectionMemberIDs ( skippableCollectionMemberIDs ) ;
@@ -819,7 +800,7 @@ describe('OnyxUtils', () => {
819800 describe ( 'setSkippableCollectionMemberIDs' , ( ) => {
820801 test ( 'one call' , async ( ) => {
821802 const skippableCollectionMemberIDs = OnyxUtils . getSkippableCollectionMemberIDs ( ) ;
822- await measureFunction ( ( ) => OnyxUtils . setSkippableCollectionMemberIDs ( new Set ( [ ONYXKEYS . COLLECTION . TEST_KEY , ONYXKEYS . COLLECTION . TEST_KEY_2 ] ) ) , {
803+ await measureFunction ( ( ) => OnyxUtils . setSkippableCollectionMemberIDs ( new Set ( [ collectionKey , ONYXKEYS . COLLECTION . TEST_KEY_2 ] ) ) , {
823804 afterEach : async ( ) => {
824805 OnyxUtils . setSkippableCollectionMemberIDs ( skippableCollectionMemberIDs ) ;
825806 } ,
0 commit comments