|
1 | 1 | import {act} from '@testing-library/react-native'; |
2 | 2 | import Onyx from '../../lib'; |
3 | | -import OnyxKeys from '../../lib/OnyxKeys'; |
4 | 3 | import OnyxUtils from '../../lib/OnyxUtils'; |
5 | 4 | import type {GenericDeepRecord} from '../types'; |
6 | 5 | import utils from '../../lib/utils'; |
@@ -95,48 +94,6 @@ describe('OnyxUtils', () => { |
95 | 94 |
|
96 | 95 | afterEach(() => jest.clearAllMocks()); |
97 | 96 |
|
98 | | - describe('splitCollectionMemberKey', () => { |
99 | | - describe('should return correct values', () => { |
100 | | - const dataResult: Record<string, [string, string]> = { |
101 | | - test_: ['test_', ''], |
102 | | - test_level_: ['test_level_', ''], |
103 | | - test_level_1: ['test_level_', '1'], |
104 | | - test_level_2: ['test_level_', '2'], |
105 | | - test_level_last_3: ['test_level_last_', '3'], |
106 | | - test___FAKE__: ['test_', '__FAKE__'], |
107 | | - 'test_-1_something': ['test_', '-1_something'], |
108 | | - 'test_level_-1_something': ['test_level_', '-1_something'], |
109 | | - }; |
110 | | - |
111 | | - it.each(Object.keys(dataResult))('%s', (key) => { |
112 | | - const [collectionKey, id] = OnyxKeys.splitCollectionMemberKey(key); |
113 | | - expect(collectionKey).toEqual(dataResult[key][0]); |
114 | | - expect(id).toEqual(dataResult[key][1]); |
115 | | - }); |
116 | | - }); |
117 | | - |
118 | | - it('should throw error if key does not contain underscore', () => { |
119 | | - expect(() => { |
120 | | - OnyxKeys.splitCollectionMemberKey(ONYXKEYS.TEST_KEY); |
121 | | - }).toThrowError("Invalid 'test' key provided, only collection keys are allowed."); |
122 | | - expect(() => { |
123 | | - OnyxKeys.splitCollectionMemberKey(''); |
124 | | - }).toThrowError("Invalid '' key provided, only collection keys are allowed."); |
125 | | - }); |
126 | | - |
127 | | - it('should allow passing the collection key beforehand for performance gains', () => { |
128 | | - const [collectionKey, id] = OnyxKeys.splitCollectionMemberKey(`${ONYXKEYS.COLLECTION.TEST_KEY}id1`, ONYXKEYS.COLLECTION.TEST_KEY); |
129 | | - expect(collectionKey).toEqual(ONYXKEYS.COLLECTION.TEST_KEY); |
130 | | - expect(id).toEqual('id1'); |
131 | | - }); |
132 | | - |
133 | | - it("should throw error if the passed collection key isn't compatible with the key", () => { |
134 | | - expect(() => { |
135 | | - OnyxKeys.splitCollectionMemberKey(`${ONYXKEYS.COLLECTION.TEST_KEY}id1`, ONYXKEYS.COLLECTION.TEST_LEVEL_KEY); |
136 | | - }).toThrowError("Invalid 'test_level_' collection key provided, it isn't compatible with 'test_id1' key."); |
137 | | - }); |
138 | | - }); |
139 | | - |
140 | 97 | describe('partialSetCollection', () => { |
141 | 98 | beforeEach(() => { |
142 | 99 | Onyx.clear(); |
@@ -324,61 +281,6 @@ describe('OnyxUtils', () => { |
324 | 281 | }); |
325 | 282 | }); |
326 | 283 |
|
327 | | - describe('getCollectionKey', () => { |
328 | | - describe('should return correct values', () => { |
329 | | - const dataResult: Record<string, string> = { |
330 | | - test_: 'test_', |
331 | | - test_level_: 'test_level_', |
332 | | - test_level_1: 'test_level_', |
333 | | - test_level_2: 'test_level_', |
334 | | - test_level_last_3: 'test_level_last_', |
335 | | - test___FAKE__: 'test_', |
336 | | - 'test_-1_something': 'test_', |
337 | | - 'test_level_-1_something': 'test_level_', |
338 | | - }; |
339 | | - |
340 | | - it.each(Object.keys(dataResult))('%s', (key) => { |
341 | | - const collectionKey = OnyxKeys.getCollectionKey(key); |
342 | | - expect(collectionKey).toEqual(dataResult[key]); |
343 | | - }); |
344 | | - }); |
345 | | - |
346 | | - it('should return undefined if key does not contain underscore', () => { |
347 | | - expect(OnyxKeys.getCollectionKey(ONYXKEYS.TEST_KEY)).toBeUndefined(); |
348 | | - expect(OnyxKeys.getCollectionKey('')).toBeUndefined(); |
349 | | - }); |
350 | | - }); |
351 | | - |
352 | | - describe('isCollectionMember', () => { |
353 | | - it('should return true for collection member keys', () => { |
354 | | - expect(OnyxKeys.isCollectionMember('test_123')).toBe(true); |
355 | | - expect(OnyxKeys.isCollectionMember('test_level_456')).toBe(true); |
356 | | - expect(OnyxKeys.isCollectionMember('test_level_last_789')).toBe(true); |
357 | | - expect(OnyxKeys.isCollectionMember('test_-1_something')).toBe(true); |
358 | | - expect(OnyxKeys.isCollectionMember('routes_abc')).toBe(true); |
359 | | - }); |
360 | | - |
361 | | - it('should return false for collection keys themselves', () => { |
362 | | - expect(OnyxKeys.isCollectionMember('test_')).toBe(false); |
363 | | - expect(OnyxKeys.isCollectionMember('test_level_')).toBe(false); |
364 | | - expect(OnyxKeys.isCollectionMember('test_level_last_')).toBe(false); |
365 | | - expect(OnyxKeys.isCollectionMember('routes_')).toBe(false); |
366 | | - }); |
367 | | - |
368 | | - it('should return false for non-collection keys', () => { |
369 | | - expect(OnyxKeys.isCollectionMember('test')).toBe(false); |
370 | | - expect(OnyxKeys.isCollectionMember('someRegularKey')).toBe(false); |
371 | | - expect(OnyxKeys.isCollectionMember('notACollection')).toBe(false); |
372 | | - expect(OnyxKeys.isCollectionMember('')).toBe(false); |
373 | | - }); |
374 | | - |
375 | | - it('should return false for invalid keys', () => { |
376 | | - expect(OnyxKeys.isCollectionMember('invalid_key_123')).toBe(false); |
377 | | - expect(OnyxKeys.isCollectionMember('notregistered_')).toBe(false); |
378 | | - expect(OnyxKeys.isCollectionMember('notregistered_123')).toBe(false); |
379 | | - }); |
380 | | - }); |
381 | | - |
382 | 284 | describe('mergeChanges', () => { |
383 | 285 | it("should return the last change if it's an array", () => { |
384 | 286 | const {result} = OnyxUtils.mergeChanges([...testMergeChanges, [0, 1, 2]], testObject); |
@@ -493,32 +395,6 @@ describe('OnyxUtils', () => { |
493 | 395 | }); |
494 | 396 | }); |
495 | 397 |
|
496 | | - describe('isRamOnlyKey', () => { |
497 | | - it('should return true for RAM-only key', () => { |
498 | | - expect(OnyxKeys.isRamOnlyKey(ONYXKEYS.RAM_ONLY_KEY)).toBeTruthy(); |
499 | | - }); |
500 | | - |
501 | | - it('should return true for RAM-only collection', () => { |
502 | | - expect(OnyxKeys.isRamOnlyKey(ONYXKEYS.COLLECTION.RAM_ONLY_COLLECTION)).toBeTruthy(); |
503 | | - }); |
504 | | - |
505 | | - it('should return true for RAM-only collection member', () => { |
506 | | - expect(OnyxKeys.isRamOnlyKey(`${ONYXKEYS.COLLECTION.RAM_ONLY_COLLECTION}1`)).toBeTruthy(); |
507 | | - }); |
508 | | - |
509 | | - it('should return false for a normal key', () => { |
510 | | - expect(OnyxKeys.isRamOnlyKey(ONYXKEYS.TEST_KEY)).toBeFalsy(); |
511 | | - }); |
512 | | - |
513 | | - it('should return false for normal collection', () => { |
514 | | - expect(OnyxKeys.isRamOnlyKey(ONYXKEYS.COLLECTION.TEST_KEY)).toBeFalsy(); |
515 | | - }); |
516 | | - |
517 | | - it('should return false for normal collection member', () => { |
518 | | - expect(OnyxKeys.isRamOnlyKey(`${ONYXKEYS.COLLECTION.TEST_KEY}1`)).toBeFalsy(); |
519 | | - }); |
520 | | - }); |
521 | | - |
522 | 398 | describe('afterInit', () => { |
523 | 399 | beforeEach(() => { |
524 | 400 | // Resets the deferred init task before each test. |
|
0 commit comments