Skip to content

Commit 99017bb

Browse files
authored
Merge pull request #4648 from mananjadhav/fix/split-money-with-automated-acc
Hide automated accounts from Recent sections of Split Money/Request Money
2 parents bd863d6 + d28b65f commit 99017bb

File tree

6 files changed

+191
-12
lines changed

6 files changed

+191
-12
lines changed

src/CONST.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libs/OptionsListUtils.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
293293
selectedOptions = [],
294294
maxRecentReportsToShow = 0,
295295
excludeConcierge = false,
296+
excludeChronos = false,
297+
excludeReceipts = false,
296298
excludeDefaultRooms = false,
297299
includeMultipleParticipantReports = false,
298300
includePersonalDetails = false,
@@ -384,6 +386,14 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
384386
loginOptionsToExclude.push({login: CONST.EMAIL.CONCIERGE});
385387
}
386388

389+
if (excludeChronos) {
390+
loginOptionsToExclude.push({login: CONST.EMAIL.CHRONOS});
391+
}
392+
393+
if (excludeReceipts) {
394+
loginOptionsToExclude.push({login: CONST.EMAIL.RECEIPTS});
395+
}
396+
387397
if (includeRecentReports) {
388398
for (let i = 0; i < allReportOptions.length; i++) {
389399
// Stop adding options to the recentReports array when we reach the maxRecentReportsToShow value
@@ -468,6 +478,7 @@ function getOptions(reports, personalDetails, draftComments, activeReportID, {
468478
&& personalDetailsOptions.length === 0
469479
&& _.every(selectedOptions, option => option.login !== searchValue)
470480
&& ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue))
481+
&& (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue))
471482
&& (searchValue !== CONST.EMAIL.CHRONOS || Permissions.canUseChronos(betas))
472483
) {
473484
// If the phone number doesn't have an international code then let's prefix it with the
@@ -527,15 +538,22 @@ function getSearchOptions(
527538
* @param {Object} reports
528539
* @param {Object} personalDetails
529540
* @param {String} searchValue
530-
* @param {Boolean} excludeConcierge
541+
* @param {Object} excludedOptions
542+
* @param {Boolean} excludedOptions.excludeConcierge
543+
* @param {Boolean} excludedOptions.excludeChronos
544+
* @param {Boolean} excludedOptions.excludeReceipts
531545
* @param {Array<String>} betas
532546
* @returns {Object}
533547
*/
534548
function getNewChatOptions(
535549
reports,
536550
personalDetails,
537551
searchValue = '',
538-
excludeConcierge,
552+
{
553+
excludeConcierge = false,
554+
excludeChronos = false,
555+
excludeReceipts = true,
556+
} = {},
539557
betas,
540558
) {
541559
return getOptions(reports, personalDetails, {}, 0, {
@@ -546,6 +564,8 @@ function getNewChatOptions(
546564
includeRecentReports: true,
547565
maxRecentReportsToShow: 5,
548566
excludeConcierge,
567+
excludeChronos,
568+
excludeReceipts,
549569
});
550570
}
551571

@@ -588,7 +608,10 @@ function getIOUConfirmationOptionsFromParticipants(
588608
* @param {Object} personalDetails
589609
* @param {String} searchValue
590610
* @param {Array} selectedOptions
591-
* @param {Boolean} excludeConcierge
611+
* @param {Object} excludedOptions
612+
* @param {Boolean} excludedOptions.excludeConcierge
613+
* @param {Boolean} excludedOptions.excludeChronos
614+
* @param {Boolean} excludedOptions.excludeReceipts
592615
* @param {Array<String>} betas
593616
* @returns {Object}
594617
*/
@@ -597,7 +620,11 @@ function getNewGroupOptions(
597620
personalDetails,
598621
searchValue = '',
599622
selectedOptions = [],
600-
excludeConcierge,
623+
{
624+
excludeConcierge = false,
625+
excludeChronos = false,
626+
excludeReceipts = true,
627+
} = {},
601628
betas,
602629
) {
603630
return getOptions(reports, personalDetails, {}, 0, {
@@ -610,6 +637,8 @@ function getNewGroupOptions(
610637
includeMultipleParticipantReports: false,
611638
maxRecentReportsToShow: 5,
612639
excludeConcierge,
640+
excludeChronos,
641+
excludeReceipts,
613642
});
614643
}
615644

src/pages/NewChatPage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ class NewChatPage extends Component {
6565
props.reports,
6666
props.personalDetails,
6767
'',
68-
false,
68+
{
69+
excludeConcierge: false,
70+
excludeChronos: false,
71+
excludeReceipts: true,
72+
},
6973
props.betas,
7074
);
7175

src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class IOUParticipantsRequest extends Component {
5656
props.reports,
5757
props.personalDetails,
5858
'',
59-
true,
59+
{
60+
excludeConcierge: true,
61+
excludeChronos: true,
62+
excludeReceipts: true,
63+
},
6064
props.betas,
6165
);
6266

@@ -128,7 +132,11 @@ class IOUParticipantsRequest extends Component {
128132
this.props.reports,
129133
this.props.personalDetails,
130134
searchValue,
131-
true,
135+
{
136+
excludeConcierge: true,
137+
excludeChronos: true,
138+
excludeReceipts: true,
139+
},
132140
this.props.betas,
133141
);
134142
this.setState({

src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ class IOUParticipantsSplit extends Component {
8282
props.personalDetails,
8383
'',
8484
props.participants,
85-
true,
85+
{
86+
excludeConcierge: true,
87+
excludeChronos: true,
88+
excludeReceipts: true,
89+
},
8690
props.betas,
8791
);
8892

@@ -183,7 +187,11 @@ class IOUParticipantsSplit extends Component {
183187
this.props.personalDetails,
184188
isOptionInList ? prevState.searchValue : '',
185189
newSelectedOptions,
186-
true,
190+
{
191+
excludeConcierge: true,
192+
excludeChronos: true,
193+
excludeReceipts: true,
194+
},
187195
this.props.betas,
188196
);
189197
return {
@@ -220,7 +228,11 @@ class IOUParticipantsSplit extends Component {
220228
this.props.personalDetails,
221229
searchValue,
222230
[],
223-
true,
231+
{
232+
excludeConcierge: true,
233+
excludeChronos: true,
234+
excludeReceipts: true,
235+
},
224236
this.props.betas,
225237
);
226238
this.setState({

tests/unit/OptionsListUtilsTest.js

Lines changed: 127 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,32 @@ describe('OptionsListUtils', () => {
162162
},
163163
};
164164

165+
const REPORTS_WITH_CHRONOS = {
166+
...REPORTS,
167+
11: {
168+
lastVisitedTimestamp: 1610666739302,
169+
lastMessageTimestamp: 1,
170+
isPinned: false,
171+
reportID: 10,
172+
participants: ['[email protected]'],
173+
reportName: 'Chronos',
174+
unreadActionCount: 1,
175+
},
176+
};
177+
178+
const REPORTS_WITH_RECEIPTS = {
179+
...REPORTS,
180+
12: {
181+
lastVisitedTimestamp: 1610666739302,
182+
lastMessageTimestamp: 1,
183+
isPinned: false,
184+
reportID: 10,
185+
participants: ['[email protected]'],
186+
reportName: 'Receipts',
187+
unreadActionCount: 1,
188+
},
189+
};
190+
165191
const PERSONAL_DETAILS_WITH_CONCIERGE = {
166192
...PERSONAL_DETAILS,
167193

@@ -171,6 +197,24 @@ describe('OptionsListUtils', () => {
171197
},
172198
};
173199

200+
const PERSONAL_DETAILS_WITH_CHRONOS = {
201+
...PERSONAL_DETAILS,
202+
203+
204+
displayName: 'Chronos',
205+
206+
},
207+
};
208+
209+
const PERSONAL_DETAILS_WITH_RECEIPTS = {
210+
...PERSONAL_DETAILS,
211+
212+
213+
displayName: 'Receipts',
214+
215+
},
216+
};
217+
174218
// Set the currently logged in user, report data, and personal details
175219
beforeAll(() => {
176220
Onyx.init({
@@ -273,7 +317,9 @@ describe('OptionsListUtils', () => {
273317
);
274318

275319
// Test by excluding Concierge from the results
276-
results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, '', true);
320+
results = OptionsListUtils.getNewChatOptions(
321+
REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, '', {excludeConcierge: true},
322+
);
277323

278324
// All the personalDetails should be returned minus the currently logged in user and Concierge
279325
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS);
@@ -282,6 +328,32 @@ describe('OptionsListUtils', () => {
282328
expect.objectContaining({login: '[email protected]'}),
283329
]),
284330
);
331+
332+
// Test by excluding Chronos from the results
333+
results = OptionsListUtils.getNewChatOptions(
334+
REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, '', {excludeChronos: true},
335+
);
336+
337+
// All the personalDetails should be returned minus the currently logged in user and Concierge
338+
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS);
339+
expect(results.personalDetails).not.toEqual(
340+
expect.arrayContaining([
341+
expect.objectContaining({login: '[email protected]'}),
342+
]),
343+
);
344+
345+
// Test by excluding Receipts from the results
346+
results = OptionsListUtils.getNewChatOptions(
347+
REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, '', {excludeReceipts: true},
348+
);
349+
350+
// All the personalDetails should be returned minus the currently logged in user and Concierge
351+
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS);
352+
expect(results.personalDetails).not.toEqual(
353+
expect.arrayContaining([
354+
expect.objectContaining({login: '[email protected]'}),
355+
]),
356+
);
285357
});
286358

287359
it('getNewGroupOptions()', () => {
@@ -402,7 +474,9 @@ describe('OptionsListUtils', () => {
402474
PERSONAL_DETAILS_WITH_CONCIERGE,
403475
'',
404476
[],
405-
true,
477+
{
478+
excludeConcierge: true,
479+
},
406480
);
407481

408482
// We should expect all the personalDetails to show (minus the 5 that are already showing,
@@ -418,6 +492,57 @@ describe('OptionsListUtils', () => {
418492
expect.objectContaining({login: '[email protected]'}),
419493
]),
420494
);
495+
496+
497+
// Test by excluding Chronos from the results
498+
results = OptionsListUtils.getNewGroupOptions(
499+
REPORTS_WITH_CHRONOS,
500+
PERSONAL_DETAILS_WITH_CHRONOS,
501+
'',
502+
[],
503+
{
504+
excludeChronos: true,
505+
},
506+
);
507+
508+
// We should expect all the personalDetails to show (minus the 5 that are already showing,
509+
// the currently logged in user and Concierge)
510+
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7);
511+
expect(results.personalDetails).not.toEqual(
512+
expect.arrayContaining([
513+
expect.objectContaining({login: '[email protected]'}),
514+
]),
515+
);
516+
expect(results.recentReports).not.toEqual(
517+
expect.arrayContaining([
518+
expect.objectContaining({login: '[email protected]'}),
519+
]),
520+
);
521+
522+
// Test by excluding Receipts from the results
523+
results = OptionsListUtils.getNewGroupOptions(
524+
REPORTS_WITH_RECEIPTS,
525+
PERSONAL_DETAILS_WITH_RECEIPTS,
526+
'',
527+
[],
528+
{
529+
excludeReceipts: true,
530+
},
531+
);
532+
533+
// We should expect all the personalDetails to show (minus the 5 that are already showing,
534+
// the currently logged in user and Concierge)
535+
expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7);
536+
expect(results.personalDetails).not.toEqual(
537+
expect.arrayContaining([
538+
expect.objectContaining({login: '[email protected]'}),
539+
]),
540+
);
541+
expect(results.recentReports).not.toEqual(
542+
expect.arrayContaining([
543+
expect.objectContaining({login: '[email protected]'}),
544+
]),
545+
);
421546
});
422547

423548
it('getSidebarOptions() with default priority mode', () => {

0 commit comments

Comments
 (0)