From 4cf316fcd39dbb654bb07d80b0dfa9f8194c571d Mon Sep 17 00:00:00 2001
From: Saturnino Abril <saturnino.abril@gmail.com>
Date: Sat, 12 Aug 2017 02:01:11 +0800
Subject: [PLT-7342] Add function and tests to specifically determine @all &
 @channel (#7181)

* add function and tests to specifically determine @all & @channel

* uodate per comments - regex and tests
---
 webapp/tests/utils/post_utils.test.jsx | 97 ++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 webapp/tests/utils/post_utils.test.jsx

(limited to 'webapp/tests/utils/post_utils.test.jsx')

diff --git a/webapp/tests/utils/post_utils.test.jsx b/webapp/tests/utils/post_utils.test.jsx
new file mode 100644
index 000000000..0546d5bea
--- /dev/null
+++ b/webapp/tests/utils/post_utils.test.jsx
@@ -0,0 +1,97 @@
+import * as PostUtils from 'utils/post_utils.jsx';
+
+describe('PostUtils.containsAtMention', function() {
+    test('should return correct @all (same for @channel)', function() {
+        for (const data of [
+            {
+                text: undefined,    //eslint-disable-line no-undefined
+                key: undefined,     //eslint-disable-line no-undefined
+                result: false
+            },
+            {
+                text: '',
+                key: '',
+                result: false
+            },
+            {
+                text: 'all',
+                key: '@all',
+                result: false
+            },
+            {
+                text: '@allison',
+                key: '@all',
+                result: false
+            },
+            {
+                text: '@ALLISON',
+                key: '@all',
+                result: false
+            },
+            {
+                text: '@all123',
+                key: '@all',
+                result: false
+            },
+            {
+                text: '123@all',
+                key: '@all',
+                result: false
+            },
+            {
+                text: 'hey@all',
+                key: '@all',
+                result: false
+            },
+            {
+                text: 'hey@all.com',
+                key: '@all',
+                result: false
+            },
+            {
+                text: '@all',
+                key: '@all',
+                result: true
+            },
+            {
+                text: '@ALL',
+                key: '@all',
+                result: true
+            },
+            {
+                text: '@all hey',
+                key: '@all',
+                result: true
+            },
+            {
+                text: 'hey @all',
+                key: '@all',
+                result: true
+            },
+            {
+                text: 'HEY @ALL',
+                key: '@all',
+                result: true
+            },
+            {
+                text: 'hey @all!',
+                key: '@all',
+                result: true
+            },
+            {
+                text: 'hey @all:+1:',
+                key: '@all',
+                result: true
+            },
+            {
+                text: 'hey @ALL:+1:',
+                key: '@all',
+                result: true
+            }
+        ]) {
+            const containsAtMention = PostUtils.containsAtMention(data.text, data.key);
+
+            expect(containsAtMention).toEqual(data.result);
+        }
+    });
+});
-- 
cgit v1.2.3-1-g7c22

