Skip to content

Commit

Permalink
fix: remove filterReportActionsForDisplay function and update UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Feb 22, 2023
1 parent 24b0083 commit c351930
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 deletions.
43 changes: 16 additions & 27 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 30 additions & 5 deletions tests/unit/ReportActionsUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,80 +114,105 @@ 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);
});

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);
});
Expand Down

0 comments on commit c351930

Please sign in to comment.