From 5af0af768288a45b7401e7a31d28e97850f20eba Mon Sep 17 00:00:00 2001 From: Surendar Singh Date: Sun, 20 Oct 2024 11:07:14 +0530 Subject: [PATCH] fix: discord group search for multiple words in same string --- __tests__/groups/group.test.js | 2 +- groups/utils.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/__tests__/groups/group.test.js b/__tests__/groups/group.test.js index 9830f377..158ec006 100644 --- a/__tests__/groups/group.test.js +++ b/__tests__/groups/group.test.js @@ -245,7 +245,7 @@ describe('Discord Groups Page', () => { }); test('Should display only specified groups when name= with different case', async () => { - const groupNames = 'fIrSt,DSA+COdInG'; + const groupNames = 'fIrSt,COdInG'; await page.goto(`${PAGE_URL}/groups?name=${groupNames}`); await page.waitForNetworkIdle(); diff --git a/groups/utils.js b/groups/utils.js index 4dfeff83..bf2b18b6 100644 --- a/groups/utils.js +++ b/groups/utils.js @@ -128,15 +128,21 @@ function removeGroupKeywordFromDiscordRoleName(groupName) { function getDiscordGroupIdsFromSearch(groups, multipleGroupSearch) { if (!multipleGroupSearch) return groups.map((group) => group.id); + const GROUP_SEARCH_SEPARATOR = ','; const searchGroups = multipleGroupSearch .split(GROUP_SEARCH_SEPARATOR) .map((group) => group.trim().toLowerCase()); + const matchGroups = groups.filter((group) => searchGroups.some((searchGroup) => - group.title.toLowerCase().startsWith(searchGroup), + group.title + .toLowerCase() + .split(' ') + .some((word) => word.startsWith(searchGroup)), ), ); + return matchGroups.map((group) => group.id); }