From c35193096346ffcfe8bb073c216d314de4419e08 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 22 Feb 2023 22:55:16 +0700 Subject: [PATCH] fix: remove filterReportActionsForDisplay function and update UTs --- src/libs/ReportActionsUtils.js | 43 +++++++++++----------------- tests/unit/ReportActionsUtilsTest.js | 35 ++++++++++++++++++---- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 32fb3562fda6..31ad10981cec 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -74,31 +74,6 @@ function getSortedReportActions(reportActions, shouldSortInDescendingOrder = fal .value(); } -/** - * Filter out any reportActions which should not be displayed. - * - * @param {Array} reportActions - * @returns {Array} - */ -function filterReportActionsForDisplay(reportActions) { - return _.filter(reportActions, (reportAction) => { - // Filter out any unsupported reportAction types - if (!_.has(CONST.REPORT.ACTIONS.TYPE, reportAction.actionName)) { - return false; - } - - // Ignore closed action here since we're already displaying a footer that explains why the report was closed - if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { - return false; - } - - // All other actions are displayed except deleted, non-pending actions - const isDeleted = isDeletedAction(reportAction); - const isPending = !_.isEmpty(reportAction.pendingAction); - return !isDeleted || isPending; - }); -} - /** * Finds most recent IOU report action number. * @@ -206,12 +181,26 @@ function getSortedReportActionsForDisplay(reportActions) { }); const sortedReportActions = getSortedReportActions(filteredReportActions, true); - return filterReportActionsForDisplay(sortedReportActions); + return _.filter(sortedReportActions, (reportAction) => { + // Filter out any unsupported reportAction types + if (!_.has(CONST.REPORT.ACTIONS.TYPE, reportAction.actionName)) { + return false; + } + + // Ignore closed action here since we're already displaying a footer that explains why the report was closed + if (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED) { + return false; + } + + // All other actions are displayed except deleted, non-pending actions + const isDeleted = isDeletedAction(reportAction); + const isPending = !_.isEmpty(reportAction.pendingAction); + return !isDeleted || isPending; + }); } export { getSortedReportActions, - filterReportActionsForDisplay, getLastVisibleAction, getLastVisibleMessageText, getMostRecentIOUReportActionID, diff --git a/tests/unit/ReportActionsUtilsTest.js b/tests/unit/ReportActionsUtilsTest.js index 8431555a8985..20bf389969b7 100644 --- a/tests/unit/ReportActionsUtilsTest.js +++ b/tests/unit/ReportActionsUtilsTest.js @@ -114,59 +114,78 @@ describe('ReportActionsUtils', () => { }); }); - describe('filterReportActionsForDisplay', () => { + describe('getSortedReportActionsForDisplay', () => { it('should filter out non-whitelisted actions', () => { const input = [ { + created: '2022-11-13 22:27:01.825', + reportActionID: '8401445780099176', actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, message: [{html: 'Hello world'}], }, { + created: '2022-11-12 22:27:01.825', + reportActionID: '6401435781022176', actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, message: [{html: 'Hello world'}], }, { + created: '2022-11-11 22:27:01.825', + reportActionID: '2962390724708756', actionName: CONST.REPORT.ACTIONS.TYPE.IOU, message: [{html: 'Hello world'}], }, { + created: '2022-11-10 22:27:01.825', + reportActionID: '1609646094152486', actionName: CONST.REPORT.ACTIONS.TYPE.RENAMED, message: [{html: 'Hello world'}], }, { + created: '2022-11-09 22:27:01.825', + reportActionID: '1661970171066218', actionName: 'REIMBURSED', message: [{html: 'Hello world'}], }, ]; - const result = ReportActionsUtils.filterReportActionsForDisplay(input); + const result = ReportActionsUtils.getSortedReportActionsForDisplay(input); input.pop(); expect(result).toStrictEqual(input); }); - it('should filter out closed actions', () => { const input = [ { + created: '2022-11-13 22:27:01.825', + reportActionID: '8401445780099176', actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, message: [{html: 'Hello world'}], }, { + created: '2022-11-12 22:27:01.825', + reportActionID: '6401435781022176', actionName: CONST.REPORT.ACTIONS.TYPE.CREATED, message: [{html: 'Hello world'}], }, { + created: '2022-11-11 22:27:01.825', + reportActionID: '2962390724708756', actionName: CONST.REPORT.ACTIONS.TYPE.IOU, message: [{html: 'Hello world'}], }, { + created: '2022-11-10 22:27:01.825', + reportActionID: '1609646094152486', actionName: CONST.REPORT.ACTIONS.TYPE.RENAMED, message: [{html: 'Hello world'}], }, { + created: '2022-11-09 22:27:01.825', + reportActionID: '1661970171066218', actionName: CONST.REPORT.ACTIONS.TYPE.CLOSED, message: [{html: 'Hello world'}], }, ]; - const result = ReportActionsUtils.filterReportActionsForDisplay(input); + const result = ReportActionsUtils.getSortedReportActionsForDisplay(input); input.pop(); expect(result).toStrictEqual(input); }); @@ -174,20 +193,26 @@ describe('ReportActionsUtils', () => { it('should filter out deleted, non-pending comments', () => { const input = [ { + created: '2022-11-13 22:27:01.825', + reportActionID: '8401445780099176', actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, message: [{html: 'Hello world'}], }, { + created: '2022-11-12 22:27:01.825', + reportActionID: '8401445780099175', actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, message: [{html: ''}], pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, }, { + created: '2022-11-11 22:27:01.825', + reportActionID: '8401445780099174', actionName: CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT, message: [{html: ''}], }, ]; - const result = ReportActionsUtils.filterReportActionsForDisplay(input); + const result = ReportActionsUtils.getSortedReportActionsForDisplay(input); input.pop(); expect(result).toStrictEqual(input); });