diff --git a/app/containers/MessageBox/getMentionRegexp.test.js b/app/containers/MessageBox/getMentionRegexp.test.js new file mode 100644 index 000000000..8923ae100 --- /dev/null +++ b/app/containers/MessageBox/getMentionRegexp.test.js @@ -0,0 +1,56 @@ +import getMentionRegexp from './getMentionRegexp'; + +const regexp = getMentionRegexp(); + +describe('getMentionRegexpUser', function () { + test('removing query text on user suggestion autocomplete (latin)', () => { + const message = 'Hey @test123'; + expect(message.replace(regexp, '')).toBe('Hey @'); + }); + + test('removing query text on user suggestion autocomplete (arabic)', () => { + const message = 'Hey @اختبار123'; + expect(message.replace(regexp, '')).toBe('Hey @'); + }); + + test('removing query text on user suggestion autocomplete (russian)', () => { + const message = 'Hey @тест123'; + expect(message.replace(regexp, '')).toBe('Hey @'); + }); + + test('removing query text on user suggestion autocomplete (chinese trad)', () => { + const message = 'Hey @測試123'; + expect(message.replace(regexp, '')).toBe('Hey @'); + }); + + test('removing query text on user suggestion autocomplete (japanese)', () => { + const message = 'Hey @テスト123'; + expect(message.replace(regexp, '')).toBe('Hey @'); + }); + + test('removing query text on user suggestion autocomplete (special characters in query)', () => { + const message = "Hey @'=test123"; + expect(message.replace(regexp, '')).toBe('Hey @'); + }); +}); + +describe('getMentionRegexpEmoji', function () { + test('removing query text on emoji suggestion autocomplete ', () => { + const message = 'Hey :smiley'; + expect(message.replace(regexp, '')).toBe('Hey :'); + }); +}); + +describe('getMentionRegexpCommand', function () { + test('removing query text on emoji suggestion autocomplete ', () => { + const message = '/archive'; + expect(message.replace(regexp, '')).toBe('/'); + }); +}); + +describe('getMentionRegexpRoom', function () { + test('removing query text on emoji suggestion autocomplete ', () => { + const message = 'Check #general'; + expect(message.replace(regexp, '')).toBe('Check #'); + }); +}); diff --git a/app/containers/MessageBox/getMentionRegexp.ts b/app/containers/MessageBox/getMentionRegexp.ts new file mode 100644 index 000000000..ec8ea5d14 --- /dev/null +++ b/app/containers/MessageBox/getMentionRegexp.ts @@ -0,0 +1,4 @@ +// Match query string from the message to replace it with the suggestion +const getMentionRegexp = (): any => /[^@:#/!]*$/; + +export default getMentionRegexp; diff --git a/app/containers/MessageBox/index.tsx b/app/containers/MessageBox/index.tsx index 073d04b74..1b94e80d9 100644 --- a/app/containers/MessageBox/index.tsx +++ b/app/containers/MessageBox/index.tsx @@ -31,6 +31,7 @@ import { isAndroid, isTablet } from '../../utils/deviceInfo'; import { canUploadFile } from '../../utils/media'; import EventEmiter from '../../utils/events'; import { KEY_COMMAND, handleCommandShowUpload, handleCommandSubmit, handleCommandTyping } from '../../commands'; +import getMentionRegexp from './getMentionRegexp'; import Mentions from './Mentions'; import MessageboxContext from './Context'; import { @@ -489,7 +490,7 @@ class MessageBox extends Component { const msg = this.text; const { start, end } = this.selection; const cursor = Math.max(start, end); - const regexp = /([a-z0-9._-]+)$/im; + const regexp = getMentionRegexp(); let result = msg.substr(0, cursor).replace(regexp, ''); // Remove the ! after select the canned response if (trackingType === MENTIONS_TRACKING_TYPE_CANNED) {