Commit 74816434 authored by JC Brand's avatar JC Brand

Validation error when trying to add an already existing contact

parent be1abdb5
......@@ -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);
......@@ -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(
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment