Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2590,8 +2590,8 @@ function getTaskSections(
const report = getReportOrDraftReport(taskItem.reportID) ?? taskItem;
const parentReport = getReportOrDraftReport(taskItem.parentReportID) ?? data[`${ONYXKEYS.COLLECTION.REPORT}${taskItem.parentReportID}`];

const reportName = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.reportName));
const description = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.description));
const reportName = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.reportName ?? ''));
const description = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.description ?? ''));

const result: TaskListItemType = {
...taskItem,
Expand Down
51 changes: 51 additions & 0 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,57 @@ describe('SearchUIUtils', () => {
expect(allReportActionsLength).toBe(6);
});

it('should not crash when a task has no description or reportName (type TASK)', () => {
const taskReportID = '987654321';
const taskReport = createMock<SearchTask>({
type: CONST.REPORT.TYPE.TASK,
accountID: adminAccountID,
managerID: adminAccountID,
created: '2024-01-01 00:00:00',
parentReportID: '123456789',
reportID: taskReportID,
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS_NUM.OPEN,
// description and reportName intentionally omitted: a task created without a description
// has `description === undefined`, which used to crash htmlToText.
});
const taskData = createMock<OnyxTypes.SearchResults['data']>({
personalDetailsList: {
[adminAccountID]: {
accountID: adminAccountID,
avatar: '',
displayName: 'Task Admin',
login: adminEmail,
},
},
[`report_${taskReportID}`]: taskReport,
});

const getTaskSectionsResult = () =>
getSectionsByType(
SearchUIUtils.getSections({
type: CONST.SEARCH.DATA_TYPES.TASK,
data: taskData,
currentAccountID: adminAccountID,
currentUserEmail: adminEmail,
translate: translateLocal,
formatPhoneNumber,
bankAccountList: {},
conciergeReportID: undefined,
convertToDisplayString,
reportAttributesDerivedValue: {},
}),
SearchUIUtils.isTaskListItemType,
)[0];

expect(getTaskSectionsResult).not.toThrow();

const [task] = getTaskSectionsResult();
expect(task.reportID).toBe(taskReportID);
expect(task.description).toBe('');
expect(task.reportName).toBe('');
});

it('should return getTransactionsSections result when groupBy is undefined', () => {
expect(
SearchUIUtils.getSections({
Expand Down
Loading