Validation error when trying to add an already existing contact

This commit is contained in:
JC Brand 2019-03-28 15:54:47 +01:00
parent be1abdb5ff
commit 7481643453
3 changed files with 18 additions and 1 deletions

4
dist/converse.js vendored
View File

@ -59173,6 +59173,10 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_4__["default"].plugins
el.textContent = __('You cannot add yourself as a contact'); el.textContent = __('You cannot add yourself as a contact');
u.addClass('d-block', el); u.addClass('d-block', el);
return false; 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); u.removeClass('d-block', el);

View File

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

View File

@ -215,6 +215,10 @@ converse.plugins.add('converse-rosterview', {
el.textContent = __('You cannot add yourself as a contact') el.textContent = __('You cannot add yourself as a contact')
u.addClass('d-block', el); u.addClass('d-block', el);
return false; 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); u.removeClass('d-block', el);
return true; return true;