Skip to content

Commit

Permalink
Merge pull request #23625 from bernhardoj/fix/20780-wrong-last-read-r…
Browse files Browse the repository at this point in the history
…eport

Fix wrong last accessed report
  • Loading branch information
Julesssss authored Jul 31, 2023
2 parents 024d210 + 93fd82d commit 8cdb506
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function isMoneyRequestReport(reportOrID) {
function sortReportsByLastRead(reports) {
return _.chain(reports)
.toArray()
.filter((report) => report && report.reportID && !isIOUReport(report))
.filter((report) => report && report.reportID && report.lastReadTime)
.sortBy('lastReadTime')
.value();
}
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/ReportUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,24 @@ describe('ReportUtils', () => {
expect(ReportUtils.getReportIDFromLink('new-expensify://settings')).toBe('');
});
});

describe('sortReportsByLastRead', () => {
it('should filter out report without reportID & lastReadTime and sort lastReadTime in ascending order', () => {
const reports = {
1: {reportID: 1, lastReadTime: '2023-07-08 07:15:44.030'},
2: {reportID: 2, lastReadTime: null},
3: {reportID: 3, lastReadTime: '2023-07-06 07:15:44.030'},
4: {reportID: 4, lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU},
5: {lastReadTime: '2023-07-09 07:15:44.030'},
6: {reportID: 6},
7: {},
};
const sortedReports = [
{reportID: 3, lastReadTime: '2023-07-06 07:15:44.030'},
{reportID: 4, lastReadTime: '2023-07-07 07:15:44.030', type: CONST.REPORT.TYPE.IOU},
{reportID: 1, lastReadTime: '2023-07-08 07:15:44.030'},
];
expect(ReportUtils.sortReportsByLastRead(reports)).toEqual(sortedReports);
});
});
});

0 comments on commit 8cdb506

Please sign in to comment.