forked from Expensify/react-native-onyx
-
Notifications
You must be signed in to change notification settings - Fork 1
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 Expensify#565 from gedu/edu/keychanged_improvement
key changed improvement
- Loading branch information
Showing
3 changed files
with
120 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import OnyxUtils from '../../lib/OnyxUtils'; | ||
|
||
describe('OnyxUtils', () => { | ||
it('splitCollectionMemberKey should return correct values', () => { | ||
const dataResult: Record<string, [string, string]> = { | ||
test_: ['test_', ''], | ||
test_level_: ['test_level_', ''], | ||
test_level_1: ['test_level_', '1'], | ||
test_level_2: ['test_level_', '2'], | ||
test_level_last_3: ['test_level_last_', '3'], | ||
}; | ||
|
||
Object.keys(dataResult).forEach((key) => { | ||
const [collectionKey, id] = OnyxUtils.splitCollectionMemberKey(key); | ||
expect(collectionKey).toEqual(dataResult[key][0]); | ||
expect(id).toEqual(dataResult[key][1]); | ||
}); | ||
}); | ||
|
||
it('splitCollectionMemberKey should throw error if key does not contain underscore', () => { | ||
expect(() => { | ||
OnyxUtils.splitCollectionMemberKey('test'); | ||
}).toThrowError('Invalid test key provided, only collection keys are allowed.'); | ||
expect(() => { | ||
OnyxUtils.splitCollectionMemberKey(''); | ||
}).toThrowError('Invalid key provided, only collection keys are allowed.'); | ||
}); | ||
|
||
it('getCollectionKey should return correct values', () => { | ||
const dataResult: Record<string, string> = { | ||
test: 'test', | ||
test_: 'test_', | ||
test_level_: 'test_level_', | ||
test_level_1: 'test_level_', | ||
test_level_2: 'test_level_', | ||
test_level_last_3: 'test_level_last_', | ||
}; | ||
|
||
Object.keys(dataResult).forEach((key) => { | ||
const collectionKey = OnyxUtils.getCollectionKey(key); | ||
expect(collectionKey).toEqual(dataResult[key]); | ||
}); | ||
}); | ||
}); |