From b6610ba0210088581014e56f653e1a0c6c1a36f7 Mon Sep 17 00:00:00 2001 From: mateusbra Date: Tue, 29 Mar 2022 15:18:46 -0300 Subject: [PATCH 1/5] ignore periods on search --- src/libs/OptionsListUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 8c600a2cb4e..381bd91464f 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -175,6 +175,7 @@ function getSearchText(report, personalDetailList, isChatRoomOrPolicyExpenseChat _.each(personalDetailList, (personalDetail) => { searchTerms.push(personalDetail.displayName); searchTerms.push(personalDetail.login); + searchTerms.push(personalDetail.login.replace(/\./g, '')); }); } if (report) { @@ -333,6 +334,7 @@ function createOption(personalDetailList, report, { function isSearchStringMatch(searchValue, searchText, participantNames = new Set(), isChatRoom = false) { const searchWords = _.map( searchValue + .replace(/\./g, '') .replace(/,/g, ' ') .split(' '), word => word.trim(), From bd09df6bb4750dae9a4dadd6e39ca0d0e2579d09 Mon Sep 17 00:00:00 2001 From: mateusbra Date: Thu, 31 Mar 2022 16:36:34 -0300 Subject: [PATCH 2/5] removed unnecessary push to searchTerms and solved edge case --- src/libs/OptionsListUtils.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 381bd91464f..f279a3c619b 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -174,7 +174,6 @@ function getSearchText(report, personalDetailList, isChatRoomOrPolicyExpenseChat if (!isChatRoomOrPolicyExpenseChat) { _.each(personalDetailList, (personalDetail) => { searchTerms.push(personalDetail.displayName); - searchTerms.push(personalDetail.login); searchTerms.push(personalDetail.login.replace(/\./g, '')); }); } @@ -589,8 +588,8 @@ function getOptions(reports, personalDetails, activeReportID, { let userToInvite = null; if (searchValue - && recentReportOptions.length === 0 - && personalDetailsOptions.length === 0 + && ((recentReportOptions.length + personalDetailsOptions.length) === 0 + || (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))) && !isCurrentUser({login: searchValue}) && _.every(selectedOptions, option => option.login !== searchValue) && ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue)) From 1b2e51960367a84d8c554800c7c81b671278fbf0 Mon Sep 17 00:00:00 2001 From: mateusbra Date: Thu, 7 Apr 2022 18:25:08 -0300 Subject: [PATCH 3/5] added test unit in order to cover the search with results containing periods --- tests/unit/OptionsListUtilsTest.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index dd401341639..c46df8b8e79 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -238,6 +238,15 @@ describe('OptionsListUtils', () => { }, }; + const PERSONAL_DETAILS_WITH_PERIODS = { + ...PERSONAL_DETAILS, + + 'barry.allen@expensify.com': { + displayName: 'The Flash', + login: 'barry.allen@expensify.com', + }, + }; + // Set the currently logged in user, report data, and personal details beforeAll(() => { Onyx.init({ @@ -277,6 +286,13 @@ describe('OptionsListUtils', () => { // Then we get both values with the pinned value still on top expect(results.recentReports.length).toBe(2); expect(results.recentReports[0].text).toBe('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'); + + // Then we expect to have the personal detail with period filtered + expect(results.recentReports.length).toBe(1); + expect(results.recentReports[0].text).toBe('The Flash'); }); it('getNewChatOptions()', () => { From 2d5e3113767a89e39e4d85a2a3e4ad85242ed7de Mon Sep 17 00:00:00 2001 From: mateusbra Date: Mon, 11 Apr 2022 10:47:12 -0300 Subject: [PATCH 4/5] added tests for userToInvite --- tests/unit/OptionsListUtilsTest.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/OptionsListUtilsTest.js b/tests/unit/OptionsListUtilsTest.js index c46df8b8e79..15a9a797830 100644 --- a/tests/unit/OptionsListUtilsTest.js +++ b/tests/unit/OptionsListUtilsTest.js @@ -473,6 +473,13 @@ describe('OptionsListUtils', () => { expect(results.personalDetails.length).toBe(0); expect(results.userToInvite).not.toBe(null); + // When we add a search term for which exist options for it excluding its period. + results = OptionsListUtils.getNewChatOptions(REPORTS, PERSONAL_DETAILS, [], 'peter.parker@expensify.com'); + + // Then we will have an options at all and there should be a userToInvite too. + expect(results.recentReports.length).toBe(1); + 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'); From cd963aaf49112fc63f0c92ab1175a7049be1690f Mon Sep 17 00:00:00 2001 From: mateusbra Date: Tue, 12 Apr 2022 21:45:40 -0300 Subject: [PATCH 5/5] refactor noOptions, noOptionsMatchExactly --- src/libs/OptionsListUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f279a3c619b..7ca3e49b4b5 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -587,9 +587,9 @@ function getOptions(reports, personalDetails, activeReportID, { } let userToInvite = null; - if (searchValue - && ((recentReportOptions.length + personalDetailsOptions.length) === 0 - || (!_.find(loginOptionsToExclude, loginOptionToExclude => loginOptionToExclude.login === searchValue.toLowerCase()))) + const noOptions = (recentReportOptions.length + personalDetailsOptions.length) === 0; + const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), option => option.login === searchValue.toLowerCase()); + if (searchValue && (noOptions || noOptionsMatchExactly) && !isCurrentUser({login: searchValue}) && _.every(selectedOptions, option => option.login !== searchValue) && ((Str.isValidEmail(searchValue) && !Str.isDomainEmail(searchValue)) || Str.isValidPhone(searchValue))