2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
2018-01-04 12:41:03 +01:00
|
|
|
define(["jquery", "jasmine", "mock", "converse-core", "test-utils"], factory);
|
2017-07-11 10:41:11 +02:00
|
|
|
} (this, function ($, jasmine, mock, converse, test_utils) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var _ = converse.env._;
|
|
|
|
var $pres = converse.env.$pres;
|
2017-06-05 21:42:25 +02:00
|
|
|
var $msg = converse.env.$msg;
|
2016-12-20 10:30:20 +01:00
|
|
|
var $iq = converse.env.$iq;
|
2017-12-17 16:03:28 +01:00
|
|
|
var u = converse.env.utils;
|
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'",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
// This spec will only pass if the controlbox is not currently
|
|
|
|
// open yet.
|
|
|
|
expect($("div#controlbox").is(':visible')).toBe(false);
|
|
|
|
spyOn(_converse.controlboxtoggle, 'onClick').and.callThrough();
|
|
|
|
spyOn(_converse.controlboxtoggle, 'showControlBox').and.callThrough();
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
// 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();
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object));
|
|
|
|
expect($("div#controlbox").is(':visible')).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 () {
|
|
|
|
|
|
|
|
it("shows the number of unread mentions received",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.createContacts(_converse, 'all').openControlBox();
|
|
|
|
|
|
|
|
var contacts_panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
|
2018-03-17 18:13:51 +01:00
|
|
|
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
|
|
|
|
expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
|
|
|
|
|
2018-03-11 13:56:53 +01:00
|
|
|
var 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);
|
2018-03-17 18:13:51 +01:00
|
|
|
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('1');
|
|
|
|
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('1');
|
2018-03-11 13:56:53 +01:00
|
|
|
|
|
|
|
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);
|
2018-03-17 18:13:51 +01:00
|
|
|
expect(_converse.chatboxviews.el.querySelector('.restore-chat .message-count').textContent).toBe('2');
|
|
|
|
expect(_converse.rosterview.el.querySelector('.msgs-indicator').textContent).toBe('2');
|
2018-03-11 13:56:53 +01:00
|
|
|
|
|
|
|
chatview.model.set({'minimized': false});
|
2018-03-17 18:13:51 +01:00
|
|
|
expect(_.isNull(_converse.chatboxviews.el.querySelector('.restore-chat .message-count'))).toBeTruthy();
|
|
|
|
expect(_.isNull(_converse.rosterview.el.querySelector('.msgs-indicator'))).toBeTruthy();
|
2018-03-11 13:56:53 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
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",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
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;
|
2018-03-17 18:13:51 +01:00
|
|
|
expect($(view.el).find('.xmpp-status span:first-child').hasClass('online')).toBe(true);
|
|
|
|
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",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return u.isVisible(modal.el);
|
|
|
|
}, 1000).then(function () {
|
|
|
|
var view = _converse.xmppstatusview;
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
modal.el.querySelector('label[for="radio-busy"]').click(); // Change status to "dnd"
|
|
|
|
modal.el.querySelector('[type="submit"]').click();
|
|
|
|
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('statusChanged', 'dnd');
|
|
|
|
expect($(view.el).find('.xmpp-status span:first-child').hasClass('online')).toBe(false);
|
|
|
|
expect($(view.el).find('.xmpp-status span:first-child').hasClass('dnd')).toBe(true);
|
|
|
|
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",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return u.isVisible(modal.el);
|
|
|
|
}, 1000).then(function () {
|
|
|
|
var view = _converse.xmppstatusview;
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
|
|
|
|
var msg = 'I am happy';
|
|
|
|
modal.el.querySelector('input[name="status_message"]').value = msg;
|
|
|
|
modal.el.querySelector('[type="submit"]').click();
|
|
|
|
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('statusMessageChanged', msg);
|
|
|
|
expect($(view.el).find('.xmpp-status span:first-child').hasClass('online')).toBe(true);
|
|
|
|
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",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var panel = _converse.chatboxviews.get('controlbox').contactspanel;
|
2018-03-18 04:35:34 +01:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
cbview.el.querySelector('.add-contact').click()
|
|
|
|
var modal = _converse.rosterview.add_contact_modal;
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return u.isVisible(modal.el);
|
|
|
|
}, 1000).then(function () {
|
|
|
|
expect(!_.isNull(modal.el.querySelector('form.add-xmpp-contact'))).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-03-08 15:33:00 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be used to add contact and it checks for case-sensivity",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-03-08 15:33:00 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-04-05 11:01:31 +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({
|
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
2017-03-08 15:33:00 +01:00
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.roster.create({
|
|
|
|
jid: mock.pend_names[0].replace(/ /g,'.') + '@localhost',
|
|
|
|
subscription: 'none',
|
|
|
|
ask: 'subscribe',
|
|
|
|
fullname: mock.pend_names[0]
|
|
|
|
});
|
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group li:visible').length;
|
2017-12-20 20:29:57 +01:00
|
|
|
}, 700).then(function () {
|
2017-03-08 15:33:00 +01:00
|
|
|
// Checking that only one entry is created because both JID is same (Case sensitive check)
|
2018-01-03 20:02:05 +01:00
|
|
|
expect($(_converse.rosterview.el).find('li:visible').length).toBe(1);
|
2017-03-08 15:33:00 +01:00
|
|
|
expect(_converse.rosterview.update).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2017-03-08 15:33:00 +01:00
|
|
|
});
|
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|