Skip to content

Commit 7f13cdd

Browse files
Merge pull request #24448 from Expensify/aldo_ignore-has-outstanding-iou-child-report
Ignore hasOutstandingIOU from child iouReport
2 parents 3204802 + 08d447c commit 7f13cdd

File tree

5 files changed

+78
-99
lines changed

5 files changed

+78
-99
lines changed

src/libs/OptionsListUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ function getOptions(
640640
const searchValue = parsedPhoneNumber.possible ? parsedPhoneNumber.number.e164 : searchInputValue.toLowerCase();
641641

642642
// Filter out all the reports that shouldn't be displayed
643-
const filteredReports = _.filter(reports, (report) => ReportUtils.shouldReportBeInOptionList(report, Navigation.getTopmostReportId(), false, null, betas, policies));
643+
const filteredReports = _.filter(reports, (report) => ReportUtils.shouldReportBeInOptionList(report, Navigation.getTopmostReportId(), false, betas, policies));
644644

645645
// Sorting the reports works like this:
646646
// - Order everything by the last message timestamp (descending)

src/libs/ReportUtils.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,12 +1136,10 @@ function getMoneyRequestAction(reportAction = {}) {
11361136
* Determines if a report has an IOU that is waiting for an action from the current user (either Pay or Add a credit bank account)
11371137
*
11381138
* @param {Object} report (chatReport or iouReport)
1139-
* @param {Object} allReportsDict
11401139
* @returns {boolean}
11411140
*/
1142-
function isWaitingForIOUActionFromCurrentUser(report, allReportsDict = null) {
1143-
const allAvailableReports = allReportsDict || allReports;
1144-
if (!report || !allAvailableReports) {
1141+
function isWaitingForIOUActionFromCurrentUser(report) {
1142+
if (!report) {
11451143
return false;
11461144
}
11471145

@@ -1150,15 +1148,8 @@ function isWaitingForIOUActionFromCurrentUser(report, allReportsDict = null) {
11501148
return true;
11511149
}
11521150

1153-
let reportToLook = report;
1154-
if (report.iouReportID) {
1155-
const iouReport = allAvailableReports[`${ONYXKEYS.COLLECTION.REPORT}${report.iouReportID}`];
1156-
if (iouReport) {
1157-
reportToLook = iouReport;
1158-
}
1159-
}
1160-
// Money request waiting for current user to Pay (from chat or from iou report)
1161-
if (reportToLook.ownerAccountID && (reportToLook.ownerAccountID !== currentUserAccountID || currentUserAccountID === reportToLook.managerID) && reportToLook.hasOutstandingIOU) {
1151+
// Money request waiting for current user to Pay (from expense or iou report)
1152+
if (report.hasOutstandingIOU && report.ownerAccountID && (report.ownerAccountID !== currentUserAccountID || currentUserAccountID === report.managerID)) {
11621153
return true;
11631154
}
11641155

@@ -2464,14 +2455,13 @@ function canAccessReport(report, policies, betas, allReportActions) {
24642455
* @param {Object} report
24652456
* @param {String} currentReportId
24662457
* @param {Boolean} isInGSDMode
2467-
* @param {Object} iouReports
24682458
* @param {String[]} betas
24692459
* @param {Object} policies
24702460
* @param {Object} allReportActions
24712461
* @param {Boolean} excludeEmptyChats
24722462
* @returns {boolean}
24732463
*/
2474-
function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouReports, betas, policies, allReportActions, excludeEmptyChats = false) {
2464+
function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, betas, policies, allReportActions, excludeEmptyChats = false) {
24752465
const isInDefaultMode = !isInGSDMode;
24762466

24772467
// Exclude reports that have no data because there wouldn't be anything to show in the option item.
@@ -2498,7 +2488,7 @@ function shouldReportBeInOptionList(report, currentReportId, isInGSDMode, iouRep
24982488
}
24992489

25002490
// Include reports that are relevant to the user in any view mode. Criteria include having a draft, having an outstanding IOU, or being assigned to an open task.
2501-
if (report.hasDraft || isWaitingForIOUActionFromCurrentUser(report, iouReports) || isWaitingForTaskCompleteFromAssignee(report)) {
2491+
if (report.hasDraft || isWaitingForIOUActionFromCurrentUser(report) || isWaitingForTaskCompleteFromAssignee(report)) {
25022492
return true;
25032493
}
25042494

src/libs/SidebarUtils.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p
8686
const isInDefaultMode = !isInGSDMode;
8787

8888
// Filter out all the reports that shouldn't be displayed
89-
const reportsToDisplay = _.filter(allReportsDict, (report) =>
90-
ReportUtils.shouldReportBeInOptionList(report, currentReportId, isInGSDMode, allReportsDict, betas, policies, allReportActions, true),
91-
);
89+
const reportsToDisplay = _.filter(allReportsDict, (report) => ReportUtils.shouldReportBeInOptionList(report, currentReportId, isInGSDMode, betas, policies, allReportActions, true));
9290

9391
if (_.isEmpty(reportsToDisplay)) {
9492
// Display Concierge chat report when there is no report to be displayed
@@ -131,7 +129,7 @@ function getOrderedReportIDs(currentReportId, allReportsDict, betas, policies, p
131129
return;
132130
}
133131

134-
if (ReportUtils.isWaitingForIOUActionFromCurrentUser(report, allReportsDict)) {
132+
if (ReportUtils.isWaitingForIOUActionFromCurrentUser(report)) {
135133
outstandingIOUReports.push(report);
136134
return;
137135
}

tests/unit/ReportUtilsTest.js

Lines changed: 19 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -288,97 +288,53 @@ describe('ReportUtils', () => {
288288
it('returns false when there is no report', () => {
289289
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser()).toBe(false);
290290
});
291-
it('returns false when there is no reports collection', () => {
291+
it('returns false when the matched IOU report does not have an owner accountID', () => {
292292
const report = {
293293
...LHNTestUtils.getFakeReport(),
294-
iouReportID: '1',
294+
ownerAccountID: undefined,
295+
hasOutstandingIOU: true,
295296
};
296297
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
297298
});
298-
it('returns false when the report has no iouReportID', () => {
299-
const report = LHNTestUtils.getFakeReport();
300-
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}2`, {
301-
reportID: '2',
302-
}).then(() => {
303-
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
304-
});
305-
});
306-
it('returns false when there is no matching IOU report', () => {
307-
const report = {
308-
...LHNTestUtils.getFakeReport(),
309-
iouReportID: '1',
310-
};
311-
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}2`, {
312-
reportID: '2',
313-
}).then(() => {
314-
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
315-
});
316-
});
317-
it('returns false when the matched IOU report does not have an owner email', () => {
318-
const report = {
319-
...LHNTestUtils.getFakeReport(),
320-
iouReportID: '1',
321-
};
322-
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, {
323-
reportID: '1',
324-
}).then(() => {
325-
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
326-
});
327-
});
328-
it('returns false when the matched IOU report does not have an owner email', () => {
299+
it('returns false when the linked iou report has an oustanding IOU', () => {
329300
const report = {
330301
...LHNTestUtils.getFakeReport(),
331302
iouReportID: '1',
332303
};
333304
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, {
334305
reportID: '1',
335306
ownerAccountID: 99,
307+
hasOutstandingIOU: true,
336308
}).then(() => {
337309
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
338310
});
339311
});
340-
it('returns true when the report has an oustanding IOU', () => {
312+
it('returns true when the report has no oustanding IOU but is waiting for a bank account and the logged user is the report owner', () => {
341313
const report = {
342314
...LHNTestUtils.getFakeReport(),
343-
iouReportID: '1',
344-
hasOutstandingIOU: true,
315+
hasOutstandingIOU: false,
316+
ownerAccountID: currentUserAccountID,
317+
isWaitingOnBankAccount: true,
345318
};
346-
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, {
347-
reportID: '1',
348-
ownerAccountID: 99,
349-
hasOutstandingIOU: true,
350-
}).then(() => {
351-
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(true);
352-
});
319+
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(true);
353320
});
354-
it('returns false when the report has no oustanding IOU', () => {
321+
it('returns true when the report has no oustanding IOU but is waiting for a bank account and the logged user is not the report owner', () => {
355322
const report = {
356323
...LHNTestUtils.getFakeReport(),
357-
iouReportID: '1',
358324
hasOutstandingIOU: false,
325+
ownerAccountID: 97,
326+
isWaitingOnBankAccount: true,
359327
};
360-
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, {
361-
reportID: '1',
362-
ownerAccountID: 99,
363-
hasOutstandingIOU: false,
364-
}).then(() => {
365-
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
366-
});
328+
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
367329
});
368-
it('returns true when the report has no oustanding IOU but is waiting for a bank account', () => {
330+
it('returns true when the report has oustanding IOU', () => {
369331
const report = {
370332
...LHNTestUtils.getFakeReport(),
371-
iouReportID: '1',
372-
hasOutstandingIOU: false,
333+
ownerAccountID: 99,
334+
hasOutstandingIOU: true,
335+
isWaitingOnBankAccount: false,
373336
};
374-
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}1`, {
375-
reportID: '1',
376-
ownerAccountID: currentUserEmail,
377-
hasOutstandingIOU: false,
378-
isWaitingOnBankAccount: true,
379-
}).then(() => {
380-
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(false);
381-
});
337+
expect(ReportUtils.isWaitingForIOUActionFromCurrentUser(report)).toBe(true);
382338
});
383339
});
384340

tests/unit/SidebarOrderTest.js

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ describe('Sidebar', () => {
385385
};
386386
const report3 = {
387387
...LHNTestUtils.getFakeReport([5, 6], 1),
388-
hasOutstandingIOU: true,
388+
hasOutstandingIOU: false,
389389

390390
// This has to be added after the IOU report is generated
391391
iouReportID: null,
@@ -427,13 +427,12 @@ describe('Sidebar', () => {
427427
.then(() => {
428428
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
429429
const displayNames = screen.queryAllByLabelText(hintText);
430-
expect(displayNames).toHaveLength(4);
430+
expect(displayNames).toHaveLength(3);
431431
expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(1);
432432
expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(1);
433433
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two');
434434
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Email Two owes $100.00');
435-
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Five, Six');
436-
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Three, Four');
435+
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four');
437436
})
438437
);
439438
});
@@ -700,21 +699,31 @@ describe('Sidebar', () => {
700699
// Given three IOU reports containing the same IOU amounts
701700
const report1 = {
702701
...LHNTestUtils.getFakeReport([1, 2]),
703-
hasOutstandingIOU: true,
704702

705703
// This has to be added after the IOU report is generated
706704
iouReportID: null,
707705
};
708706
const report2 = {
709707
...LHNTestUtils.getFakeReport([3, 4]),
710-
hasOutstandingIOU: true,
711708

712709
// This has to be added after the IOU report is generated
713710
iouReportID: null,
714711
};
715712
const report3 = {
716713
...LHNTestUtils.getFakeReport([5, 6]),
717-
hasOutstandingIOU: true,
714+
hasOutstandingIOU: false,
715+
716+
// This has to be added after the IOU report is generated
717+
iouReportID: null,
718+
};
719+
const report4 = {
720+
...LHNTestUtils.getFakeReport([5, 6]),
721+
722+
// This has to be added after the IOU report is generated
723+
iouReportID: null,
724+
};
725+
const report5 = {
726+
...LHNTestUtils.getFakeReport([5, 6]),
718727

719728
// This has to be added after the IOU report is generated
720729
iouReportID: null,
@@ -733,7 +742,7 @@ describe('Sidebar', () => {
733742
...LHNTestUtils.getFakeReport([9, 10]),
734743
type: CONST.REPORT.TYPE.IOU,
735744
ownerAccountID: 2,
736-
managerID: 2,
745+
managerID: 3,
737746
hasOutstandingIOU: true,
738747
total: 10000,
739748
currency: 'USD',
@@ -743,7 +752,27 @@ describe('Sidebar', () => {
743752
...LHNTestUtils.getFakeReport([11, 12]),
744753
type: CONST.REPORT.TYPE.IOU,
745754
ownerAccountID: 2,
746-
managerID: 2,
755+
managerID: 4,
756+
hasOutstandingIOU: true,
757+
total: 100000,
758+
currency: 'USD',
759+
chatReportID: report3.reportID,
760+
};
761+
const iouReport4 = {
762+
...LHNTestUtils.getFakeReport([11, 12]),
763+
type: CONST.REPORT.TYPE.IOU,
764+
ownerAccountID: 2,
765+
managerID: 5,
766+
hasOutstandingIOU: true,
767+
total: 10000,
768+
currency: 'USD',
769+
chatReportID: report3.reportID,
770+
};
771+
const iouReport5 = {
772+
...LHNTestUtils.getFakeReport([11, 12]),
773+
type: CONST.REPORT.TYPE.IOU,
774+
ownerAccountID: 2,
775+
managerID: 6,
747776
hasOutstandingIOU: true,
748777
total: 10000,
749778
currency: 'USD',
@@ -753,6 +782,8 @@ describe('Sidebar', () => {
753782
report1.iouReportID = iouReport1.reportID;
754783
report2.iouReportID = iouReport2.reportID;
755784
report3.iouReportID = iouReport3.reportID;
785+
report4.iouReportID = iouReport4.reportID;
786+
report5.iouReportID = iouReport5.reportID;
756787

757788
const currentlyLoggedInUserAccountID = 13;
758789
LHNTestUtils.getDefaultRenderedSidebarLinks('0');
@@ -768,22 +799,26 @@ describe('Sidebar', () => {
768799
[`${ONYXKEYS.COLLECTION.REPORT}${report1.reportID}`]: report1,
769800
[`${ONYXKEYS.COLLECTION.REPORT}${report2.reportID}`]: report2,
770801
[`${ONYXKEYS.COLLECTION.REPORT}${report3.reportID}`]: report3,
802+
[`${ONYXKEYS.COLLECTION.REPORT}${report4.reportID}`]: report4,
803+
[`${ONYXKEYS.COLLECTION.REPORT}${report5.reportID}`]: report5,
771804
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport1.reportID}`]: iouReport1,
772805
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport2.reportID}`]: iouReport2,
773806
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport3.reportID}`]: iouReport3,
807+
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport4.reportID}`]: iouReport4,
808+
[`${ONYXKEYS.COLLECTION.REPORT}${iouReport5.reportID}`]: iouReport5,
774809
}),
775810
)
776811

777-
// Then the reports are ordered alphabetically since their amounts are the same
812+
// Then the reports with the same amount are ordered alphabetically
778813
.then(() => {
779814
const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames');
780815
const displayNames = screen.queryAllByLabelText(hintText);
781816
expect(displayNames).toHaveLength(5);
782-
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Email Two owes $100.00');
783-
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Email Two owes $100.00');
784-
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Email Two owes $100.00');
785-
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Five, Six');
786-
expect(lodashGet(displayNames, [4, 'props', 'children'])).toBe('One, Two');
817+
expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Email Four owes $1,000.00');
818+
expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Email Five owes $100.00');
819+
expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Email Six owes $100.00');
820+
expect(lodashGet(displayNames, [3, 'props', 'children'])).toBe('Email Three owes $100.00');
821+
expect(lodashGet(displayNames, [4, 'props', 'children'])).toBe('Email Two owes $100.00');
787822
})
788823
);
789824
});

0 commit comments

Comments
 (0)