From 569ac5d44c7adefbb79836a2841b4cd8c2764a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Fri, 8 Apr 2022 00:07:43 +0300 Subject: [PATCH 01/11] getNewChatOptions function calls changed. Sort by LastMessageTimestamp now. --- src/libs/OptionsListUtils.js | 7 +- src/pages/NewChatPage.js | 3 + .../IOUParticipantsRequest.js | 2 + .../IOUParticipantsSplit.js | 3 + tests/unit/OptionsListUtilsTest.js | 366 +++++++++++++++++- 5 files changed, 369 insertions(+), 12 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 8c600a2cb4eb..3948ef5751d6 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -637,6 +637,7 @@ function getOptions(reports, personalDetails, activeReportID, { * @param {Object} personalDetails * @param {String} searchValue * @param {Array} betas + * @param {Boolean} sortByLastMessageTimestamp * @returns {Object} */ function getSearchOptions( @@ -644,6 +645,7 @@ function getSearchOptions( personalDetails, searchValue = '', betas, + sortByLastMessageTimestamp, ) { return getOptions(reports, personalDetails, 0, { betas, @@ -657,7 +659,7 @@ function getSearchOptions( showChatPreviewLine: true, showReportsWithNoComments: true, includePersonalDetails: true, - sortByLastMessageTimestamp: false, + sortByLastMessageTimestamp, forcePolicyNamePreview: true, prioritizeIOUDebts: false, }); @@ -704,6 +706,7 @@ function getIOUConfirmationOptionsFromParticipants( * @param {String} searchValue * @param {Array} selectedOptions * @param {Array} excludeLogins + * @param {Boolean} sortByLastMessageTimestamp * @returns {Object} */ function getNewChatOptions( @@ -713,6 +716,7 @@ function getNewChatOptions( searchValue = '', selectedOptions = [], excludeLogins = [], + sortByLastMessageTimestamp, ) { return getOptions(reports, personalDetails, 0, { betas, @@ -723,6 +727,7 @@ function getNewChatOptions( includePersonalDetails: true, maxRecentReportsToShow: 5, excludeLogins, + sortByLastMessageTimestamp, }); } diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index 00f2209d3d3e..e65efee54484 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -77,6 +77,7 @@ class NewChatPage extends Component { '', [], this.props.isGroupChat ? this.excludedGroupEmails : [], + true, ); this.state = { searchValue: '', @@ -184,6 +185,7 @@ class NewChatPage extends Component { prevState.searchValue, [], this.excludedGroupEmails, + true, ); return { @@ -256,6 +258,7 @@ class NewChatPage extends Component { searchValue, [], this.props.isGroupChat ? this.excludedGroupEmails : [], + true, ); this.setState({ searchValue, diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js index 247a873c12d3..76d5a52418ff 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js @@ -49,6 +49,7 @@ class IOUParticipantsRequest extends Component { '', [], CONST.EXPENSIFY_EMAILS, + true, ); this.state = { @@ -127,6 +128,7 @@ class IOUParticipantsRequest extends Component { searchValue, [], CONST.EXPENSIFY_EMAILS, + true, ); this.setState({ searchValue, diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js index 46c048e819a6..032cdc61c5fb 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js @@ -74,6 +74,7 @@ class IOUParticipantsSplit extends Component { '', props.participants, CONST.EXPENSIFY_EMAILS, + true, ); this.state = { @@ -175,6 +176,7 @@ class IOUParticipantsSplit extends Component { isOptionInList ? prevState.searchValue : '', newSelectedOptions, CONST.EXPENSIFY_EMAILS, + true, ); return { recentReports, @@ -217,6 +219,7 @@ class IOUParticipantsSplit extends Component { searchValue, [], CONST.EXPENSIFY_EMAILS, + true, ); this.setState({ searchValue, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index dd4013416391..57646aad0cc3 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -11,7 +11,7 @@ describe('OptionsListUtils', () => { const REPORTS = { 1: { lastVisitedTimestamp: 1610666739295, - lastMessageTimestamp: 1, + lastMessageTimestamp: 15, isPinned: false, reportID: 1, participants: ['tonystark@expensify.com', 'reedrichards@expensify.com'], @@ -20,7 +20,7 @@ describe('OptionsListUtils', () => { }, 2: { lastVisitedTimestamp: 1610666739296, - lastMessageTimestamp: 1, + lastMessageTimestamp: 16, isPinned: false, reportID: 2, participants: ['peterparker@expensify.com'], @@ -31,7 +31,7 @@ describe('OptionsListUtils', () => { // This is the only report we are pinning in this test 3: { lastVisitedTimestamp: 1610666739297, - lastMessageTimestamp: 1, + lastMessageTimestamp: 17, isPinned: true, reportID: 3, participants: ['reedrichards@expensify.com'], @@ -40,7 +40,7 @@ describe('OptionsListUtils', () => { }, 4: { lastVisitedTimestamp: 1610666739298, - lastMessageTimestamp: 1, + lastMessageTimestamp: 18, isPinned: false, reportID: 4, participants: ['tchalla@expensify.com'], @@ -49,7 +49,7 @@ describe('OptionsListUtils', () => { }, 5: { lastVisitedTimestamp: 1610666739299, - lastMessageTimestamp: 1, + lastMessageTimestamp: 19, isPinned: false, reportID: 5, participants: ['suestorm@expensify.com'], @@ -58,7 +58,7 @@ describe('OptionsListUtils', () => { }, 6: { lastVisitedTimestamp: 1610666739300, - lastMessageTimestamp: 1, + lastMessageTimestamp: 20, isPinned: false, reportID: 6, participants: ['thor@expensify.com'], @@ -154,7 +154,7 @@ describe('OptionsListUtils', () => { 10: { lastVisitedTimestamp: 1610666739302, - lastMessageTimestamp: 1, + lastMessageTimestamp: 22, isPinned: false, reportID: 10, participants: ['concierge@expensify.com'], @@ -167,7 +167,7 @@ describe('OptionsListUtils', () => { ...REPORTS, 11: { lastVisitedTimestamp: 1610666739302, - lastMessageTimestamp: 1, + lastMessageTimestamp: 22, isPinned: false, reportID: 10, participants: ['chronos@expensify.com'], @@ -180,7 +180,7 @@ describe('OptionsListUtils', () => { ...REPORTS, 12: { lastVisitedTimestamp: 1610666739302, - lastMessageTimestamp: 1, + lastMessageTimestamp: 22, isPinned: false, reportID: 10, participants: ['receipts@expensify.com'], @@ -193,7 +193,7 @@ describe('OptionsListUtils', () => { ...REPORTS, 13: { lastVisitedTimestamp: 1610666739302, - lastMessageTimestamp: 1, + lastMessageTimestamp: 22, isPinned: true, reportID: 13, participants: ['d_email@email.com'], @@ -202,7 +202,7 @@ describe('OptionsListUtils', () => { }, 14: { lastVisitedTimestamp: 1610666732302, - lastMessageTimestamp: 1, + lastMessageTimestamp: 22, isPinned: true, reportID: 14, participants: ['z_email@email.com'], @@ -279,6 +279,38 @@ describe('OptionsListUtils', () => { expect(results.recentReports[0].text).toBe('Mister Fantastic'); }); + it('getSearchOptions() with message timeStamp order', () => { + // When we filter in the Search view without providing a searchValue + let results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '', [], true); + + // Then the 2 personalDetails that don't have reports should be returned + expect(results.personalDetails.length).toBe(2); + + // Then all of the reports should be shown, including the one that has no message on them. + expect(results.recentReports.length).toBe(_.size(REPORTS)); + + // When we filter again but provide a searchValue + results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'spider', [], true); + + // Then only one option should be returned and it's the one matching the search value + expect(results.recentReports.length).toBe(1); + expect(results.recentReports[0].login).toBe('peterparker@expensify.com'); + + // When we filter again but provide a searchValue that should match multiple times + results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '.com', [], true); + + // Then we get both values with the pinned value still on top + expect(results.recentReports.length).toBe(11); + expect(results.recentReports[0].text).toBe('Captain America'); + + // When we filter again but provide a searchValue that should match multiple times + results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '.com', [], false); + + // Then we get both values with the pinned value still on top + expect(results.recentReports.length).toBe(11); + expect(results.recentReports[0].text).toBe('Mister Sinister'); + }); + it('getNewChatOptions()', () => { // maxRecentReportsToShow in src/libs/OptionsListUtils.js const MAX_RECENT_REPORTS = 5; @@ -378,6 +410,117 @@ describe('OptionsListUtils', () => { ); }); + it('getNewChatOptions() using message timeStamp order', () => { + // maxRecentReportsToShow in src/libs/OptionsListUtils.js + const MAX_RECENT_REPORTS = 5; + + // When we call getNewChatOptions() with no search value + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true); + + // We should expect maximimum of 5 recent reports to be returned + expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS); + + // We should expect all personalDetails to be returned, + // minus the currently logged in user and recent reports count + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 1 - MAX_RECENT_REPORTS); + + // Then the result which has an existing report should also have the reportID attached + const personalDetailWithExistingReport = _.find( + results.personalDetails, + personalDetail => personalDetail.login === 'peterparker@expensify.com', + ); + expect(personalDetailWithExistingReport.reportID).toBe(2); + + // When we provide a search value that does not match any personal details + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], [], true); + + // Then no options will be returned + expect(results.personalDetails.length).toBe(0); + + // When we provide a search value that matches an email + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], [], true); + + // Then one recentReports will be returned and it will be the correct option + // personalDetails should be empty array + expect(results.recentReports.length).toBe(1); + expect(results.recentReports[0].text).toBe('Spider-Man'); + expect(results.personalDetails.length).toBe(0); + + // When we provide a search value that matches a partial display name or email + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], true); + + // Then several options will be returned and they will be each have the search string in their email or name + // even though the currently logged in user matches they should not show. + expect(results.personalDetails.length).toBe(4); + expect(results.recentReports.length).toBe(5); + expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + expect(results.recentReports[0].text).toBe('Captain America'); + expect(results.recentReports[1].text).toBe('Mister Sinister'); + expect(results.recentReports[2].text).toBe('Thor'); + + // When we provide a search value that matches a partial display name or email + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); + + // Then several options will be returned and they will be each have the search string in their email or name + // even though the currently logged in user matches they should not show. + expect(results.personalDetails.length).toBe(4); + expect(results.recentReports.length).toBe(5); + expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + expect(results.recentReports[0].text).toBe('Mister Sinister'); + expect(results.recentReports[1].text).toBe('Captain America'); + + // Test for Concierge's existence in chat options + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [], true); + + // Concierge is included in the results by default. We should expect all the personalDetails to show + // (minus the 5 that are already showing and the currently logged in user) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 1 - MAX_RECENT_REPORTS); + expect(results.recentReports).toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + + // Test by excluding Concierge from the results + results = OptionsListUtils.getNewChatOptions( + REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], true, + ); + + // All the personalDetails should be returned minus the currently logged in user and Concierge + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + + // Test by excluding Chronos from the results + results = OptionsListUtils.getNewChatOptions( + REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], true, + ); + + // All the personalDetails should be returned minus the currently logged in user and Concierge + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'chronos@expensify.com'}), + ]), + ); + + // Test by excluding Receipts from the results + results = OptionsListUtils.getNewChatOptions( + REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], true, + ); + + // All the personalDetails should be returned minus the currently logged in user and Concierge + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'receipts@expensify.com'}), + ]), + ); + }); + it('getNewChatOptions() for group Chat', () => { // When we call getNewChatOptions() with no search value let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], ''); @@ -564,6 +707,207 @@ describe('OptionsListUtils', () => { ); }); + it('getNewChatOptions() for group Chat using message timeStamp order', () => { + // When we call getNewChatOptions() with no search value + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true); + + // Then we should expect only a maxmimum of 5 recent reports to be returned + expect(results.recentReports.length).toBe(5); + + // And we should expect all the personalDetails to show (minus the 5 that are already + // showing and the currently logged in user) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 6); + + // And none of our personalDetails should include any of the users with recent reports + const reportLogins = _.map(results.recentReports, reportOption => reportOption.login); + const personalDetailsOverlapWithReports = _.every(results.personalDetails, ( + personalDetailOption => _.contains(reportLogins, personalDetailOption.login) + )); + expect(personalDetailsOverlapWithReports).toBe(false); + + // When we search for an option that is only in a personalDetail with no existing report + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk', [], [], true); + + // Then reports should return no results + expect(results.recentReports.length).toBe(0); + + // And personalDetails should show just one option and it will be the one we expect + expect(results.personalDetails.length).toBe(1); + expect(results.personalDetails[0].login).toBe('brucebanner@expensify.com'); + + // When we search for an option that matches things in both personalDetails and reports + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], true); + + // Then all single participant reports that match will show up in the recentReports array + expect(results.recentReports.length).toBe(5); + expect(results.recentReports[0].text).toBe('Captain America'); + + // And logins with no single participant reports will show up in personalDetails + expect(results.personalDetails.length).toBe(4); + expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + + // When we search for an option that matches things in both personalDetails and reports + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); + + // Then all single participant reports that match will show up in the recentReports array + expect(results.recentReports.length).toBe(5); + expect(results.recentReports[0].text).toBe('Mister Sinister'); + + // And logins with no single participant reports will show up in personalDetails + expect(results.personalDetails.length).toBe(4); + expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + + // When we provide no selected options to getNewChatOptions() + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true); + + // Then one of our older report options (not in our five most recent) should appear in the personalDetails + // but not in recentReports + expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true); + expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(false); + + // When we provide a "selected" option to getNewChatOptions() + results = OptionsListUtils.getNewChatOptions( + REPORTS, + PERSONAL_DETAILS, + [], + '', + [{login: 'peterparker@expensify.com'}], + [], + true, + ); + + // Then the option should not appear anywhere in either list + expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true); + expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(true); + + // When we add a search term for which no options exist and the searchValue itself + // is not a potential email or phone + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify', [], [], true); + + // Then we should have no options or personal details at all and also that there is no userToInvite + expect(results.recentReports.length).toBe(0); + expect(results.personalDetails.length).toBe(0); + expect(results.userToInvite).toBe(null); + + // When we add a search term for which no options exist and the searchValue itself + // is a potential email + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com', [], [], true); + + // Then we should have no options or personal details at all but there should be a userToInvite + expect(results.recentReports.length).toBe(0); + expect(results.personalDetails.length).toBe(0); + expect(results.userToInvite).not.toBe(null); + + // When we add a search term for which no options exist and the searchValue itself + // is a potential phone number without country code added + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006', [], [], true); + + // Then we should have no options or personal details at all but there should be a userToInvite and the login + // should have the country code included + expect(results.recentReports.length).toBe(0); + expect(results.personalDetails.length).toBe(0); + expect(results.userToInvite).not.toBe(null); + expect(results.userToInvite.login).toBe('+15005550006'); + + // When we add a search term for which no options exist and the searchValue itself + // is a potential phone number with country code added + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006', [], [], true); + + // Then we should have no options or personal details at all but there should be a userToInvite and the login + // should have the country code included + expect(results.recentReports.length).toBe(0); + expect(results.personalDetails.length).toBe(0); + expect(results.userToInvite).not.toBe(null); + expect(results.userToInvite.login).toBe('+15005550006'); + + // Test Concierge's existence in new group options + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.RECEIPTS], true); + + // Concierge is included in the results by default. We should expect all the personalDetails to show + // (minus the 5 that are already showing and the currently logged in user) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 6); + expect(results.recentReports).toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + + // Test by excluding Concierge from the results + results = OptionsListUtils.getNewChatOptions( + REPORTS_WITH_CONCIERGE, + PERSONAL_DETAILS_WITH_CONCIERGE, + [], + '', + [], + [CONST.EMAIL.CONCIERGE], + true, + ); + + // We should expect all the personalDetails to show (minus the 5 that are already showing, + // the currently logged in user and Concierge) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 7); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + expect(results.recentReports).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'concierge@expensify.com'}), + ]), + ); + + // Test by excluding Chronos from the results + results = OptionsListUtils.getNewChatOptions( + REPORTS_WITH_CHRONOS, + PERSONAL_DETAILS_WITH_CHRONOS, + [], + '', + [], + [CONST.EMAIL.CHRONOS], + true, + ); + + // We should expect all the personalDetails to show (minus the 5 that are already showing, + // the currently logged in user and Concierge) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'chronos@expensify.com'}), + ]), + ); + expect(results.recentReports).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'chronos@expensify.com'}), + ]), + ); + + // Test by excluding Receipts from the results + results = OptionsListUtils.getNewChatOptions( + REPORTS_WITH_RECEIPTS, + PERSONAL_DETAILS_WITH_RECEIPTS, + [], + '', + [], + [CONST.EMAIL.RECEIPTS], + true, + ); + + // We should expect all the personalDetails to show (minus the 5 that are already showing, + // the currently logged in user and Concierge) + expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7); + expect(results.personalDetails).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'receipts@expensify.com'}), + ]), + ); + expect(results.recentReports).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({login: 'receipts@expensify.com'}), + ]), + ); + }); + it('getSidebarOptions() with default priority mode', () => { const reportsWithAddedPinnedMessagelessReport = { ...REPORTS, From fb23b692d1efbad6a12f3ecb77f60566c5c0db05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sat, 9 Apr 2022 12:26:23 +0300 Subject: [PATCH 02/11] added getNewChatOptions default parameter,function calls changed. --- src/libs/OptionsListUtils.js | 2 +- src/pages/NewChatPage.js | 3 - .../IOUParticipantsRequest.js | 2 - .../IOUParticipantsSplit.js | 3 - src/pages/workspace/WorkspaceInvitePage.js | 3 + tests/unit/OptionsListUtilsTest.js | 101 +++++++++--------- 6 files changed, 56 insertions(+), 58 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 3948ef5751d6..9024d70ae325 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -716,7 +716,7 @@ function getNewChatOptions( searchValue = '', selectedOptions = [], excludeLogins = [], - sortByLastMessageTimestamp, + sortByLastMessageTimestamp = true, ) { return getOptions(reports, personalDetails, 0, { betas, diff --git a/src/pages/NewChatPage.js b/src/pages/NewChatPage.js index e65efee54484..00f2209d3d3e 100755 --- a/src/pages/NewChatPage.js +++ b/src/pages/NewChatPage.js @@ -77,7 +77,6 @@ class NewChatPage extends Component { '', [], this.props.isGroupChat ? this.excludedGroupEmails : [], - true, ); this.state = { searchValue: '', @@ -185,7 +184,6 @@ class NewChatPage extends Component { prevState.searchValue, [], this.excludedGroupEmails, - true, ); return { @@ -258,7 +256,6 @@ class NewChatPage extends Component { searchValue, [], this.props.isGroupChat ? this.excludedGroupEmails : [], - true, ); this.setState({ searchValue, diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js index 76d5a52418ff..247a873c12d3 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsRequest.js @@ -49,7 +49,6 @@ class IOUParticipantsRequest extends Component { '', [], CONST.EXPENSIFY_EMAILS, - true, ); this.state = { @@ -128,7 +127,6 @@ class IOUParticipantsRequest extends Component { searchValue, [], CONST.EXPENSIFY_EMAILS, - true, ); this.setState({ searchValue, diff --git a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js index 032cdc61c5fb..46c048e819a6 100755 --- a/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js +++ b/src/pages/iou/steps/IOUParticipantsPage/IOUParticipantsSplit.js @@ -74,7 +74,6 @@ class IOUParticipantsSplit extends Component { '', props.participants, CONST.EXPENSIFY_EMAILS, - true, ); this.state = { @@ -176,7 +175,6 @@ class IOUParticipantsSplit extends Component { isOptionInList ? prevState.searchValue : '', newSelectedOptions, CONST.EXPENSIFY_EMAILS, - true, ); return { recentReports, @@ -219,7 +217,6 @@ class IOUParticipantsSplit extends Component { searchValue, [], CONST.EXPENSIFY_EMAILS, - true, ); this.setState({ searchValue, diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 16777e17fd16..0e0024c3d8d6 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -75,6 +75,7 @@ class WorkspaceInvitePage extends React.Component { '', [], this.getExcludedUsers(), + false, ); this.state = { searchValue: '', @@ -199,6 +200,7 @@ class WorkspaceInvitePage extends React.Component { prevState.searchValue, [], this.getExcludedUsers(), + false, ); return { @@ -282,6 +284,7 @@ class WorkspaceInvitePage extends React.Component { searchValue, [], this.getExcludedUsers(), + false, ); this.setState({ searchValue, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 57646aad0cc3..d62fd2d76908 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -31,7 +31,7 @@ describe('OptionsListUtils', () => { // This is the only report we are pinning in this test 3: { lastVisitedTimestamp: 1610666739297, - lastMessageTimestamp: 17, + lastMessageTimestamp: 170, isPinned: true, reportID: 3, participants: ['reedrichards@expensify.com'], @@ -40,7 +40,7 @@ describe('OptionsListUtils', () => { }, 4: { lastVisitedTimestamp: 1610666739298, - lastMessageTimestamp: 18, + lastMessageTimestamp: 180, isPinned: false, reportID: 4, participants: ['tchalla@expensify.com'], @@ -279,7 +279,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports[0].text).toBe('Mister Fantastic'); }); - it('getSearchOptions() with message timeStamp order', () => { + it('getSearchOptions() with message timeStampOrder', () => { // When we filter in the Search view without providing a searchValue let results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '', [], true); @@ -311,12 +311,12 @@ describe('OptionsListUtils', () => { expect(results.recentReports[0].text).toBe('Mister Sinister'); }); - it('getNewChatOptions()', () => { + it('getNewChatOptions() not using default message timeStampOrder', () => { // maxRecentReportsToShow in src/libs/OptionsListUtils.js const MAX_RECENT_REPORTS = 5; // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], ''); + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], false); // We should expect maximimum of 5 recent reports to be returned expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS); @@ -333,13 +333,13 @@ describe('OptionsListUtils', () => { expect(personalDetailWithExistingReport.reportID).toBe(2); // When we provide a search value that does not match any personal details - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], [], false); // Then no options will be returned expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches an email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], [], false); // Then one recentReports will be returned and it will be the correct option // personalDetails should be empty array @@ -348,7 +348,7 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches a partial display name or email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man', [], [], false); // Then several options will be returned and they will be each have the search string in their email or name // even though the currently logged in user matches they should not show. @@ -359,7 +359,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports[1].text).toBe('Spider-Man'); // Test for Concierge's existence in chat options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [], false); // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) @@ -372,7 +372,7 @@ describe('OptionsListUtils', () => { // Test by excluding Concierge from the results results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], + REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], false, ); // All the personalDetails should be returned minus the currently logged in user and Concierge @@ -385,7 +385,7 @@ describe('OptionsListUtils', () => { // Test by excluding Chronos from the results results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], + REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], false, ); // All the personalDetails should be returned minus the currently logged in user and Concierge @@ -398,7 +398,7 @@ describe('OptionsListUtils', () => { // Test by excluding Receipts from the results results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], + REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], false, ); // All the personalDetails should be returned minus the currently logged in user and Concierge @@ -410,12 +410,12 @@ describe('OptionsListUtils', () => { ); }); - it('getNewChatOptions() using message timeStamp order', () => { + it('getNewChatOptions() using default message timeStampOrder', () => { // maxRecentReportsToShow in src/libs/OptionsListUtils.js const MAX_RECENT_REPORTS = 5; // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true); + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); // We should expect maximimum of 5 recent reports to be returned expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS); @@ -432,13 +432,13 @@ describe('OptionsListUtils', () => { expect(personalDetailWithExistingReport.reportID).toBe(2); // When we provide a search value that does not match any personal details - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], []); // Then no options will be returned expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches an email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], []); // Then one recentReports will be returned and it will be the correct option // personalDetails should be empty array @@ -447,16 +447,16 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches a partial display name or email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], []); // Then several options will be returned and they will be each have the search string in their email or name // even though the currently logged in user matches they should not show. expect(results.personalDetails.length).toBe(4); expect(results.recentReports.length).toBe(5); - expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + expect(results.personalDetails[0].login).toBe('peterparker@expensify.com'); expect(results.recentReports[0].text).toBe('Captain America'); expect(results.recentReports[1].text).toBe('Mister Sinister'); - expect(results.recentReports[2].text).toBe('Thor'); + expect(results.recentReports[2].text).toBe('Black Panther'); // When we provide a search value that matches a partial display name or email results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); @@ -470,7 +470,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports[1].text).toBe('Captain America'); // Test for Concierge's existence in chat options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], []); // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) @@ -483,7 +483,7 @@ describe('OptionsListUtils', () => { // Test by excluding Concierge from the results results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], true, + REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], ); // All the personalDetails should be returned minus the currently logged in user and Concierge @@ -496,7 +496,7 @@ describe('OptionsListUtils', () => { // Test by excluding Chronos from the results results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], true, + REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], ); // All the personalDetails should be returned minus the currently logged in user and Concierge @@ -509,7 +509,7 @@ describe('OptionsListUtils', () => { // Test by excluding Receipts from the results results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], true, + REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], ); // All the personalDetails should be returned minus the currently logged in user and Concierge @@ -521,9 +521,9 @@ describe('OptionsListUtils', () => { ); }); - it('getNewChatOptions() for group Chat', () => { + it('getNewChatOptions() for group Chat not using default message timeStamp order', () => { // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], ''); + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], '', false); // Then we should expect only a maxmimum of 5 recent reports to be returned expect(results.recentReports.length).toBe(5); @@ -540,7 +540,7 @@ describe('OptionsListUtils', () => { expect(personalDetailsOverlapWithReports).toBe(false); // When we search for an option that is only in a personalDetail with no existing report - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk', [], '', false); // Then reports should return no results expect(results.recentReports.length).toBe(0); @@ -550,7 +550,7 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[0].login).toBe('brucebanner@expensify.com'); // When we search for an option that matches things in both personalDetails and reports - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man', [], '', false); // Then all single participant reports that match will show up in the recentReports array expect(results.recentReports.length).toBe(2); @@ -562,7 +562,7 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); // When we provide no selected options to getNewChatOptions() - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', []); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], '', false); // Then one of our older report options (not in our five most recent) should appear in the personalDetails // but not in recentReports @@ -576,6 +576,8 @@ describe('OptionsListUtils', () => { [], '', [{login: 'peterparker@expensify.com'}], + '', + false, ); // Then the option should not appear anywhere in either list @@ -584,7 +586,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is not a potential email or phone - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify', [], '', false); // Then we should have no options or personal details at all and also that there is no userToInvite expect(results.recentReports.length).toBe(0); @@ -593,7 +595,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com', [], '', false); // Then we should have no options or personal details at all but there should be a userToInvite expect(results.recentReports.length).toBe(0); @@ -602,7 +604,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential phone number without country code added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006', [], '', false); // Then we should have no options or personal details at all but there should be a userToInvite and the login // should have the country code included @@ -613,7 +615,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential phone number with country code added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006'); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006', [], '', false); // Then we should have no options or personal details at all but there should be a userToInvite and the login // should have the country code included @@ -623,7 +625,7 @@ describe('OptionsListUtils', () => { expect(results.userToInvite.login).toBe('+15005550006'); // Test Concierge's existence in new group options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], '', false); // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) @@ -642,6 +644,8 @@ describe('OptionsListUtils', () => { '', [], [CONST.EMAIL.CONCIERGE], + '', + false, ); // We should expect all the personalDetails to show (minus the 5 that are already showing, @@ -666,6 +670,8 @@ describe('OptionsListUtils', () => { '', [], [CONST.EMAIL.CHRONOS], + '', + false, ); // We should expect all the personalDetails to show (minus the 5 that are already showing, @@ -690,6 +696,8 @@ describe('OptionsListUtils', () => { '', [], [CONST.EMAIL.RECEIPTS], + '', + false, ); // We should expect all the personalDetails to show (minus the 5 that are already showing, @@ -707,9 +715,9 @@ describe('OptionsListUtils', () => { ); }); - it('getNewChatOptions() for group Chat using message timeStamp order', () => { + it('getNewChatOptions() for group Chat using default message timeStamp order', () => { // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true); + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); // Then we should expect only a maxmimum of 5 recent reports to be returned expect(results.recentReports.length).toBe(5); @@ -726,7 +734,7 @@ describe('OptionsListUtils', () => { expect(personalDetailsOverlapWithReports).toBe(false); // When we search for an option that is only in a personalDetail with no existing report - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk'); // Then reports should return no results expect(results.recentReports.length).toBe(0); @@ -736,7 +744,7 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[0].login).toBe('brucebanner@expensify.com'); // When we search for an option that matches things in both personalDetails and reports - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com'); // Then all single participant reports that match will show up in the recentReports array expect(results.recentReports.length).toBe(5); @@ -744,7 +752,7 @@ describe('OptionsListUtils', () => { // And logins with no single participant reports will show up in personalDetails expect(results.personalDetails.length).toBe(4); - expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + expect(results.personalDetails[0].login).toBe('peterparker@expensify.com'); // When we search for an option that matches things in both personalDetails and reports results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); @@ -758,7 +766,7 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); // When we provide no selected options to getNewChatOptions() - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); // Then one of our older report options (not in our five most recent) should appear in the personalDetails // but not in recentReports @@ -772,8 +780,6 @@ describe('OptionsListUtils', () => { [], '', [{login: 'peterparker@expensify.com'}], - [], - true, ); // Then the option should not appear anywhere in either list @@ -782,7 +788,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is not a potential email or phone - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify'); // Then we should have no options or personal details at all and also that there is no userToInvite expect(results.recentReports.length).toBe(0); @@ -791,7 +797,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com'); // Then we should have no options or personal details at all but there should be a userToInvite expect(results.recentReports.length).toBe(0); @@ -800,7 +806,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential phone number without country code added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006'); // Then we should have no options or personal details at all but there should be a userToInvite and the login // should have the country code included @@ -811,7 +817,7 @@ describe('OptionsListUtils', () => { // When we add a search term for which no options exist and the searchValue itself // is a potential phone number with country code added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006', [], [], true); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006'); // Then we should have no options or personal details at all but there should be a userToInvite and the login // should have the country code included @@ -821,7 +827,7 @@ describe('OptionsListUtils', () => { expect(results.userToInvite.login).toBe('+15005550006'); // Test Concierge's existence in new group options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.RECEIPTS], true); + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.RECEIPTS]); // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) @@ -840,7 +846,6 @@ describe('OptionsListUtils', () => { '', [], [CONST.EMAIL.CONCIERGE], - true, ); // We should expect all the personalDetails to show (minus the 5 that are already showing, @@ -865,7 +870,6 @@ describe('OptionsListUtils', () => { '', [], [CONST.EMAIL.CHRONOS], - true, ); // We should expect all the personalDetails to show (minus the 5 that are already showing, @@ -890,7 +894,6 @@ describe('OptionsListUtils', () => { '', [], [CONST.EMAIL.RECEIPTS], - true, ); // We should expect all the personalDetails to show (minus the 5 that are already showing, From d13c668b17744c2b788be613d7cd197f0750bd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Wed, 20 Apr 2022 22:26:27 +0300 Subject: [PATCH 03/11] Contacts sorted by alphabetical order,test file changed --- src/libs/OptionsListUtils.js | 6 ++++-- src/pages/workspace/WorkspaceInvitePage.js | 3 --- tests/unit/OptionsListUtilsTest.js | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 9024d70ae325..be3faea7b750 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -483,13 +483,16 @@ function getOptions(reports, personalDetails, activeReportID, { })); }); - const allPersonalDetailsOptions = _.map(personalDetails, personalDetail => ( + let allPersonalDetailsOptions = _.map(personalDetails, personalDetail => ( createOption([personalDetail], reportMapForLogins[personalDetail.login], { showChatPreviewLine, forcePolicyNamePreview, }) )); + // PersonalDetails should be ordered Alphabetically by default acording to issue #8220 + allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [personalDetail => personalDetail.text.toLowerCase()], 'asc'); + // Always exclude already selected options and the currently logged in user const loginOptionsToExclude = [...selectedOptions, {login: currentUserLogin}]; @@ -622,7 +625,6 @@ function getOptions(reports, personalDetails, activeReportID, { return 1; }], ['asc']); } - return { personalDetails: personalDetailsOptions, recentReports: recentReportOptions, diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 0e0024c3d8d6..16777e17fd16 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -75,7 +75,6 @@ class WorkspaceInvitePage extends React.Component { '', [], this.getExcludedUsers(), - false, ); this.state = { searchValue: '', @@ -200,7 +199,6 @@ class WorkspaceInvitePage extends React.Component { prevState.searchValue, [], this.getExcludedUsers(), - false, ); return { @@ -284,7 +282,6 @@ class WorkspaceInvitePage extends React.Component { searchValue, [], this.getExcludedUsers(), - false, ); this.setState({ searchValue, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index d62fd2d76908..50af94e75dfd 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -453,7 +453,7 @@ describe('OptionsListUtils', () => { // even though the currently logged in user matches they should not show. expect(results.personalDetails.length).toBe(4); expect(results.recentReports.length).toBe(5); - expect(results.personalDetails[0].login).toBe('peterparker@expensify.com'); + expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); expect(results.recentReports[0].text).toBe('Captain America'); expect(results.recentReports[1].text).toBe('Mister Sinister'); expect(results.recentReports[2].text).toBe('Black Panther'); @@ -465,7 +465,7 @@ describe('OptionsListUtils', () => { // even though the currently logged in user matches they should not show. expect(results.personalDetails.length).toBe(4); expect(results.recentReports.length).toBe(5); - expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); expect(results.recentReports[0].text).toBe('Mister Sinister'); expect(results.recentReports[1].text).toBe('Captain America'); @@ -752,7 +752,7 @@ describe('OptionsListUtils', () => { // And logins with no single participant reports will show up in personalDetails expect(results.personalDetails.length).toBe(4); - expect(results.personalDetails[0].login).toBe('peterparker@expensify.com'); + expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); // When we search for an option that matches things in both personalDetails and reports results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); @@ -763,7 +763,7 @@ describe('OptionsListUtils', () => { // And logins with no single participant reports will show up in personalDetails expect(results.personalDetails.length).toBe(4); - expect(results.personalDetails[0].login).toBe('reedrichards@expensify.com'); + expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); // When we provide no selected options to getNewChatOptions() results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); From 9e5d43f6ec3970f87c0479ebaa56e4c69db34dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Wed, 20 Apr 2022 23:00:47 +0300 Subject: [PATCH 04/11] Search page ordered my recent used --- src/pages/SearchPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 1fc76da9c3be..01c30d7c52c5 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -66,6 +66,7 @@ class SearchPage extends Component { props.personalDetails, '', props.betas, + true, ); this.state = { @@ -125,6 +126,7 @@ class SearchPage extends Component { this.props.personalDetails, this.state.searchValue.trim(), this.props.betas, + true, ); this.setState({ userToInvite, From 9d79e47d70c719a8666511d4a3e83731e5163666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sun, 1 May 2022 10:41:00 +0300 Subject: [PATCH 05/11] removed sortByLastMessageTimestamp wrapper methods parameters and update test file --- src/libs/OptionsListUtils.js | 8 +- src/pages/SearchPage.js | 2 - tests/unit/OptionsListUtilsTest.js | 373 ++--------------------------- 3 files changed, 16 insertions(+), 367 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 25d1aba9e8b4..b59585dc1f4d 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -623,7 +623,6 @@ function getOptions(reports, personalDetails, activeReportID, { * @param {Object} personalDetails * @param {String} searchValue * @param {Array} betas - * @param {Boolean} sortByLastMessageTimestamp * @returns {Object} */ function getSearchOptions( @@ -631,7 +630,6 @@ function getSearchOptions( personalDetails, searchValue = '', betas, - sortByLastMessageTimestamp, ) { return getOptions(reports, personalDetails, 0, { betas, @@ -645,7 +643,7 @@ function getSearchOptions( showChatPreviewLine: true, showReportsWithNoComments: true, includePersonalDetails: true, - sortByLastMessageTimestamp, + sortByLastMessageTimestamp: true, forcePolicyNamePreview: true, prioritizeIOUDebts: false, }); @@ -692,7 +690,6 @@ function getIOUConfirmationOptionsFromParticipants( * @param {String} searchValue * @param {Array} selectedOptions * @param {Array} excludeLogins - * @param {Boolean} sortByLastMessageTimestamp * @returns {Object} */ function getNewChatOptions( @@ -702,7 +699,6 @@ function getNewChatOptions( searchValue = '', selectedOptions = [], excludeLogins = [], - sortByLastMessageTimestamp = true, ) { return getOptions(reports, personalDetails, 0, { betas, @@ -713,7 +709,7 @@ function getNewChatOptions( includePersonalDetails: true, maxRecentReportsToShow: 5, excludeLogins, - sortByLastMessageTimestamp, + sortByLastMessageTimestamp: true, }); } diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 6bc26a5880e5..30212fc2c711 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -65,7 +65,6 @@ class SearchPage extends Component { props.personalDetails, '', props.betas, - true, ); this.state = { @@ -129,7 +128,6 @@ class SearchPage extends Component { this.props.personalDetails, this.state.searchValue.trim(), this.props.betas, - true, ); this.setState({ userToInvite, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 3c6f86109bcb..a5d4efeab1a0 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -283,9 +283,10 @@ describe('OptionsListUtils', () => { // When we filter again but provide a searchValue that should match multiple times results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'fantastic'); - // Then we get both values with the pinned value still on top + // lastMessageTimestamp value should be top expect(results.recentReports.length).toBe(2); expect(results.recentReports[0].text).toBe('Mister Fantastic'); + expect(results.recentReports[1].text).toBe('tonystark@expensify.com, reedrichards@expensify.com'); // When we filter again but provide a searchValue that should match with periods results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS_WITH_PERIODS, 'barryallen@expensify.com'); @@ -295,145 +296,14 @@ describe('OptionsListUtils', () => { expect(results.recentReports[0].text).toBe('The Flash'); }); - it('getSearchOptions() with message timeStampOrder', () => { - // When we filter in the Search view without providing a searchValue - let results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '', [], true); - - // Then the 2 personalDetails that don't have reports should be returned - expect(results.personalDetails.length).toBe(2); - - // Then all of the reports should be shown, including the one that has no message on them. - expect(results.recentReports.length).toBe(_.size(REPORTS)); - - // When we filter again but provide a searchValue - results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'spider', [], true); - - // Then only one option should be returned and it's the one matching the search value - expect(results.recentReports.length).toBe(1); - expect(results.recentReports[0].login).toBe('peterparker@expensify.com'); - - // When we filter again but provide a searchValue that should match multiple times - results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '.com', [], true); - - // Then we get both values with the pinned value still on top - expect(results.recentReports.length).toBe(11); - expect(results.recentReports[0].text).toBe('Captain America'); - - // When we filter again but provide a searchValue that should match multiple times - results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, '.com', [], false); - - // Then we get both values with the pinned value still on top - expect(results.recentReports.length).toBe(11); - expect(results.recentReports[0].text).toBe('Mister Sinister'); - }); - - it('getNewChatOptions() not using default message timeStampOrder', () => { - // maxRecentReportsToShow in src/libs/OptionsListUtils.js - const MAX_RECENT_REPORTS = 5; - - // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], [], false); - - // We should expect maximimum of 5 recent reports to be returned - expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS); - - // We should expect all personalDetails to be returned, - // minus the currently logged in user and recent reports count - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 1 - MAX_RECENT_REPORTS); - - // Then the result which has an existing report should also have the reportID attached - const personalDetailWithExistingReport = _.find( - results.personalDetails, - personalDetail => personalDetail.login === 'peterparker@expensify.com', - ); - expect(personalDetailWithExistingReport.reportID).toBe(2); - - // When we provide a search value that does not match any personal details - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], [], false); - - // Then no options will be returned - expect(results.personalDetails.length).toBe(0); - - // When we provide a search value that matches an email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], [], false); - - // Then one recentReports will be returned and it will be the correct option - // personalDetails should be empty array - expect(results.recentReports.length).toBe(1); - expect(results.recentReports[0].text).toBe('Spider-Man'); - expect(results.personalDetails.length).toBe(0); - - // When we provide a search value that matches a partial display name or email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man', [], [], false); - - // Then several options will be returned and they will be each have the search string in their email or name - // even though the currently logged in user matches they should not show. - expect(results.personalDetails.length).toBe(1); - expect(results.recentReports.length).toBe(2); - expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); - expect(results.recentReports[0].text).toBe('Invisible Woman'); - expect(results.recentReports[1].text).toBe('Spider-Man'); - - // Test for Concierge's existence in chat options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [], false); - - // Concierge is included in the results by default. We should expect all the personalDetails to show - // (minus the 5 that are already showing and the currently logged in user) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 1 - MAX_RECENT_REPORTS); - expect(results.recentReports).toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'concierge@expensify.com'}), - ]), - ); - - // Test by excluding Concierge from the results - results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.CONCIERGE], false, - ); - - // All the personalDetails should be returned minus the currently logged in user and Concierge - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 2 - MAX_RECENT_REPORTS); - expect(results.personalDetails).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'concierge@expensify.com'}), - ]), - ); - - // Test by excluding Chronos from the results - results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CHRONOS, PERSONAL_DETAILS_WITH_CHRONOS, [], '', [], [CONST.EMAIL.CHRONOS], false, - ); - - // All the personalDetails should be returned minus the currently logged in user and Concierge - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 2 - MAX_RECENT_REPORTS); - expect(results.personalDetails).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'chronos@expensify.com'}), - ]), - ); - - // Test by excluding Receipts from the results - results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_RECEIPTS, PERSONAL_DETAILS_WITH_RECEIPTS, [], '', [], [CONST.EMAIL.RECEIPTS], false, - ); - - // All the personalDetails should be returned minus the currently logged in user and Concierge - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 2 - MAX_RECENT_REPORTS); - expect(results.personalDetails).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'receipts@expensify.com'}), - ]), - ); - }); - - it('getNewChatOptions() using default message timeStampOrder', () => { + it('getNewChatOptions()', () => { // maxRecentReportsToShow in src/libs/OptionsListUtils.js const MAX_RECENT_REPORTS = 5; // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], ''); - // We should expect maximimum of 5 recent reports to be returned + // We should expect maximimum of 5 recent reports to be returneda expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS); // We should expect all personalDetails to be returned, @@ -448,13 +318,13 @@ describe('OptionsListUtils', () => { expect(personalDetailWithExistingReport.reportID).toBe(2); // When we provide a search value that does not match any personal details - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto', [], []); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto'); // Then no options will be returned expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches an email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com', [], []); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peterparker@expensify.com'); // Then one recentReports will be returned and it will be the correct option // personalDetails should be empty array @@ -463,10 +333,11 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches a partial display name or email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], []); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com'); // Then several options will be returned and they will be each have the search string in their email or name // even though the currently logged in user matches they should not show. + // should be ordered by lastMessageTimestamp values expect(results.personalDetails.length).toBe(4); expect(results.recentReports.length).toBe(5); expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); @@ -474,19 +345,8 @@ describe('OptionsListUtils', () => { expect(results.recentReports[1].text).toBe('Mister Sinister'); expect(results.recentReports[2].text).toBe('Black Panther'); - // When we provide a search value that matches a partial display name or email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); - - // Then several options will be returned and they will be each have the search string in their email or name - // even though the currently logged in user matches they should not show. - expect(results.personalDetails.length).toBe(4); - expect(results.recentReports.length).toBe(5); - expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); - expect(results.recentReports[0].text).toBe('Mister Sinister'); - expect(results.recentReports[1].text).toBe('Captain America'); - // Test for Concierge's existence in chat options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], []); + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) @@ -537,203 +397,9 @@ describe('OptionsListUtils', () => { ); }); - it('getNewChatOptions() for group Chat not using default message timeStamp order', () => { + it('getNewChatOptions() for group Chat', () => { // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], '', false); - - // Then we should expect only a maxmimum of 5 recent reports to be returned - expect(results.recentReports.length).toBe(5); - - // And we should expect all the personalDetails to show (minus the 5 that are already - // showing and the currently logged in user) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 6); - - // And none of our personalDetails should include any of the users with recent reports - const reportLogins = _.map(results.recentReports, reportOption => reportOption.login); - const personalDetailsOverlapWithReports = _.every(results.personalDetails, ( - personalDetailOption => _.contains(reportLogins, personalDetailOption.login) - )); - expect(personalDetailsOverlapWithReports).toBe(false); - - // When we search for an option that is only in a personalDetail with no existing report - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'hulk', [], '', false); - - // Then reports should return no results - expect(results.recentReports.length).toBe(0); - - // And personalDetails should show just one option and it will be the one we expect - expect(results.personalDetails.length).toBe(1); - expect(results.personalDetails[0].login).toBe('brucebanner@expensify.com'); - - // When we search for an option that matches things in both personalDetails and reports - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'man', [], '', false); - - // Then all single participant reports that match will show up in the recentReports array - expect(results.recentReports.length).toBe(2); - expect(results.recentReports[0].text).toBe('Invisible Woman'); - expect(results.recentReports[1].text).toBe('Spider-Man'); - - // And logins with no single participant reports will show up in personalDetails - expect(results.personalDetails.length).toBe(1); - expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); - - // When we provide no selected options to getNewChatOptions() - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', [], '', false); - - // Then one of our older report options (not in our five most recent) should appear in the personalDetails - // but not in recentReports - expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true); - expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(false); - - // When we provide a "selected" option to getNewChatOptions() - results = OptionsListUtils.getNewChatOptions( - REPORTS, - PERSONAL_DETAILS, - [], - '', - [{login: 'peterparker@expensify.com'}], - '', - false, - ); - - // Then the option should not appear anywhere in either list - expect(_.every(results.recentReports, option => option.login !== 'peterparker@expensify.com')).toBe(true); - expect(_.every(results.personalDetails, option => option.login !== 'peterparker@expensify.com')).toBe(true); - - // When we add a search term for which no options exist and the searchValue itself - // is not a potential email or phone - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify', [], '', false); - - // Then we should have no options or personal details at all and also that there is no userToInvite - expect(results.recentReports.length).toBe(0); - expect(results.personalDetails.length).toBe(0); - expect(results.userToInvite).toBe(null); - - // When we add a search term for which no options exist and the searchValue itself - // is a potential email - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'marc@expensify.com', [], '', false); - - // Then we should have no options or personal details at all but there should be a userToInvite - expect(results.recentReports.length).toBe(0); - expect(results.personalDetails.length).toBe(0); - expect(results.userToInvite).not.toBe(null); - - // When we add a search term for which no options exist and the searchValue itself - // is a potential phone number without country code added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '5005550006', [], '', false); - - // Then we should have no options or personal details at all but there should be a userToInvite and the login - // should have the country code included - expect(results.recentReports.length).toBe(0); - expect(results.personalDetails.length).toBe(0); - expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+15005550006'); - - // When we add a search term for which no options exist and the searchValue itself - // is a potential phone number with country code added - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '+15005550006', [], '', false); - - // Then we should have no options or personal details at all but there should be a userToInvite and the login - // should have the country code included - expect(results.recentReports.length).toBe(0); - expect(results.personalDetails.length).toBe(0); - expect(results.userToInvite).not.toBe(null); - expect(results.userToInvite.login).toBe('+15005550006'); - - // Test Concierge's existence in new group options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], '', false); - - // Concierge is included in the results by default. We should expect all the personalDetails to show - // (minus the 5 that are already showing and the currently logged in user) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 6); - expect(results.recentReports).toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'concierge@expensify.com'}), - ]), - ); - - // Test by excluding Concierge from the results - results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CONCIERGE, - PERSONAL_DETAILS_WITH_CONCIERGE, - [], - '', - [], - [CONST.EMAIL.CONCIERGE], - '', - false, - ); - - // We should expect all the personalDetails to show (minus the 5 that are already showing, - // the currently logged in user and Concierge) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CONCIERGE) - 7); - expect(results.personalDetails).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'concierge@expensify.com'}), - ]), - ); - expect(results.recentReports).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'concierge@expensify.com'}), - ]), - ); - - // Test by excluding Chronos from the results - results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_CHRONOS, - PERSONAL_DETAILS_WITH_CHRONOS, - [], - '', - [], - [CONST.EMAIL.CHRONOS], - '', - false, - ); - - // We should expect all the personalDetails to show (minus the 5 that are already showing, - // the currently logged in user and Concierge) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_CHRONOS) - 7); - expect(results.personalDetails).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'chronos@expensify.com'}), - ]), - ); - expect(results.recentReports).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'chronos@expensify.com'}), - ]), - ); - - // Test by excluding Receipts from the results - results = OptionsListUtils.getNewChatOptions( - REPORTS_WITH_RECEIPTS, - PERSONAL_DETAILS_WITH_RECEIPTS, - [], - '', - [], - [CONST.EMAIL.RECEIPTS], - '', - false, - ); - - // We should expect all the personalDetails to show (minus the 5 that are already showing, - // the currently logged in user and Concierge) - expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS_WITH_RECEIPTS) - 7); - expect(results.personalDetails).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'receipts@expensify.com'}), - ]), - ); - expect(results.recentReports).not.toEqual( - expect.arrayContaining([ - expect.objectContaining({login: 'receipts@expensify.com'}), - ]), - ); - }); - - it('getNewChatOptions() for group Chat using default message timeStamp order', () => { - // When we call getNewChatOptions() with no search value - let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); + let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], ''); // Then we should expect only a maxmimum of 5 recent reports to be returned expect(results.recentReports.length).toBe(5); @@ -762,7 +428,7 @@ describe('OptionsListUtils', () => { // When we search for an option that matches things in both personalDetails and reports results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com'); - // Then all single participant reports that match will show up in the recentReports array + // Then all single participant reports that match will show up in the recentReports array, Recent used person should be top expect(results.recentReports.length).toBe(5); expect(results.recentReports[0].text).toBe('Captain America'); @@ -770,19 +436,8 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(4); expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); - // When we search for an option that matches things in both personalDetails and reports - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com', [], [], false); - - // Then all single participant reports that match will show up in the recentReports array - expect(results.recentReports.length).toBe(5); - expect(results.recentReports[0].text).toBe('Mister Sinister'); - - // And logins with no single participant reports will show up in personalDetails - expect(results.personalDetails.length).toBe(4); - expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); - // When we provide no selected options to getNewChatOptions() - results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS); + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '', []); // Then one of our older report options (not in our five most recent) should appear in the personalDetails // but not in recentReports From 19a6181fba734b7b1f868705a5c518b02f5300d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sun, 1 May 2022 11:04:12 +0300 Subject: [PATCH 06/11] spelling mistakes corrected. --- tests/unit/OptionsListUtilsTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index a5d4efeab1a0..dea05fb33376 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -303,7 +303,7 @@ describe('OptionsListUtils', () => { // When we call getNewChatOptions() with no search value let results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], ''); - // We should expect maximimum of 5 recent reports to be returneda + // We should expect maximimum of 5 recent reports to be returned expect(results.recentReports.length).toBe(MAX_RECENT_REPORTS); // We should expect all personalDetails to be returned, @@ -505,7 +505,7 @@ describe('OptionsListUtils', () => { expect(results.userToInvite.login).toBe('+15005550006'); // Test Concierge's existence in new group options - results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE, [], '', [], [CONST.EMAIL.RECEIPTS]); + results = OptionsListUtils.getNewChatOptions(REPORTS_WITH_CONCIERGE, PERSONAL_DETAILS_WITH_CONCIERGE); // Concierge is included in the results by default. We should expect all the personalDetails to show // (minus the 5 that are already showing and the currently logged in user) From 5fd20b67cd61fb8a4aab313e5b84dc5e2be6fdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sun, 1 May 2022 11:54:34 +0300 Subject: [PATCH 07/11] Alphabetically order tests added --- tests/unit/OptionsListUtilsTest.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index dea05fb33376..b5397d50d8ea 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -310,6 +310,12 @@ describe('OptionsListUtils', () => { // minus the currently logged in user and recent reports count expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 1 - MAX_RECENT_REPORTS); + // We should expect personal details sorted alphabetically + expect(results.personalDetails[0].text).toBe('Black Widow'); + expect(results.personalDetails[1].text).toBe('Invisible Woman'); + expect(results.personalDetails[2].text).toBe('Spider-Man'); + expect(results.personalDetails[3].text).toBe('The Incredible Hulk'); + // Then the result which has an existing report should also have the reportID attached const personalDetailWithExistingReport = _.find( results.personalDetails, @@ -317,6 +323,15 @@ describe('OptionsListUtils', () => { ); expect(personalDetailWithExistingReport.reportID).toBe(2); + // When we call only pass personal details + results = OptionsListUtils.getNewChatOptions([], PERSONAL_DETAILS, [], ''); + + // We should expect personal details sorted alphabetically + expect(results.personalDetails[0].text).toBe('Black Panther'); + expect(results.personalDetails[1].text).toBe('Black Widow'); + expect(results.personalDetails[2].text).toBe('Captain America'); + expect(results.personalDetails[3].text).toBe('Invisible Woman'); + // When we provide a search value that does not match any personal details results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'magneto'); @@ -408,6 +423,12 @@ describe('OptionsListUtils', () => { // showing and the currently logged in user) expect(results.personalDetails.length).toBe(_.size(PERSONAL_DETAILS) - 6); + // We should expect personal details sorted alphabetically + expect(results.personalDetails[0].text).toBe('Black Widow'); + expect(results.personalDetails[1].text).toBe('Invisible Woman'); + expect(results.personalDetails[2].text).toBe('Spider-Man'); + expect(results.personalDetails[3].text).toBe('The Incredible Hulk'); + // And none of our personalDetails should include any of the users with recent reports const reportLogins = _.map(results.recentReports, reportOption => reportOption.login); const personalDetailsOverlapWithReports = _.every(results.personalDetails, ( From c3f8620c2d95e4dcfe1eb0090fe43423dcfea04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sat, 14 May 2022 12:11:30 +0300 Subject: [PATCH 08/11] change default paramater in getOptions, better comments added. --- src/libs/OptionsListUtils.js | 7 ++----- tests/unit/OptionsListUtilsTest.js | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index b59585dc1f4d..45d3ec56917e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -373,7 +373,7 @@ function getOptions(reports, personalDetails, activeReportID, { // When sortByReportTypeInSearch flag is true, recentReports will include the personalDetails options as well. sortByReportTypeInSearch = false, - sortByLastMessageTimestamp = false, + sortByLastMessageTimestamp = true, searchValue = '', showChatPreviewLine = false, showReportsWithNoComments = false, @@ -470,7 +470,7 @@ function getOptions(reports, personalDetails, activeReportID, { }) )); - // PersonalDetails should be ordered Alphabetically by default acording to issue #8220 + // PersonalDetails should be ordered Alphabetically by default - https://github.com/Expensify/App/issues/8220#issuecomment-1104009435 allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [personalDetail => personalDetail.text.toLowerCase()], 'asc'); // Always exclude already selected options and the currently logged in user @@ -643,7 +643,6 @@ function getSearchOptions( showChatPreviewLine: true, showReportsWithNoComments: true, includePersonalDetails: true, - sortByLastMessageTimestamp: true, forcePolicyNamePreview: true, prioritizeIOUDebts: false, }); @@ -709,7 +708,6 @@ function getNewChatOptions( includePersonalDetails: true, maxRecentReportsToShow: 5, excludeLogins, - sortByLastMessageTimestamp: true, }); } @@ -746,7 +744,6 @@ function getSidebarOptions( includeRecentReports: true, includeMultipleParticipantReports: true, maxRecentReportsToShow: 0, // Unlimited - sortByLastMessageTimestamp: true, showChatPreviewLine: true, prioritizePinnedReports: true, ...sideBarOptions, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index b5397d50d8ea..13a58d3d34d4 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -283,7 +283,7 @@ describe('OptionsListUtils', () => { // When we filter again but provide a searchValue that should match multiple times results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS, 'fantastic'); - // lastMessageTimestamp value should be top + // Value with latest lastMessageTimestamp should be at the top. expect(results.recentReports.length).toBe(2); expect(results.recentReports[0].text).toBe('Mister Fantastic'); expect(results.recentReports[1].text).toBe('tonystark@expensify.com, reedrichards@expensify.com'); @@ -323,7 +323,7 @@ describe('OptionsListUtils', () => { ); expect(personalDetailWithExistingReport.reportID).toBe(2); - // When we call only pass personal details + // When we only pass personal details results = OptionsListUtils.getNewChatOptions([], PERSONAL_DETAILS, [], ''); // We should expect personal details sorted alphabetically @@ -352,7 +352,7 @@ describe('OptionsListUtils', () => { // Then several options will be returned and they will be each have the search string in their email or name // even though the currently logged in user matches they should not show. - // should be ordered by lastMessageTimestamp values + // Should be ordered by lastMessageTimestamp values. expect(results.personalDetails.length).toBe(4); expect(results.recentReports.length).toBe(5); expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); @@ -449,7 +449,7 @@ describe('OptionsListUtils', () => { // When we search for an option that matches things in both personalDetails and reports results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], '.com'); - // Then all single participant reports that match will show up in the recentReports array, Recent used person should be top + // Then all single participant reports that match will show up in the recentReports array, Recently used contact should be at the top expect(results.recentReports.length).toBe(5); expect(results.recentReports[0].text).toBe('Captain America'); From 1a8b5cd1d930809cafb38b7ef4b3765f014f71ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sun, 12 Jun 2022 12:44:05 +0300 Subject: [PATCH 09/11] new wrapper method added , test document updated --- src/libs/OptionsListUtils.js | 38 ++++++++++++++++++++-- src/pages/workspace/WorkspaceInvitePage.js | 6 ++-- tests/unit/OptionsListUtilsTest.js | 24 ++++++++++++++ 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 2f58f38ad8d8..44dfe5aea6b8 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -380,6 +380,7 @@ function getOptions(reports, personalDetails, activeReportID, { showReportsWithNoComments = false, hideReadReports = false, sortByAlphaAsc = false, + sortPersonalDetailsByAlphaAsc = true, forcePolicyNamePreview = false, prioritizeIOUDebts = false, prioritizeReportsWithDraftComments = false, @@ -471,8 +472,10 @@ function getOptions(reports, personalDetails, activeReportID, { }) )); - // PersonalDetails should be ordered Alphabetically by default - https://github.com/Expensify/App/issues/8220#issuecomment-1104009435 - allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [personalDetail => personalDetail.text.toLowerCase()], 'asc'); + if (sortPersonalDetailsByAlphaAsc) { + // PersonalDetails should be ordered Alphabetically by default - https://github.com/Expensify/App/issues/8220#issuecomment-1104009435 + allPersonalDetailsOptions = lodashOrderBy(allPersonalDetailsOptions, [personalDetail => personalDetail.text.toLowerCase()], 'asc'); + } // Always exclude already selected options and the currently logged in user const loginOptionsToExclude = [...selectedOptions, {login: currentUserLogin}]; @@ -712,6 +715,36 @@ function getNewChatOptions( }); } +/** + * Build the options for the Workspace Member Invite view + * + * @param {Object} reports + * @param {Object} personalDetails + * @param {Array} betas + * @param {String} searchValue + * @param {Array} selectedOptions + * @param {Array} excludeLogins + * @returns {Object} + */ +function getMemberInviteOptions( + reports, + personalDetails, + betas = [], + searchValue = '', + selectedOptions = [], + excludeLogins = [], +) { + return getOptions(reports, personalDetails, 0, { + betas, + searchValue: searchValue.trim(), + selectedOptions, + excludeDefaultRooms: true, + includePersonalDetails: true, + excludeLogins, + sortPersonalDetailsByAlphaAsc: false, + }); +} + /** * Build the options for the Sidebar a.k.a. LHN * @@ -804,6 +837,7 @@ export { isCurrentUser, getSearchOptions, getNewChatOptions, + getMemberInviteOptions, getSidebarOptions, getHeaderMessage, getPersonalDetailsForLogins, diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 0aa6dbcd079c..7c3251aac628 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -68,7 +68,7 @@ class WorkspaceInvitePage extends React.Component { const { personalDetails, userToInvite, - } = OptionsListUtils.getNewChatOptions( + } = OptionsListUtils.getMemberInviteOptions( [], props.personalDetails, props.betas, @@ -192,7 +192,7 @@ class WorkspaceInvitePage extends React.Component { const { personalDetails, userToInvite, - } = OptionsListUtils.getNewChatOptions( + } = OptionsListUtils.getMemberInviteOptions( [], this.props.personalDetails, this.props.betas, @@ -275,7 +275,7 @@ class WorkspaceInvitePage extends React.Component { const { personalDetails, userToInvite, - } = OptionsListUtils.getNewChatOptions( + } = OptionsListUtils.getMemberInviteOptions( [], this.props.personalDetails, this.props.betas, diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 52e502243fd3..5801d937034d 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -622,6 +622,30 @@ describe('OptionsListUtils', () => { ); }); + it('getMemberInviteOptions()', () => { + // When we only pass personal details + let results = OptionsListUtils.getMemberInviteOptions([], PERSONAL_DETAILS, [], ''); + + // We should expect personal details PERSONAL_DETAILS order + expect(results.personalDetails[0].text).toBe('Mister Fantastic'); + expect(results.personalDetails[1].text).toBe('Spider-Man'); + expect(results.personalDetails[2].text).toBe('Black Panther'); + expect(results.personalDetails[3].text).toBe('Invisible Woman'); + + // When we provide a search value that does not match any personal details + results = OptionsListUtils.getMemberInviteOptions([], PERSONAL_DETAILS, [], 'magneto'); + + // Then no options will be returned + expect(results.personalDetails.length).toBe(0); + + // When we provide a search value that matches an email + results = OptionsListUtils.getNewChatOptions([], PERSONAL_DETAILS, [], 'peterparker@expensify.com'); + + // Then one personal should be in personalDetails list + expect(results.personalDetails.length).toBe(1); + expect(results.personalDetails[0].text).toBe('Spider-Man'); + }); + it('getSidebarOptions() with default priority mode', () => { const reportsWithAddedPinnedMessagelessReport = { ...REPORTS, From 568916235bd96e257247ccdd904a6131a1ea33c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Sun, 12 Jun 2022 12:52:38 +0300 Subject: [PATCH 10/11] test document updated --- tests/unit/OptionsListUtilsTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index 8f97741145f0..cf501b8edbaf 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -305,7 +305,7 @@ describe('OptionsListUtils', () => { // Value with latest lastMessageTimestamp should be at the top. expect(results.recentReports.length).toBe(2); expect(results.recentReports[0].text).toBe('Mister Fantastic'); - expect(results.recentReports[1].text).toBe('tonystark@expensify.com, reedrichards@expensify.com'); + expect(results.recentReports[1].text).toBe('Iron Man, Mister Fantastic'); // When we filter again but provide a searchValue that should match with periods results = OptionsListUtils.getSearchOptions(REPORTS, PERSONAL_DETAILS_WITH_PERIODS, 'barryallen@expensify.com'); @@ -376,7 +376,7 @@ describe('OptionsListUtils', () => { expect(results.recentReports.length).toBe(5); expect(results.personalDetails[0].login).toBe('natasharomanoff@expensify.com'); expect(results.recentReports[0].text).toBe('Captain America'); - expect(results.recentReports[1].text).toBe('Mister Sinister'); + expect(results.recentReports[1].text).toBe('Mr Sinister'); expect(results.recentReports[2].text).toBe('Black Panther'); // Test for Concierge's existence in chat options From 32f0441251050b8e8dc041bd61a6cabb781f7fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Metehan=20=C3=96zyurt?= Date: Thu, 16 Jun 2022 21:35:22 +0300 Subject: [PATCH 11/11] unused parameters removed from function --- src/libs/OptionsListUtils.js | 8 ++------ src/pages/workspace/WorkspaceInvitePage.js | 6 ------ tests/unit/OptionsListUtilsTest.js | 6 +++--- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 393c8479420e..da16be11ca63 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -613,6 +613,7 @@ function getOptions(reports, personalDetails, activeReportID, { return 0; }], ['asc']); } + return { personalDetails: personalDetailsOptions, recentReports: recentReportOptions, @@ -718,26 +719,21 @@ function getNewChatOptions( /** * Build the options for the Workspace Member Invite view * - * @param {Object} reports * @param {Object} personalDetails * @param {Array} betas * @param {String} searchValue - * @param {Array} selectedOptions * @param {Array} excludeLogins * @returns {Object} */ function getMemberInviteOptions( - reports, personalDetails, betas = [], searchValue = '', - selectedOptions = [], excludeLogins = [], ) { - return getOptions(reports, personalDetails, 0, { + return getOptions([], personalDetails, 0, { betas, searchValue: searchValue.trim(), - selectedOptions, excludeDefaultRooms: true, includePersonalDetails: true, excludeLogins, diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index 7c3251aac628..8976f10d934c 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -69,11 +69,9 @@ class WorkspaceInvitePage extends React.Component { personalDetails, userToInvite, } = OptionsListUtils.getMemberInviteOptions( - [], props.personalDetails, props.betas, '', - [], this.getExcludedUsers(), ); this.state = { @@ -193,11 +191,9 @@ class WorkspaceInvitePage extends React.Component { personalDetails, userToInvite, } = OptionsListUtils.getMemberInviteOptions( - [], this.props.personalDetails, this.props.betas, prevState.searchValue, - [], this.getExcludedUsers(), ); @@ -276,11 +272,9 @@ class WorkspaceInvitePage extends React.Component { personalDetails, userToInvite, } = OptionsListUtils.getMemberInviteOptions( - [], this.props.personalDetails, this.props.betas, searchValue, - [], this.getExcludedUsers(), ); this.setState({ diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index cf501b8edbaf..3a174a50cf1f 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -631,7 +631,7 @@ describe('OptionsListUtils', () => { it('getMemberInviteOptions()', () => { // When we only pass personal details - let results = OptionsListUtils.getMemberInviteOptions([], PERSONAL_DETAILS, [], ''); + let results = OptionsListUtils.getMemberInviteOptions(PERSONAL_DETAILS, [], ''); // We should expect personal details PERSONAL_DETAILS order expect(results.personalDetails[0].text).toBe('Mister Fantastic'); @@ -640,13 +640,13 @@ describe('OptionsListUtils', () => { expect(results.personalDetails[3].text).toBe('Invisible Woman'); // When we provide a search value that does not match any personal details - results = OptionsListUtils.getMemberInviteOptions([], PERSONAL_DETAILS, [], 'magneto'); + results = OptionsListUtils.getMemberInviteOptions(PERSONAL_DETAILS, [], 'magneto'); // Then no options will be returned expect(results.personalDetails.length).toBe(0); // When we provide a search value that matches an email - results = OptionsListUtils.getNewChatOptions([], PERSONAL_DETAILS, [], 'peterparker@expensify.com'); + results = OptionsListUtils.getMemberInviteOptions(PERSONAL_DETAILS, [], 'peterparker@expensify.com'); // Then one personal should be in personalDetails list expect(results.personalDetails.length).toBe(1);