-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 #29324 from waterim/feat-29271-remove-parseISO
Feat: Remove parseISO
- Loading branch information
Showing
4 changed files
with
94 additions
and
7 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
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,7 +1,32 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import CONST from '../../src/CONST'; | ||
import ONYXKEYS from '../../src/ONYXKEYS'; | ||
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates'; | ||
import * as ReportActionsUtils from '../../src/libs/ReportActionsUtils'; | ||
import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
|
||
describe('ReportActionsUtils', () => { | ||
beforeAll(() => | ||
Onyx.init({ | ||
keys: ONYXKEYS, | ||
registerStorageEventListener: () => {}, | ||
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS], | ||
}), | ||
); | ||
|
||
beforeEach(() => { | ||
// Wrap Onyx each onyx action with waitForBatchedUpdates | ||
wrapOnyxWithWaitForBatchedUpdates(Onyx); | ||
// Initialize the network key for OfflineWithFeedback | ||
return Onyx.merge(ONYXKEYS.NETWORK, {isOffline: false}); | ||
}); | ||
|
||
// Clear out Onyx after each test so that each test starts with a clean slate | ||
afterEach(() => { | ||
Onyx.clear(); | ||
}); | ||
|
||
describe('getSortedReportActions', () => { | ||
const cases = [ | ||
[ | ||
|
@@ -229,4 +254,66 @@ describe('ReportActionsUtils', () => { | |
expect(result).toStrictEqual(input); | ||
}); | ||
}); | ||
|
||
describe('getLastVisibleAction', () => { | ||
it('should return the last visible action for a report', () => { | ||
const report = { | ||
...LHNTestUtils.getFakeReport(['[email protected]', '[email protected]'], 3, true), | ||
reportID: 1, | ||
}; | ||
const action = { | ||
...LHNTestUtils.getFakeReportAction('[email protected]', 3, true), | ||
created: '2023-08-01 16:00:00', | ||
reportActionID: 'action1', | ||
actionName: 'ADDCOMMENT', | ||
originalMessage: { | ||
policyName: 'Vikings Policy', | ||
reason: 'policyDeleted', | ||
}, | ||
message: { | ||
policyName: 'Vikings Policy', | ||
reason: 'policyDeleted', | ||
}, | ||
}; | ||
const action2 = { | ||
...LHNTestUtils.getFakeReportAction('[email protected]', 3, true), | ||
created: '2023-08-01 18:00:00', | ||
reportActionID: 'action2', | ||
actionName: 'ADDCOMMENT', | ||
originalMessage: { | ||
policyName: 'Vikings Policy', | ||
reason: 'policyDeleted', | ||
}, | ||
message: { | ||
policyName: 'Vikings Policy', | ||
reason: 'policyDeleted', | ||
}, | ||
}; | ||
return ( | ||
waitForBatchedUpdates() | ||
// When Onyx is updated with the data and the sidebar re-renders | ||
.then(() => | ||
Onyx.multiSet({ | ||
[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`]: report, | ||
[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`]: {[action.reportActionID]: action, [action2.reportActionID]: action2}, | ||
}), | ||
) | ||
.then( | ||
() => | ||
new Promise((resolve) => { | ||
const connectionID = Onyx.connect({ | ||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, | ||
waitForCollectionCallback: true, | ||
callback: () => { | ||
Onyx.disconnect(connectionID); | ||
const res = ReportActionsUtils.getLastVisibleAction(report.reportID); | ||
expect(res).toBe(action2); | ||
resolve(); | ||
}, | ||
}); | ||
}), | ||
) | ||
); | ||
}); | ||
}); | ||
}); |