diff --git a/src/hooks/useSearchSelector.base.ts b/src/hooks/useSearchSelector.base.ts index 2295ba794f5cb..2fdd9fd33ee36 100644 --- a/src/hooks/useSearchSelector.base.ts +++ b/src/hooks/useSearchSelector.base.ts @@ -268,6 +268,7 @@ function useSearchSelectorBase({ searchString: computedSearchTerm, includeUserToInvite, includeCurrentUser, + shouldAcceptName: true, }); default: return getEmptyOptions(); diff --git a/src/libs/OptionsListUtils/index.ts b/src/libs/OptionsListUtils/index.ts index 08cfe6e4b4bcb..7b8f7e39f132d 100644 --- a/src/libs/OptionsListUtils/index.ts +++ b/src/libs/OptionsListUtils/index.ts @@ -2086,6 +2086,7 @@ function getValidOptions( maxElements, includeUserToInvite = false, maxRecentReportElements = undefined, + shouldAcceptName = false, ...config }: GetOptionsConfig = {}, countryCode: number = CONST.DEFAULT_COUNTRY_CODE, @@ -2271,6 +2272,7 @@ function getValidOptions( countryCode, { excludeLogins: loginsToExclude, + shouldAcceptName, }, ); } diff --git a/src/libs/OptionsListUtils/types.ts b/src/libs/OptionsListUtils/types.ts index c13b856af8bfb..c8c03f52a864d 100644 --- a/src/libs/OptionsListUtils/types.ts +++ b/src/libs/OptionsListUtils/types.ts @@ -190,6 +190,7 @@ type GetOptionsConfig = { maxElements?: number; maxRecentReportElements?: number; includeUserToInvite?: boolean; + shouldAcceptName?: boolean; } & GetValidReportsConfig; type GetUserToInviteConfig = { diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index e597953bed302..c5911c57b7f5e 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -1940,6 +1940,28 @@ describe('OptionsListUtils', () => { expect(filteredOptions.userToInvite).toBe(null); }); + it('should not return userToInvite for plain text name when shouldAcceptName is false', () => { + // Given a set of options + const options = getValidOptions({reports: OPTIONS.reports, personalDetails: OPTIONS.personalDetails}, {}, nvpDismissedProductTraining, {includeUserToInvite: true}); + + // When we call filterAndOrderOptions with a plain text name (not email or phone) without shouldAcceptName + const filteredOptions = filterAndOrderOptions(options, 'Jeff Amazon', COUNTRY_CODE, {shouldAcceptName: false}); + + // Then userToInvite should be null since plain names are not accepted by default + expect(filteredOptions?.userToInvite).toBe(null); + }); + + it('should return userToInvite for plain text name when shouldAcceptName is true', () => { + // Given a set of options + const options = getValidOptions({reports: OPTIONS.reports, personalDetails: OPTIONS.personalDetails}, {}, nvpDismissedProductTraining, {includeUserToInvite: true}); + + // When we call filterAndOrderOptions with a plain text name (not email or phone) with shouldAcceptName + const filteredOptions = filterAndOrderOptions(options, 'Jeff', COUNTRY_CODE, {shouldAcceptName: true}); + + // Then userToInvite should be returned for the plain name + expect(filteredOptions?.userToInvite?.text).toBe('jeff'); + }); + it('should not return any options if search value does not match any personal details', () => { // Given a set of options const options = getValidOptions({reports: OPTIONS.reports, personalDetails: OPTIONS.personalDetails}, {}, nvpDismissedProductTraining);