From 692953e860cdb6d21537fcaa24919b49e2f05b85 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Wed, 13 Mar 2019 09:37:56 -0400 Subject: [PATCH] MM-14461: make @-mentions (and searches) case insensitive (#2641) --- app/selectors/autocomplete.js | 2 +- app/selectors/autocomplete.test.js | 59 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 app/selectors/autocomplete.test.js diff --git a/app/selectors/autocomplete.js b/app/selectors/autocomplete.js index 54c1bd978..4c4bb8baf 100644 --- a/app/selectors/autocomplete.js +++ b/app/selectors/autocomplete.js @@ -27,7 +27,7 @@ export const getMatchTermForAtMention = (() => { lastValue = value; lastIsSearch = isSearch; if (match) { - lastMatchTerm = isSearch ? match[1] : match[2]; + lastMatchTerm = (isSearch ? match[1] : match[2]).toLowerCase(); } else { lastMatchTerm = null; } diff --git a/app/selectors/autocomplete.test.js b/app/selectors/autocomplete.test.js new file mode 100644 index 000000000..ad639159b --- /dev/null +++ b/app/selectors/autocomplete.test.js @@ -0,0 +1,59 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import assert from 'assert'; + +import { + getMatchTermForAtMention, +} from 'app/selectors/autocomplete'; + +/* eslint-disable max-nested-callbacks */ + +describe('Selectors.Autocomplete', () => { + describe('getMatchTermForAtMention', () => { + describe('match non-search at mentions', () => { + const testCases = [ + ['@', ''], + ['@a', 'a'], + ['@match', 'match'], + ['@Username', 'username'], + ['@USERNAME', 'username'], + ['not a match', null], + ]; + + testCases.forEach((testCase) => { + it(testCase[0], () => { + const value = testCase[0]; + const isSearch = false; + const expected = testCase[1]; + const actual = getMatchTermForAtMention(value, isSearch); + + assert.equal(expected, actual); + }); + }); + }); + + describe('match search at mentions', () => { + const testCases = [ + ['from:', ''], + ['from:a', 'a'], + ['from:match', 'match'], + ['from:not a match', null], + ['from:Username', 'username'], + ['from:USERNAME', 'username'], + ['from: space', 'space'], + ]; + + testCases.forEach((testCase) => { + it(testCase[0], () => { + const value = testCase[0]; + const isSearch = true; + const expected = testCase[1]; + const actual = getMatchTermForAtMention(value, isSearch); + + assert.equal(expected, actual); + }); + }); + }); + }); +});