-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 #37531 from VickyStash/ts-migration/tests-g10
[TS migration] Migrate 'SelectionList.perf-test.js', 'ReportActionItemSingleTest.js', 'LoginUtilsTest.js' and 'isEmptyString.js' tests to TypeScript
- Loading branch information
Showing
6 changed files
with
81 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import type {OnyxCollectionKey, OnyxCollectionValuesMapping} from '@src/ONYXKEYS'; | ||
|
||
/** Helps with typing a collection item update inside Onyx.multiSet call */ | ||
type CollectionDataSet<TCollectionKey extends OnyxCollectionKey> = Record<`${TCollectionKey}${string}`, OnyxCollectionValuesMapping[TCollectionKey]>; | ||
|
||
const toCollectionDataSet = <TCollectionKey extends OnyxCollectionKey>( | ||
collectionKey: TCollectionKey, | ||
collection: Array<OnyxEntry<OnyxCollectionValuesMapping[TCollectionKey]>>, | ||
idSelector: (collectionValue: OnyxCollectionValuesMapping[TCollectionKey]) => string, | ||
) => { | ||
const collectionDataSet = collection.reduce<CollectionDataSet<TCollectionKey>>((result, collectionValue) => { | ||
if (collectionValue) { | ||
// eslint-disable-next-line no-param-reassign | ||
result[`${collectionKey}${idSelector(collectionValue)}`] = collectionValue; | ||
} | ||
return result; | ||
}, {} as CollectionDataSet<TCollectionKey>); | ||
|
||
return collectionDataSet; | ||
}; | ||
|
||
export default CollectionDataSet; | ||
|
||
export {toCollectionDataSet}; |
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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import {cleanup, screen, waitFor} from '@testing-library/react-native'; | ||
import Onyx from 'react-native-onyx'; | ||
import type {PersonalDetailsList} from '@src/types/onyx'; | ||
import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; | ||
import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; | ||
|
@@ -12,13 +14,12 @@ const ONYXKEYS = { | |
POLICY: 'policy_', | ||
}, | ||
NETWORK: 'network', | ||
}; | ||
} as const; | ||
|
||
describe('ReportActionItemSingle', () => { | ||
beforeAll(() => | ||
Onyx.init({ | ||
keys: ONYXKEYS, | ||
registerStorageEventListener: () => {}, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
}), | ||
); | ||
|
@@ -42,9 +43,10 @@ describe('ReportActionItemSingle', () => { | |
const fakeReport = LHNTestUtils.getFakeReportWithPolicy([1, 2]); | ||
const fakeReportAction = LHNTestUtils.getFakeAdvancedReportAction(); | ||
const fakePolicy = LHNTestUtils.getFakePolicy(fakeReport.policyID); | ||
const fakePersonalDetails = { | ||
[fakeReportAction.actorAccountID]: { | ||
accountID: fakeReportAction.actorAccountID, | ||
const faceAccountId = fakeReportAction.actorAccountID ?? -1; | ||
const fakePersonalDetails: PersonalDetailsList = { | ||
[faceAccountId]: { | ||
accountID: faceAccountId, | ||
login: '[email protected]', | ||
displayName: 'Email One', | ||
avatar: 'https://example.com/avatar.png', | ||
|
@@ -57,11 +59,13 @@ describe('ReportActionItemSingle', () => { | |
}); | ||
|
||
function setup() { | ||
const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [fakePolicy], (item) => item.id); | ||
|
||
return waitForBatchedUpdates().then(() => | ||
Onyx.multiSet({ | ||
[ONYXKEYS.PERSONAL_DETAILS_LIST]: fakePersonalDetails, | ||
[ONYXKEYS.IS_LOADING_REPORT_DATA]: false, | ||
[`${ONYXKEYS.COLLECTION.POLICY}${fakeReport.policyID}`]: fakePolicy, | ||
...policyCollectionDataSet, | ||
}), | ||
); | ||
} | ||
|
@@ -77,10 +81,10 @@ describe('ReportActionItemSingle', () => { | |
}); | ||
|
||
it('renders Person information', () => { | ||
const [expectedPerson] = fakeReportAction.person; | ||
const [expectedPerson] = fakeReportAction.person ?? []; | ||
|
||
return setup().then(() => { | ||
expect(screen.getByText(expectedPerson.text)).toBeDefined(); | ||
expect(screen.getByText(expectedPerson.text ?? '')).toBeDefined(); | ||
}); | ||
}); | ||
}); | ||
|
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