2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
2019-03-01 10:53:12 +01:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-08-18 11:28:51 +02:00
|
|
|
const _ = converse.env._,
|
|
|
|
$msg = converse.env.$msg,
|
|
|
|
u = converse.env.utils,
|
2019-05-20 12:38:33 +02:00
|
|
|
Strophe = converse.env.Strophe,
|
|
|
|
sizzle = converse.env.sizzle;
|
2014-07-20 20:45:59 +02:00
|
|
|
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
describe("The Controlbox", function () {
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be opened by clicking a DOM element with class 'toggle-controlbox'",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
// This spec will only pass if the controlbox is not currently
|
|
|
|
// open yet.
|
2019-03-01 10:53:12 +01:00
|
|
|
let el = document.querySelector("div#controlbox");
|
|
|
|
expect(_.isElement(el)).toBe(true);
|
|
|
|
expect(u.isVisible(el)).toBe(false);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.controlboxtoggle, 'onClick').and.callThrough();
|
|
|
|
spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough();
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2017-04-05 11:01:31 +02:00
|
|
|
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
|
|
|
|
_converse.controlboxtoggle.delegateEvents();
|
2018-01-03 20:02:05 +01:00
|
|
|
document.querySelector('.toggle-controlbox').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.controlboxtoggle.onClick).toHaveBeenCalled();
|
|
|
|
expect(_converse.controlboxtoggle.showControlBox).toHaveBeenCalled();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
|
2019-03-01 10:53:12 +01:00
|
|
|
el = document.querySelector("div#controlbox");
|
|
|
|
expect(u.isVisible(el)).toBe(true);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
describe("The \"Contacts\" section", function () {
|
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
it("can be used to add contact and it checks for case-sensivity",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2018-11-26 12:58:06 +01:00
|
|
|
async function (done, _converse) {
|
2018-03-26 15:38:03 +02:00
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-03-26 15:38:03 +02:00
|
|
|
spyOn(_converse.rosterview, 'update').and.callThrough();
|
|
|
|
test_utils.openControlBox();
|
|
|
|
// Adding two contacts one with Capital initials and one with small initials of same JID (Case sensitive check)
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2018-03-26 15:38:03 +02:00
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
|
|
|
});
|
|
|
|
_converse.roster.create({
|
2019-06-03 07:58:51 +02:00
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.') + '@montague.lit',
|
2018-03-26 15:38:03 +02:00
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
|
|
|
});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _.filter(_converse.rosterview.el.querySelectorAll('.roster-group li'), u.isVisible).length, 700);
|
2018-11-26 12:58:06 +01:00
|
|
|
// Checking that only one entry is created because both JID is same (Case sensitive check)
|
2019-03-01 10:53:12 +01:00
|
|
|
expect(_.filter(_converse.rosterview.el.querySelectorAll('li'), u.isVisible).length).toBe(1);
|
2018-11-26 12:58:06 +01:00
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
|
|
|
done();
|
2018-03-26 15:38:03 +02:00
|
|
|
}));
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
it("shows the number of unread mentions received",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-18 15:24:34 +01:00
|
|
|
async function (done, _converse) {
|
2018-03-11 13:56:53 +01:00
|
|
|
|
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
2019-03-29 21:10:45 +01:00
|
|
|
_converse.api.trigger('rosterContactsFetched');
|
2018-03-11 13:56:53 +01:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-18 15:24:34 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length);
|
2018-11-18 15:24:34 +01:00
|
|
|
const chatview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
|
|
|
|
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
|
|
|
|
expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
|
|
|
|
|
|
|
|
let msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('hello').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll(".msgs-indicator").length);
|
2018-11-18 15:24:34 +01:00
|
|
|
spyOn(chatview.model, 'incrementUnreadMsgCounter').and.callThrough();
|
|
|
|
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1');
|
|
|
|
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1');
|
|
|
|
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('hello again').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatview.model.incrementUnreadMsgCounter.calls.count());
|
2018-11-18 15:24:34 +01:00
|
|
|
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('2');
|
|
|
|
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('2');
|
|
|
|
chatview.model.set({'minimized': false});
|
|
|
|
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
|
|
|
|
expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
|
|
|
|
done();
|
2018-03-11 13:56:53 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The Status Widget", function () {
|
2014-03-04 14:48:16 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows the user's chat status, which is online by default",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.xmppstatusview;
|
2019-03-01 10:53:12 +01:00
|
|
|
expect(u.hasClass('online', view.el.querySelector('.xmpp-status span:first-child'))).toBe(true);
|
2018-03-17 18:13:51 +01:00
|
|
|
expect(view.el.querySelector('.xmpp-status span.online').textContent.trim()).toBe('I am online');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to set the current user's chat status",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-26 12:58:06 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2018-03-17 18:13:51 +01:00
|
|
|
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.change-status').click()
|
|
|
|
var modal = _converse.xmppstatusview.status_modal;
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2018-11-26 12:58:06 +01:00
|
|
|
const view = _converse.xmppstatusview;
|
|
|
|
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
|
|
|
|
modal.el.querySelector('[type="submit"]').click();
|
2019-06-13 14:17:51 +02:00
|
|
|
const last_stanza = _converse.connection.sent_stanzas.pop();
|
|
|
|
expect(Strophe.serialize(last_stanza)).toBe(
|
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<show>dnd</show>`+
|
|
|
|
`<priority>0</priority>`+
|
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="Hxbsr5fazs62i+O0GxIXf2OEDNs=" xmlns="http://jabber.org/protocol/caps"/>`+
|
|
|
|
`</presence>`);
|
2019-03-01 10:53:12 +01:00
|
|
|
const first_child = view.el.querySelector('.xmpp-status span:first-child');
|
|
|
|
expect(u.hasClass('online', first_child)).toBe(false);
|
|
|
|
expect(u.hasClass('dnd', first_child)).toBe(true);
|
2018-11-26 12:58:06 +01:00
|
|
|
expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe('I am busy');
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to set a custom status message",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-26 12:58:06 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2018-03-17 18:13:51 +01:00
|
|
|
|
2018-11-26 12:58:06 +01:00
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
2018-03-17 18:13:51 +01:00
|
|
|
cbview.el.querySelector('.change-status').click()
|
2018-11-26 12:58:06 +01:00
|
|
|
const modal = _converse.xmppstatusview.status_modal;
|
2018-03-17 18:13:51 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2018-11-26 12:58:06 +01:00
|
|
|
const view = _converse.xmppstatusview;
|
|
|
|
const msg = 'I am happy';
|
|
|
|
modal.el.querySelector('input[name="status_message"]').value = msg;
|
|
|
|
modal.el.querySelector('[type="submit"]').click();
|
2019-06-13 14:17:51 +02:00
|
|
|
const last_stanza = _converse.connection.sent_stanzas.pop();
|
|
|
|
expect(Strophe.serialize(last_stanza)).toBe(
|
|
|
|
`<presence xmlns="jabber:client">`+
|
|
|
|
`<status>I am happy</status>`+
|
|
|
|
`<priority>0</priority>`+
|
|
|
|
`<c hash="sha-1" node="https://conversejs.org" ver="Hxbsr5fazs62i+O0GxIXf2OEDNs=" xmlns="http://jabber.org/protocol/caps"/>`+
|
|
|
|
`</presence>`);
|
2018-03-17 18:13:51 +01:00
|
|
|
|
2019-03-01 10:53:12 +01:00
|
|
|
const first_child = view.el.querySelector('.xmpp-status span:first-child');
|
|
|
|
expect(u.hasClass('online', first_child)).toBe(true);
|
2018-11-26 12:58:06 +01:00
|
|
|
expect(view.el.querySelector('.xmpp-status span:first-child').textContent.trim()).toBe(msg);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The 'Add Contact' widget", function () {
|
|
|
|
|
2018-03-18 04:35:34 +01:00
|
|
|
it("opens up an add modal when you click on it",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-26 12:58:06 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2018-03-26 15:38:03 +02:00
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
|
|
|
|
2018-11-26 12:58:06 +01:00
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
2018-03-18 04:35:34 +01:00
|
|
|
cbview.el.querySelector('.add-contact').click()
|
2018-11-26 12:58:06 +01:00
|
|
|
const modal = _converse.rosterview.add_contact_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2018-11-26 12:58:06 +01:00
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2018-03-18 04:35:34 +01:00
|
|
|
});
|
2018-11-26 12:58:06 +01:00
|
|
|
|
|
|
|
expect(!_.isNull(modal.el.querySelector('form.add-xmpp-contact'))).toBeTruthy();
|
|
|
|
const input_jid = modal.el.querySelector('input[name="jid"]');
|
|
|
|
const input_name = modal.el.querySelector('input[name="name"]');
|
|
|
|
input_jid.value = 'someone@';
|
|
|
|
const evt = new Event('input');
|
|
|
|
input_jid.dispatchEvent(evt);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(modal.el.querySelector('.suggestion-box li').textContent).toBe('someone@montague.lit');
|
|
|
|
input_jid.value = 'someone@montague.lit';
|
2018-11-26 12:58:06 +01:00
|
|
|
input_name.value = 'Someone';
|
|
|
|
modal.el.querySelector('button[type="submit"]').click();
|
|
|
|
expect(sent_stanza.toLocaleString()).toEqual(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
2019-06-03 07:58:51 +02:00
|
|
|
`<query xmlns="jabber:iq:roster"><item jid="someone@montague.lit" name="Someone"/></query>`+
|
2018-11-26 12:58:06 +01:00
|
|
|
`</iq>`);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-03-08 15:33:00 +01:00
|
|
|
|
2019-03-28 14:34:12 +01:00
|
|
|
it("can be configured to not provide search suggestions",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {'autocomplete_add_contact': false},
|
2019-03-28 14:34:12 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.openControlBox();
|
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.add-contact').click()
|
|
|
|
const modal = _converse.rosterview.add_contact_modal;
|
|
|
|
expect(modal.jid_auto_complete).toBe(undefined);
|
|
|
|
expect(modal.name_auto_complete).toBe(undefined);
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2019-03-28 14:34:12 +01:00
|
|
|
expect(!_.isNull(modal.el.querySelector('form.add-xmpp-contact'))).toBeTruthy();
|
|
|
|
const input_jid = modal.el.querySelector('input[name="jid"]');
|
2019-06-03 07:58:51 +02:00
|
|
|
input_jid.value = 'someone@montague.lit';
|
2019-03-28 14:34:12 +01:00
|
|
|
modal.el.querySelector('button[type="submit"]').click();
|
2019-05-20 12:38:33 +02:00
|
|
|
|
|
|
|
const IQ_stanzas = _converse.connection.IQ_stanzas;
|
2019-07-11 22:50:30 +02:00
|
|
|
const sent_stanza = await u.waitUntil(
|
2019-05-20 12:38:33 +02:00
|
|
|
() => IQ_stanzas.filter(s => sizzle(`query[xmlns="${Strophe.NS.ROSTER}"]`, s).length).pop()
|
|
|
|
);
|
|
|
|
expect(Strophe.serialize(sent_stanza)).toEqual(
|
|
|
|
`<iq id="${sent_stanza.getAttribute('id')}" type="set" xmlns="jabber:client">`+
|
2019-06-03 07:58:51 +02:00
|
|
|
`<query xmlns="jabber:iq:roster"><item jid="someone@montague.lit"/></query>`+
|
2019-05-20 12:38:33 +02:00
|
|
|
`</iq>`
|
|
|
|
);
|
2019-03-28 14:34:12 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2018-03-26 15:38:03 +02:00
|
|
|
|
2019-05-20 12:38:33 +02:00
|
|
|
it("integrates with xhr_user_search_url to search for contacts",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'],
|
2019-03-28 14:34:12 +01:00
|
|
|
{ 'xhr_user_search_url': 'http://example.org/?' },
|
2018-11-26 12:58:06 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-03-01 10:53:12 +01:00
|
|
|
const xhr = {
|
2019-08-05 11:14:49 +02:00
|
|
|
'open': function open () {},
|
2018-03-26 15:38:03 +02:00
|
|
|
'send': function () {
|
|
|
|
xhr.responseText = JSON.stringify([
|
|
|
|
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
|
|
|
|
{"jid": "doc@brown.com", "fullname": "Doc Brown"}
|
|
|
|
]);
|
|
|
|
xhr.onload();
|
|
|
|
}
|
|
|
|
};
|
2018-04-17 15:17:39 +02:00
|
|
|
const XMLHttpRequestBackup = window.XMLHttpRequest;
|
2018-03-26 15:38:03 +02:00
|
|
|
window.XMLHttpRequest = jasmine.createSpy('XMLHttpRequest');
|
2019-03-01 10:53:12 +01:00
|
|
|
XMLHttpRequest.and.callFake(() => xhr);
|
2018-03-26 15:38:03 +02:00
|
|
|
|
2019-03-01 10:53:12 +01:00
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
2018-03-26 15:38:03 +02:00
|
|
|
cbview.el.querySelector('.add-contact').click()
|
2019-03-01 10:53:12 +01:00
|
|
|
const modal = _converse.rosterview.add_contact_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2019-03-28 10:47:14 +01:00
|
|
|
|
|
|
|
// We only have autocomplete for the name input
|
|
|
|
expect(modal.jid_auto_complete).toBe(undefined);
|
|
|
|
expect(modal.name_auto_complete instanceof _converse.AutoComplete).toBe(true);
|
|
|
|
|
2019-03-01 10:53:12 +01:00
|
|
|
const input_el = modal.el.querySelector('input[name="name"]');
|
2018-11-26 12:58:06 +01:00
|
|
|
input_el.value = 'marty';
|
2019-03-28 10:47:14 +01:00
|
|
|
input_el.dispatchEvent(new Event('input'));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => modal.el.querySelector('.suggestion-box li'), 1000);
|
2019-03-01 10:53:12 +01:00
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
let sent_stanza, IQ_id;
|
2018-11-26 12:58:06 +01:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
2017-03-08 15:33:00 +01:00
|
|
|
});
|
2019-03-28 10:47:14 +01:00
|
|
|
expect(modal.el.querySelectorAll('.suggestion-box li').length).toBe(1);
|
|
|
|
const suggestion = modal.el.querySelector('.suggestion-box li');
|
2018-11-26 12:58:06 +01:00
|
|
|
expect(suggestion.textContent).toBe('Marty McFly');
|
|
|
|
|
2019-03-28 10:47:14 +01:00
|
|
|
// Mock selection
|
|
|
|
modal.name_auto_complete.select(suggestion);
|
|
|
|
|
2018-11-26 12:58:06 +01:00
|
|
|
expect(input_el.value).toBe('Marty McFly');
|
|
|
|
expect(modal.el.querySelector('input[name="jid"]').value).toBe('marty@mcfly.net');
|
|
|
|
modal.el.querySelector('button[type="submit"]').click();
|
|
|
|
expect(sent_stanza.toLocaleString()).toEqual(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query xmlns="jabber:iq:roster"><item jid="marty@mcfly.net" name="Marty McFly"/></query>`+
|
|
|
|
`</iq>`);
|
|
|
|
window.XMLHttpRequest = XMLHttpRequestBackup;
|
|
|
|
done();
|
2017-03-08 15:33:00 +01:00
|
|
|
}));
|
2019-03-28 14:34:12 +01:00
|
|
|
|
|
|
|
it("can be configured to not provide search suggestions for XHR search results",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'],
|
2019-03-28 14:34:12 +01:00
|
|
|
{ 'autocomplete_add_contact': false,
|
|
|
|
'xhr_user_search_url': 'http://example.org/?' },
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-03-28 15:54:47 +01:00
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
2019-03-28 14:34:12 +01:00
|
|
|
var modal;
|
|
|
|
const xhr = {
|
2019-08-05 11:14:49 +02:00
|
|
|
'open': function open () {},
|
2019-03-28 14:34:12 +01:00
|
|
|
'send': function () {
|
|
|
|
const value = modal.el.querySelector('input[name="name"]').value;
|
2019-03-28 15:54:47 +01:00
|
|
|
if (value === 'existing') {
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-03-28 15:54:47 +01:00
|
|
|
xhr.responseText = JSON.stringify([{"jid": contact_jid, "fullname": mock.cur_names[0]}]);
|
2019-06-03 07:58:51 +02:00
|
|
|
} else if (value === 'romeo') {
|
|
|
|
xhr.responseText = JSON.stringify([{"jid": "romeo@montague.lit", "fullname": "Romeo Montague"}]);
|
2019-03-28 15:32:50 +01:00
|
|
|
} else if (value === 'ambiguous') {
|
2019-03-28 14:34:12 +01:00
|
|
|
xhr.responseText = JSON.stringify([
|
|
|
|
{"jid": "marty@mcfly.net", "fullname": "Marty McFly"},
|
|
|
|
{"jid": "doc@brown.com", "fullname": "Doc Brown"}
|
|
|
|
]);
|
|
|
|
} else if (value === 'insufficient') {
|
|
|
|
xhr.responseText = JSON.stringify([]);
|
|
|
|
} else {
|
|
|
|
xhr.responseText = JSON.stringify([{"jid": "marty@mcfly.net", "fullname": "Marty McFly"}]);
|
|
|
|
}
|
|
|
|
xhr.onload();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const XMLHttpRequestBackup = window.XMLHttpRequest;
|
|
|
|
window.XMLHttpRequest = jasmine.createSpy('XMLHttpRequest');
|
|
|
|
XMLHttpRequest.and.callFake(() => xhr);
|
|
|
|
|
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.add-contact').click()
|
|
|
|
modal = _converse.rosterview.add_contact_modal;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(modal.el), 1000);
|
2019-03-28 14:34:12 +01:00
|
|
|
|
|
|
|
expect(modal.jid_auto_complete).toBe(undefined);
|
|
|
|
expect(modal.name_auto_complete).toBe(undefined);
|
|
|
|
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
|
|
|
|
const input_el = modal.el.querySelector('input[name="name"]');
|
|
|
|
input_el.value = 'ambiguous';
|
|
|
|
modal.el.querySelector('button[type="submit"]').click();
|
2019-03-28 15:32:50 +01:00
|
|
|
let feedback_el = modal.el.querySelector('.invalid-feedback');
|
2019-03-28 14:34:12 +01:00
|
|
|
expect(feedback_el.textContent).toBe('Sorry, could not find a contact with that name');
|
|
|
|
feedback_el.textContent = '';
|
|
|
|
|
|
|
|
input_el.value = 'insufficient';
|
|
|
|
modal.el.querySelector('button[type="submit"]').click();
|
2019-03-28 15:32:50 +01:00
|
|
|
feedback_el = modal.el.querySelector('.invalid-feedback');
|
2019-03-28 14:34:12 +01:00
|
|
|
expect(feedback_el.textContent).toBe('Sorry, could not find a contact with that name');
|
2019-03-28 15:32:50 +01:00
|
|
|
feedback_el.textContent = '';
|
|
|
|
|
2019-03-28 15:54:47 +01:00
|
|
|
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');
|
|
|
|
|
2019-03-28 14:34:12 +01:00
|
|
|
input_el.value = 'Marty McFly';
|
|
|
|
modal.el.querySelector('button[type="submit"]').click();
|
|
|
|
expect(sent_stanza.toLocaleString()).toEqual(
|
|
|
|
`<iq id="${IQ_id}" type="set" xmlns="jabber:client">`+
|
|
|
|
`<query xmlns="jabber:iq:roster"><item jid="marty@mcfly.net" name="Marty McFly"/></query>`+
|
|
|
|
`</iq>`);
|
|
|
|
window.XMLHttpRequest = XMLHttpRequestBackup;
|
|
|
|
done();
|
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|