瀏覽代碼

Validation error when trying to add an already existing contact

JC Brand 6 年之前
父節點
當前提交
7481643453
共有 3 個文件被更改,包括 18 次插入1 次删除
  1. 4 0
      dist/converse.js
  2. 10 1
      spec/controlbox.js
  3. 4 0
      src/converse-rosterview.js

+ 4 - 0
dist/converse.js

@@ -59173,6 +59173,10 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_4__["default"].plugins
           el.textContent = __('You cannot add yourself as a contact');
           u.addClass('d-block', el);
           return false;
+        } else if (_converse.roster.get(Strophe.getBareJidFromJid(jid))) {
+          el.textContent = __('This contact has already been added');
+          u.addClass('d-block', el);
+          return false;
         }
 
         u.removeClass('d-block', el);

+ 10 - 1
spec/controlbox.js

@@ -317,12 +317,16 @@
                   'xhr_user_search_url': 'http://example.org/?' },
                 async function (done, _converse) {
 
+            test_utils.createContacts(_converse, 'all').openControlBox();
             var modal;
             const xhr = {
                 'open': _.noop,
                 'send': function () {
                     const value = modal.el.querySelector('input[name="name"]').value;
-                    if (value === 'dummy') {
+                    if (value === 'existing') {
+                        const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
+                        xhr.responseText = JSON.stringify([{"jid": contact_jid, "fullname": mock.cur_names[0]}]);
+                    } else if (value === 'dummy') {
                         xhr.responseText = JSON.stringify([{"jid": "dummy@localhost", "fullname": "Max Mustermann"}]);
                     } else if (value === 'ambiguous') {
                         xhr.responseText = JSON.stringify([
@@ -375,6 +379,11 @@
             feedback_el = modal.el.querySelector('.invalid-feedback');
             expect(feedback_el.textContent).toBe('You cannot add yourself as a contact');
 
+            input_el.value = 'existing';
+            modal.el.querySelector('button[type="submit"]').click();
+            feedback_el = modal.el.querySelector('.invalid-feedback');
+            expect(feedback_el.textContent).toBe('This contact has already been added');
+
             input_el.value = 'Marty McFly';
             modal.el.querySelector('button[type="submit"]').click();
             expect(sent_stanza.toLocaleString()).toEqual(

+ 4 - 0
src/converse-rosterview.js

@@ -215,6 +215,10 @@ converse.plugins.add('converse-rosterview', {
                     el.textContent = __('You cannot add yourself as a contact')
                     u.addClass('d-block', el);
                     return false;
+                } else if (_converse.roster.get(Strophe.getBareJidFromJid(jid))) {
+                    el.textContent = __('This contact has already been added')
+                    u.addClass('d-block', el);
+                    return false;
                 }
                 u.removeClass('d-block', el);
                 return true;