2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2016-03-28 12:49:52 +02:00
|
|
|
"utils",
|
2016-11-30 13:18:58 +01:00
|
|
|
"converse-api",
|
2013-11-02 12:37:38 +01:00
|
|
|
"mock",
|
2014-08-08 22:06:01 +02:00
|
|
|
"test_utils"
|
2016-03-28 12:49:52 +02:00
|
|
|
], factory);
|
2016-12-20 10:30:20 +01:00
|
|
|
} (this, function (utils, converse, mock, test_utils) {
|
2016-06-23 08:55:25 +02:00
|
|
|
"use strict";
|
2016-12-20 10:30:20 +01:00
|
|
|
var _ = converse.env._;
|
|
|
|
var $ = converse.env.jQuery;
|
|
|
|
var $msg = converse.env.$msg;
|
|
|
|
var Strophe = converse.env.Strophe;
|
|
|
|
var moment = converse.env.moment;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
return describe("Chatboxes", function() {
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Chatbox", function () {
|
2014-01-19 06:02:18 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is created when you click on a roster item", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2015-10-25 18:49:35 +01:00
|
|
|
var i, $el, jid, chatboxview;
|
2013-11-03 10:38:48 +01:00
|
|
|
// openControlBox was called earlier, so the controlbox is
|
2013-11-02 12:37:38 +01:00
|
|
|
// visible, but no other chat boxes have been created.
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
2014-06-01 16:26:51 +02:00
|
|
|
expect($("#conversejs .chatbox").length).toBe(1); // Controlbox is open
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var online_contacts = _converse.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact').find('a.open-chat');
|
2013-11-02 12:37:38 +01:00
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
$el = $(online_contacts[i]);
|
2014-06-30 20:26:45 +02:00
|
|
|
jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
|
2013-11-02 12:37:38 +01:00
|
|
|
$el.click();
|
2016-12-20 10:30:20 +01:00
|
|
|
chatboxview = _converse.chatboxviews.get(jid);
|
|
|
|
expect(_converse.chatboxes.length).toEqual(i+2);
|
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
2014-06-01 16:26:51 +02:00
|
|
|
// Check that new chat boxes are created to the left of the
|
|
|
|
// controlbox (but to the right of all existing chat boxes)
|
|
|
|
expect($("#conversejs .chatbox").length).toBe(i+2);
|
|
|
|
expect($("#conversejs .chatbox")[1].id).toBe(chatboxview.model.get('box_id'));
|
2013-11-02 12:37:38 +01:00
|
|
|
}
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be trimmed to conserve space", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2015-10-25 18:49:35 +01:00
|
|
|
var i, $el, jid, chatbox, chatboxview, trimmedview;
|
2014-06-01 17:57:03 +02:00
|
|
|
// openControlBox was called earlier, so the controlbox is
|
|
|
|
// visible, but no other chat boxes have been created.
|
2016-12-20 10:30:20 +01:00
|
|
|
var trimmed_chatboxes = _converse.minimized_chats;
|
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
2014-06-16 00:03:34 +02:00
|
|
|
spyOn(trimmed_chatboxes, 'addChat').andCallThrough();
|
|
|
|
spyOn(trimmed_chatboxes, 'removeChat').andCallThrough();
|
2014-06-01 17:57:03 +02:00
|
|
|
expect($("#conversejs .chatbox").length).toBe(1); // Controlbox is open
|
|
|
|
|
2014-06-01 18:16:32 +02:00
|
|
|
// Test that they can be trimmed
|
2015-10-07 10:57:11 +02:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2014-10-27 23:06:11 +01:00
|
|
|
waits(50);
|
2015-10-07 10:57:11 +02:00
|
|
|
runs(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
// Test that they can be maximized again
|
2016-12-20 10:30:20 +01:00
|
|
|
var online_contacts = _converse.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact').find('a.open-chat');
|
2014-10-27 23:06:11 +01:00
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
$el = $(online_contacts[i]);
|
|
|
|
jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
$el.click();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
chatboxview = _converse.chatboxviews.get(jid);
|
2016-03-09 12:16:15 +01:00
|
|
|
spyOn(chatboxview, 'minimize').andCallThrough();
|
2014-10-27 23:06:11 +01:00
|
|
|
chatboxview.model.set({'minimized': true});
|
|
|
|
expect(trimmed_chatboxes.addChat).toHaveBeenCalled();
|
2016-03-09 12:16:15 +01:00
|
|
|
expect(chatboxview.minimize).toHaveBeenCalled();
|
2014-10-27 23:06:11 +01:00
|
|
|
trimmedview = trimmed_chatboxes.get(jid);
|
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
var key = _converse.chatboxviews.keys()[1];
|
2014-06-01 18:16:32 +02:00
|
|
|
trimmedview = trimmed_chatboxes.get(key);
|
2014-06-16 00:03:34 +02:00
|
|
|
chatbox = trimmedview.model;
|
|
|
|
spyOn(chatbox, 'maximize').andCallThrough();
|
|
|
|
spyOn(trimmedview, 'restore').andCallThrough();
|
|
|
|
trimmedview.delegateEvents();
|
2014-06-01 18:16:32 +02:00
|
|
|
trimmedview.$("a.restore-chat").click();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2014-06-16 00:03:34 +02:00
|
|
|
waits(250);
|
2015-10-07 10:57:11 +02:00
|
|
|
runs(function () {
|
2014-06-16 00:03:34 +02:00
|
|
|
expect(trimmedview.restore).toHaveBeenCalled();
|
|
|
|
expect(chatbox.maximize).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is focused if its already open and you click on its corresponding roster item", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-06-01 17:57:03 +02:00
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2015-10-25 18:49:35 +01:00
|
|
|
var $el, jid, chatboxview, chatbox;
|
2014-04-24 19:39:03 +02:00
|
|
|
// openControlBox was called earlier, so the controlbox is
|
|
|
|
// visible, but no other chat boxes have been created.
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
chatbox = test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
chatboxview = _converse.chatboxviews.get(contact_jid);
|
2014-04-24 19:39:03 +02:00
|
|
|
spyOn(chatboxview, 'focus');
|
2014-10-27 23:06:11 +01:00
|
|
|
// Test that they can be trimmed
|
2015-10-07 10:57:11 +02:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
2016-02-15 15:55:34 +01:00
|
|
|
});
|
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
2015-10-07 10:57:11 +02:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
$el = _converse.rosterview.$el.find('a.open-chat:contains("'+chatbox.get('fullname')+'")');
|
2014-10-27 23:06:11 +01:00
|
|
|
jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
$el.click();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(2);
|
2014-10-27 23:06:11 +01:00
|
|
|
expect(chatboxview.focus).toHaveBeenCalled();
|
2016-02-15 15:55:34 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be saved to, and retrieved from, browserStorage", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-04-24 19:39:03 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxes(_converse, 6);
|
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
2014-02-28 03:04:52 +01:00
|
|
|
// We instantiate a new ChatBoxes collection, which by default
|
|
|
|
// will be empty.
|
2016-12-20 10:30:20 +01:00
|
|
|
var newchatboxes = new _converse.ChatBoxes();
|
2014-02-28 03:04:52 +01:00
|
|
|
expect(newchatboxes.length).toEqual(0);
|
2014-06-30 19:21:16 +02:00
|
|
|
// The chatboxes will then be fetched from browserStorage inside the
|
2014-02-28 03:04:52 +01:00
|
|
|
// onConnected method
|
|
|
|
newchatboxes.onConnected();
|
2014-04-18 17:42:11 +02:00
|
|
|
expect(newchatboxes.length).toEqual(7);
|
2014-06-30 19:21:16 +02:00
|
|
|
// Check that the chatboxes items retrieved from browserStorage
|
2014-02-28 03:04:52 +01:00
|
|
|
// have the same attributes values as the original ones.
|
2015-10-25 18:49:35 +01:00
|
|
|
var attrs = ['id', 'box_id', 'visible'];
|
|
|
|
var new_attrs, old_attrs;
|
|
|
|
for (var i=0; i<attrs.length; i++) {
|
2017-01-26 15:49:02 +01:00
|
|
|
new_attrs = _.map(_.map(newchatboxes.models, 'attributes'), attrs[i]);
|
2016-12-20 10:30:20 +01:00
|
|
|
old_attrs = _.map(_.map(_converse.chatboxes.models, 'attributes'), attrs[i]);
|
2014-02-28 03:04:52 +01:00
|
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
|
|
}
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.rosterview.render();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be closed by clicking a DOM element with class 'close-chatbox-button'", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var chatbox = test_utils.openChatBoxes(_converse, 1)[0],
|
|
|
|
controlview = _converse.chatboxviews.get('controlbox'), // The controlbox is currently open
|
|
|
|
chatview = _converse.chatboxviews.get(chatbox.get('jid'));
|
2014-05-27 18:34:22 +02:00
|
|
|
spyOn(chatview, 'close').andCallThrough();
|
|
|
|
spyOn(controlview, 'close').andCallThrough();
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2014-03-04 12:22:49 +01:00
|
|
|
|
|
|
|
// We need to rebind all events otherwise our spy won't be called
|
|
|
|
controlview.delegateEvents();
|
|
|
|
chatview.delegateEvents();
|
2014-02-28 03:04:52 +01:00
|
|
|
|
|
|
|
runs(function () {
|
2014-03-04 12:22:49 +01:00
|
|
|
controlview.$el.find('.close-chatbox-button').click();
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
2014-05-27 18:34:22 +02:00
|
|
|
expect(controlview.close).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
|
|
|
expect(_converse.emit.callCount, 1);
|
2014-03-04 12:22:49 +01:00
|
|
|
chatview.$el.find('.close-chatbox-button').click();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
2014-05-27 18:34:22 +02:00
|
|
|
expect(chatview.close).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
|
|
|
expect(_converse.emit.callCount, 2);
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var chatbox = test_utils.openChatBoxes(_converse, 1)[0],
|
|
|
|
chatview = _converse.chatboxviews.get(chatbox.get('jid')),
|
|
|
|
trimmed_chatboxes = _converse.minimized_chats,
|
2014-06-16 00:03:34 +02:00
|
|
|
trimmedview;
|
2014-06-02 05:13:53 +02:00
|
|
|
spyOn(chatview, 'minimize').andCallThrough();
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2014-03-04 19:16:39 +01:00
|
|
|
// We need to rebind all events otherwise our spy won't be called
|
|
|
|
chatview.delegateEvents();
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
});
|
2014-06-16 00:03:34 +02:00
|
|
|
waits(250);
|
2014-03-04 19:16:39 +01:00
|
|
|
runs(function () {
|
2014-06-02 05:13:53 +02:00
|
|
|
expect(chatview.minimize).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
|
|
|
|
expect(_converse.emit.callCount, 2);
|
2014-06-01 20:09:09 +02:00
|
|
|
expect(chatview.$el.is(':visible')).toBeFalsy();
|
2014-03-04 19:16:39 +01:00
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
2014-06-01 20:09:09 +02:00
|
|
|
trimmedview = trimmed_chatboxes.get(chatview.model.get('id'));
|
2014-06-16 00:03:34 +02:00
|
|
|
spyOn(trimmedview, 'restore').andCallThrough();
|
|
|
|
trimmedview.delegateEvents();
|
2014-06-01 20:09:09 +02:00
|
|
|
trimmedview.$("a.restore-chat").click();
|
2014-03-04 19:16:39 +01:00
|
|
|
});
|
2014-06-16 00:03:34 +02:00
|
|
|
waits(250);
|
2014-03-04 19:16:39 +01:00
|
|
|
runs(function () {
|
2014-06-16 00:03:34 +02:00
|
|
|
expect(trimmedview.restore).toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
|
2014-03-04 19:16:39 +01:00
|
|
|
expect(chatview.$el.find('.chat-body').is(':visible')).toBeTruthy();
|
|
|
|
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
|
|
|
|
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-plus')).toBeFalsy();
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will be removed from browserStorage when closed", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-03-04 19:16:39 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
|
|
|
_converse.chatboxes.browserStorage._clear();
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeControlBox();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2014-09-22 12:55:14 +02:00
|
|
|
waits(50);
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
|
|
|
test_utils.openChatBoxes(_converse, 6);
|
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
expect(_converse.chatboxes.length).toEqual(7);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxOpened', jasmine.any(Object));
|
|
|
|
test_utils.closeAllChatBoxes(_converse);
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2014-09-22 12:55:14 +02:00
|
|
|
waits(50);
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
|
|
|
var newchatboxes = new _converse.ChatBoxes();
|
2014-02-28 03:04:52 +01:00
|
|
|
expect(newchatboxes.length).toEqual(0);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
2014-06-30 19:21:16 +02:00
|
|
|
// onConnected will fetch chatboxes in browserStorage, but
|
2014-02-28 03:04:52 +01:00
|
|
|
// because there aren't any open chatboxes, there won't be any
|
2014-06-30 19:21:16 +02:00
|
|
|
// in browserStorage either. XXX except for the controlbox
|
2014-02-28 03:04:52 +01:00
|
|
|
newchatboxes.onConnected();
|
2014-04-18 17:42:11 +02:00
|
|
|
expect(newchatboxes.length).toEqual(1);
|
|
|
|
expect(newchatboxes.models[0].id).toBe("controlbox");
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A chat toolbar", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be found on each chat box", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2013-11-03 21:28:44 +01:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(view).toBeDefined();
|
|
|
|
var $toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
expect($toolbar.length).toBe(1);
|
2013-12-18 03:52:16 +01:00
|
|
|
expect($toolbar.children('li').length).toBe(3);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("contains a button for inserting emoticons", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-03 21:28:44 +01:00
|
|
|
|
2016-02-15 15:55:34 +01:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
view, $toolbar, $textarea;
|
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
2013-11-03 21:28:44 +01:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2016-02-15 15:55:34 +01:00
|
|
|
$toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
$textarea = view.$el.find('textarea.chat-textarea');
|
|
|
|
expect($toolbar.children('li.toggle-smiley').length).toBe(1);
|
|
|
|
// Register spies
|
|
|
|
spyOn(view, 'toggleEmoticonMenu').andCallThrough();
|
|
|
|
spyOn(view, 'insertEmoticon').andCallThrough();
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2013-11-03 21:28:44 +01:00
|
|
|
$toolbar.children('li.toggle-smiley').click();
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.toggleEmoticonMenu).toHaveBeenCalled();
|
|
|
|
var $menu = view.$el.find('.toggle-smiley ul');
|
|
|
|
var $items = $menu.children('li');
|
|
|
|
expect($menu.is(':visible')).toBeTruthy();
|
|
|
|
expect($items.length).toBe(13);
|
|
|
|
expect($($items[0]).children('a').data('emoticon')).toBe(':)');
|
|
|
|
expect($($items[1]).children('a').data('emoticon')).toBe(';)');
|
|
|
|
expect($($items[2]).children('a').data('emoticon')).toBe(':D');
|
|
|
|
expect($($items[3]).children('a').data('emoticon')).toBe(':P');
|
|
|
|
expect($($items[4]).children('a').data('emoticon')).toBe('8)');
|
|
|
|
expect($($items[5]).children('a').data('emoticon')).toBe('>:)');
|
|
|
|
expect($($items[6]).children('a').data('emoticon')).toBe(':S');
|
|
|
|
expect($($items[7]).children('a').data('emoticon')).toBe(':\\');
|
|
|
|
expect($($items[8]).children('a').data('emoticon')).toBe('>:(');
|
|
|
|
expect($($items[9]).children('a').data('emoticon')).toBe(':(');
|
|
|
|
expect($($items[10]).children('a').data('emoticon')).toBe(':O');
|
|
|
|
expect($($items[11]).children('a').data('emoticon')).toBe('(^.^)b');
|
|
|
|
expect($($items[12]).children('a').data('emoticon')).toBe('<3');
|
2014-04-18 17:42:11 +02:00
|
|
|
$items.first().click();
|
2013-11-03 21:28:44 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.insertEmoticon).toHaveBeenCalled();
|
|
|
|
expect($textarea.val()).toBe(':) ');
|
|
|
|
expect(view.$el.find('.toggle-smiley ul').is(':visible')).toBeFalsy();
|
|
|
|
$toolbar.children('li.toggle-smiley').click();
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.toggleEmoticonMenu).toHaveBeenCalled();
|
|
|
|
expect(view.$el.find('.toggle-smiley ul').is(':visible')).toBeTruthy();
|
|
|
|
view.$el.find('.toggle-smiley ul').children('li').last().click();
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.insertEmoticon).toHaveBeenCalled();
|
|
|
|
expect(view.$el.find('.toggle-smiley ul').is(':visible')).toBeFalsy();
|
|
|
|
expect($textarea.val()).toBe(':) <3 ');
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("contains a button for starting an encrypted chat session", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-03 21:28:44 +01:00
|
|
|
|
|
|
|
// TODO: More tests can be added here...
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2013-11-03 21:28:44 +01:00
|
|
|
var $toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
expect($toolbar.children('li.toggle-otr').length).toBe(1);
|
|
|
|
// Register spies
|
|
|
|
spyOn(view, 'toggleOTRMenu').andCallThrough();
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
$toolbar.children('li.toggle-otr').click();
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.toggleOTRMenu).toHaveBeenCalled();
|
|
|
|
var $menu = view.$el.find('.toggle-otr ul');
|
|
|
|
expect($menu.is(':visible')).toBeTruthy();
|
|
|
|
expect($menu.children('li').length).toBe(2);
|
|
|
|
});
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can contain a button for starting a call", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-12-18 03:52:16 +01:00
|
|
|
|
2014-04-24 19:14:37 +02:00
|
|
|
var view, callButton, $toolbar;
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2014-04-24 19:14:37 +02:00
|
|
|
// First check that the button doesn't show if it's not enabled
|
|
|
|
// via "visible_toolbar_buttons"
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.visible_toolbar_buttons.call = false;
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
$toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
callButton = $toolbar.find('.toggle-call');
|
|
|
|
expect(callButton.length).toBe(0);
|
2014-05-27 18:34:22 +02:00
|
|
|
view.close();
|
2014-04-24 19:14:37 +02:00
|
|
|
// Now check that it's shown if enabled and that it emits
|
2014-07-14 23:29:08 +02:00
|
|
|
// callButtonClicked
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.visible_toolbar_buttons.call = true; // enable the button
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
$toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
callButton = $toolbar.find('.toggle-call');
|
2013-12-18 03:52:16 +01:00
|
|
|
expect(callButton.length).toBe(1);
|
2014-04-24 19:14:37 +02:00
|
|
|
callButton.click();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can contain a button for clearing messages", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-12-18 03:52:16 +01:00
|
|
|
|
2014-04-24 19:14:37 +02:00
|
|
|
var view, clearButton, $toolbar;
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-04-24 19:14:37 +02:00
|
|
|
// First check that the button doesn't show if it's not enabled
|
|
|
|
// via "visible_toolbar_buttons"
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.visible_toolbar_buttons.clear = false;
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
$toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
clearButton = $toolbar.find('.toggle-clear');
|
|
|
|
expect(clearButton.length).toBe(0);
|
2014-05-27 18:34:22 +02:00
|
|
|
view.close();
|
2014-04-24 19:14:37 +02:00
|
|
|
// Now check that it's shown if enabled and that it calls
|
|
|
|
// clearMessages
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.visible_toolbar_buttons.clear = true; // enable the button
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
$toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
clearButton = $toolbar.find('.toggle-clear');
|
|
|
|
expect(clearButton.length).toBe(1);
|
|
|
|
spyOn(view, 'clearMessages');
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
|
|
|
clearButton.click();
|
|
|
|
expect(view.clearMessages).toHaveBeenCalled();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2013-11-03 21:28:44 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Chat Message", function () {
|
2014-03-05 00:23:45 +01:00
|
|
|
|
2016-05-28 08:35:16 +02:00
|
|
|
describe("when received from someone else", function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be received which will open a chatbox and be displayed inside it", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2017-02-01 10:14:36 +01:00
|
|
|
var message = 'This is a received message';
|
2016-05-28 10:55:03 +02:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2016-05-28 10:55:03 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
|
|
|
|
// We don't already have an open chatbox for this user
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.get(sender_jid)).not.toBeDefined();
|
2016-05-28 10:55:03 +02:00
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
// onMessage is a handler for received XMPP messages
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2016-05-28 10:55:03 +02:00
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
// Check that the chatbox and its view now exist
|
2016-12-20 10:30:20 +01:00
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2016-05-28 10:55:03 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(chatboxview).toBeDefined();
|
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
var msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[0]);
|
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content');
|
|
|
|
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
var sender_txt = $chat_content.find('span.chat-msg-them').text();
|
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
|
|
|
}));
|
2016-05-28 10:55:03 +02:00
|
|
|
|
2017-02-01 10:14:36 +01:00
|
|
|
describe("who is not on the roster", function () {
|
|
|
|
it("will open a chatbox and be displayed inside it if allow_non_roster_messaging is true", mock.initConverse(function (converse) {
|
|
|
|
converse.allow_non_roster_messaging = false;
|
|
|
|
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
var message = 'This is a received message from someone not on the roster';
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
|
|
|
|
// We don't already have an open chatbox for this user
|
|
|
|
expect(converse.chatboxes.get(sender_jid)).not.toBeDefined();
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
// onMessage is a handler for received XMPP messages
|
|
|
|
converse.chatboxes.onMessage(msg);
|
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
var chatbox = converse.chatboxes.get(sender_jid);
|
|
|
|
expect(chatbox).not.toBeDefined();
|
|
|
|
|
|
|
|
// onMessage is a handler for received XMPP messages
|
|
|
|
converse.allow_non_roster_messaging =true;
|
|
|
|
converse.chatboxes.onMessage(msg);
|
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
// Check that the chatbox and its view now exist
|
|
|
|
var chatbox = converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = converse.chatboxviews.get(sender_jid);
|
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(chatboxview).toBeDefined();
|
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
var msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(sender_jid);
|
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content');
|
|
|
|
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
var sender_txt = $chat_content.find('span.chat-msg-them').text();
|
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2016-06-23 08:55:25 +02:00
|
|
|
describe("and for which then an error message is received from the server", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will have the error message displayed after itself", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-06-23 08:55:25 +02:00
|
|
|
// TODO: what could still be done for error
|
|
|
|
// messages... if the <error> element has type
|
|
|
|
// "cancel", then we know the messages wasn't sent,
|
|
|
|
// and can give the user a nicer indication of
|
|
|
|
// that.
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
/* <message from="scotty@enterprise.com/_converse.js-84843526"
|
2016-06-23 08:55:25 +02:00
|
|
|
* to="kirk@enterprise.com.com"
|
|
|
|
* type="chat"
|
|
|
|
* id="82bc02ce-9651-4336-baf0-fa04762ed8d2"
|
|
|
|
* xmlns="jabber:client">
|
|
|
|
* <body>yo</body>
|
|
|
|
* <active xmlns="http://jabber.org/protocol/chatstates"/>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
var sender_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
var fullname = _converse.xmppstatus.get('fullname');
|
|
|
|
fullname = _.isEmpty(fullname)? _converse.bare_jid: fullname;
|
|
|
|
_converse.api.chats.open(sender_jid);
|
2016-06-23 08:55:25 +02:00
|
|
|
var msg_text = 'This message will not be sent, due to an error';
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
2016-06-23 08:55:25 +02:00
|
|
|
var message = view.model.messages.create({
|
|
|
|
'msgid': '82bc02ce-9651-4336-baf0-fa04762ed8d2',
|
|
|
|
'fullname': fullname,
|
|
|
|
'sender': 'me',
|
|
|
|
'time': moment().format(),
|
|
|
|
'message': msg_text
|
|
|
|
});
|
|
|
|
view.sendMessage(message);
|
|
|
|
var $chat_content = view.$el.find('.chat-content');
|
|
|
|
var msg_txt = $chat_content.find('.chat-message:last').find('.chat-msg-content').text();
|
|
|
|
expect(msg_txt).toEqual(msg_text);
|
|
|
|
|
|
|
|
// We send another message, for which an error will
|
|
|
|
// not be received, to test that errors appear
|
|
|
|
// after the relevant message.
|
|
|
|
msg_text = 'This message will be sent, and not receive an error';
|
|
|
|
message = view.model.messages.create({
|
|
|
|
'msgid': '6fcdeee3-000f-4ce8-a17e-9ce28f0ae104',
|
|
|
|
'fullname': fullname,
|
|
|
|
'sender': 'me',
|
|
|
|
'time': moment().format(),
|
|
|
|
'message': msg_text
|
|
|
|
});
|
|
|
|
view.sendMessage(message);
|
|
|
|
msg_txt = $chat_content.find('.chat-message:last').find('.chat-msg-content').text();
|
|
|
|
expect(msg_txt).toEqual(msg_text);
|
|
|
|
|
|
|
|
/* <message xmlns="jabber:client"
|
2016-12-20 10:30:20 +01:00
|
|
|
* to="scotty@enterprise.com/_converse.js-84843526"
|
2016-06-23 08:55:25 +02:00
|
|
|
* type="error"
|
|
|
|
* id="82bc02ce-9651-4336-baf0-fa04762ed8d2"
|
|
|
|
* from="kirk@enterprise.com.com">
|
|
|
|
* <error type="cancel">
|
|
|
|
* <remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
|
|
|
|
* <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Server-to-server connection failed: Connecting failed: connection timeout</text>
|
|
|
|
* </error>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
var error_txt = 'Server-to-server connection failed: Connecting failed: connection timeout';
|
|
|
|
var stanza = $msg({
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.connection.jid,
|
2016-06-23 08:55:25 +02:00
|
|
|
'type':'error',
|
|
|
|
'id':'82bc02ce-9651-4336-baf0-fa04762ed8d2',
|
|
|
|
'from': sender_jid
|
|
|
|
})
|
|
|
|
.c('error', {'type': 'cancel'})
|
|
|
|
.c('remote-server-not-found', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" }).up()
|
|
|
|
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
|
|
|
|
.t('Server-to-server connection failed: Connecting failed: connection timeout');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-06-23 08:55:25 +02:00
|
|
|
expect($chat_content.find('.chat-error').text()).toEqual(error_txt);
|
|
|
|
|
|
|
|
/* Incoming error messages that are not tied to a
|
|
|
|
* certain show message (via the msgid attribute),
|
|
|
|
* are not shown at all. The reason for this is
|
|
|
|
* that we may get error messages for chat state
|
|
|
|
* notifications as well.
|
|
|
|
*/
|
|
|
|
stanza = $msg({
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.connection.jid,
|
2016-06-23 08:55:25 +02:00
|
|
|
'type':'error',
|
|
|
|
'id':'some-other-unused-id',
|
|
|
|
'from': sender_jid
|
|
|
|
})
|
|
|
|
.c('error', {'type': 'cancel'})
|
|
|
|
.c('remote-server-not-found', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" }).up()
|
|
|
|
.c('text', { 'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas" })
|
|
|
|
.t('Server-to-server connection failed: Connecting failed: connection timeout');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2016-06-23 08:55:25 +02:00
|
|
|
expect($chat_content.find('.chat-error').length).toEqual(1);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-06-23 08:55:25 +02:00
|
|
|
});
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will cause the chat area to be scrolled down only if it was at the bottom already", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-05-28 10:55:03 +02:00
|
|
|
var message = 'This message is received while the chat area is scrolled up';
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2016-05-28 10:55:03 +02:00
|
|
|
spyOn(chatboxview, 'scrollDown').andCallThrough();
|
|
|
|
runs(function () {
|
|
|
|
/* Create enough messages so that there's a
|
|
|
|
* scrollbar.
|
|
|
|
*/
|
|
|
|
for (var i=0; i<20; i++) {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage($msg({
|
2016-05-28 10:55:03 +02:00
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2016-05-28 10:55:03 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('Message: '+i).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
chatboxview.$content.scrollTop(0);
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage($msg({
|
2016-05-28 10:55:03 +02:00
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2016-05-28 10:55:03 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
});
|
|
|
|
waits(150);
|
|
|
|
runs(function () {
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content');
|
|
|
|
var msg_txt = $chat_content.find('.chat-message:last').find('.chat-msg-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
expect(chatboxview.model.get('scrolled')).toBeTruthy();
|
|
|
|
expect(chatboxview.$content.scrollTop()).toBe(0);
|
|
|
|
expect(chatboxview.$('.new-msgs-indicator').is(':visible')).toBeTruthy();
|
|
|
|
// Scroll down again
|
|
|
|
chatboxview.$content.scrollTop(chatboxview.$content[0].scrollHeight);
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(chatboxview.$('.new-msgs-indicator').is(':visible')).toBeFalsy();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is ignored if it's intended for a different resource and filter_by_resource is set to true", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-05-28 10:55:03 +02:00
|
|
|
|
|
|
|
// Send a message from a different resource
|
|
|
|
var message, sender_jid, msg;
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'log');
|
|
|
|
spyOn(_converse.chatboxes, 'getChatBox').andCallThrough();
|
2016-05-28 10:55:03 +02:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.filter_by_resource = true;
|
2016-05-28 10:55:03 +02:00
|
|
|
sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.bare_jid+"/some-other-resource",
|
2016-05-28 10:55:03 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t("This message will not be shown").up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
2016-05-28 10:55:03 +02:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.log).toHaveBeenCalledWith(
|
2016-05-28 10:55:03 +02:00
|
|
|
"onMessage: Ignoring incoming message intended for a different resource: dummy@localhost/some-other-resource", "info");
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.getChatBox).not.toHaveBeenCalled();
|
|
|
|
_converse.filter_by_resource = false;
|
2016-05-28 10:55:03 +02:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
message = "This message sent to a different resource will be shown";
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.bare_jid+"/some-other-resource",
|
2016-05-28 10:55:03 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: '134234623462346'
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
2016-05-28 10:55:03 +02:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.getChatBox).toHaveBeenCalled();
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2016-05-28 10:55:03 +02:00
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content:last');
|
|
|
|
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-05-28 08:35:16 +02:00
|
|
|
});
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is ignored if it's a malformed headline message", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-03-28 12:49:52 +02:00
|
|
|
/* Ideally we wouldn't have to filter out headline
|
|
|
|
* messages, but Prosody gives them the wrong 'type' :(
|
|
|
|
*/
|
2016-12-20 10:30:20 +01:00
|
|
|
sinon.spy(_converse, 'log');
|
|
|
|
sinon.spy(_converse.chatboxes, 'getChatBox');
|
2016-03-28 12:49:52 +02:00
|
|
|
sinon.spy(utils, 'isHeadlineMessage');
|
|
|
|
var msg = $msg({
|
|
|
|
from: 'localhost',
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.bare_jid,
|
2016-03-28 12:49:52 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t("This headline message will not be shown").tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.log.calledWith(
|
2016-03-28 12:49:52 +02:00
|
|
|
"onMessage: Ignoring incoming headline message sent with type 'chat' from JID: localhost",
|
|
|
|
"info"
|
|
|
|
)).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.called).toBeTruthy();
|
|
|
|
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.getChatBox.called).toBeFalsy();
|
2016-03-28 12:49:52 +02:00
|
|
|
// Remove sinon spies
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.log.restore();
|
|
|
|
_converse.chatboxes.getChatBox.restore();
|
2016-03-28 12:49:52 +02:00
|
|
|
utils.isHeadlineMessage.restore();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be a carbon message, as defined in XEP-0280", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-07-02 11:23:52 +02:00
|
|
|
|
2015-07-03 11:36:30 +02:00
|
|
|
// Send a message from a different resource
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'log');
|
2015-07-03 11:36:30 +02:00
|
|
|
var msgtext = 'This is a carbon message';
|
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msg = $msg({
|
2017-01-31 23:18:26 +01:00
|
|
|
'from': sender_jid,
|
2015-07-03 11:36:30 +02:00
|
|
|
'id': (new Date()).getTime(),
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.connection.jid,
|
2015-07-03 11:36:30 +02:00
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('received', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.bare_jid+'/another-resource',
|
2015-07-03 11:36:30 +02:00
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(msgtext).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
2015-07-03 11:36:30 +02:00
|
|
|
|
|
|
|
// Check that the chatbox and its view now exist
|
2016-12-20 10:30:20 +01:00
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2015-07-03 11:36:30 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(chatboxview).toBeDefined();
|
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
var msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(msgtext);
|
2016-03-23 23:27:25 +01:00
|
|
|
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[1]);
|
2015-07-03 11:36:30 +02:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content');
|
2015-10-28 09:52:19 +01:00
|
|
|
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
|
2015-07-03 11:36:30 +02:00
|
|
|
expect(msg_txt).toEqual(msgtext);
|
2015-10-28 09:52:19 +01:00
|
|
|
var sender_txt = $chat_content.find('span.chat-msg-them').text();
|
2015-07-03 11:36:30 +02:00
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be a carbon message that this user sent from a different client, as defined in XEP-0280", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-07-03 11:36:30 +02:00
|
|
|
|
2015-07-03 11:55:13 +02:00
|
|
|
// Send a message from a different resource
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'log');
|
2015-07-03 11:55:13 +02:00
|
|
|
var msgtext = 'This is a sent carbon message';
|
|
|
|
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msg = $msg({
|
2016-12-20 10:30:20 +01:00
|
|
|
'from': _converse.bare_jid,
|
2015-07-03 11:55:13 +02:00
|
|
|
'id': (new Date()).getTime(),
|
2016-12-20 10:30:20 +01:00
|
|
|
'to': _converse.connection.jid,
|
2015-07-03 11:55:13 +02:00
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('sent', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
2016-12-20 10:30:20 +01:00
|
|
|
'from': _converse.bare_jid+'/another-resource',
|
2015-07-03 11:55:13 +02:00
|
|
|
'to': recipient_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(msgtext).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
2015-07-03 11:55:13 +02:00
|
|
|
|
|
|
|
// Check that the chatbox and its view now exist
|
2016-12-20 10:30:20 +01:00
|
|
|
var chatbox = _converse.chatboxes.get(recipient_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(recipient_jid);
|
2015-07-03 11:55:13 +02:00
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(chatboxview).toBeDefined();
|
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
var msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(msgtext);
|
2016-03-23 23:27:25 +01:00
|
|
|
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[5]);
|
2015-07-03 11:55:13 +02:00
|
|
|
expect(msg_obj.get('sender')).toEqual('me');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
|
|
|
// Now check that the message appears inside the chatbox in the DOM
|
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content');
|
2015-10-28 09:52:19 +01:00
|
|
|
var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
|
2015-07-03 11:55:13 +02:00
|
|
|
expect(msg_txt).toEqual(msgtext);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-01-31 23:18:26 +01:00
|
|
|
it("will be discarded if it's a malicious message meant to look like a carbon copy", mock.initConverse(function (converse) {
|
|
|
|
test_utils.createContacts(converse, 'current');
|
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.openContactsPanel(converse);
|
|
|
|
/* <message from="mallory@evil.example" to="b@xmpp.example">
|
|
|
|
* <received xmlns='urn:xmpp:carbons:2'>
|
|
|
|
* <forwarded xmlns='urn:xmpp:forward:0'>
|
|
|
|
* <message from="alice@xmpp.example" to="bob@xmpp.example/client1">
|
|
|
|
* <body>Please come to Creepy Valley tonight, alone!</body>
|
|
|
|
* </message>
|
|
|
|
* </forwarded>
|
|
|
|
* </received>
|
|
|
|
* </message>
|
|
|
|
*/
|
|
|
|
spyOn(converse, 'log');
|
|
|
|
var msgtext = 'Please come to Creepy Valley tonight, alone!';
|
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var impersonated_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msg = $msg({
|
|
|
|
'from': sender_jid,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('received', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': impersonated_jid,
|
|
|
|
'to': converse.connection.jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('body').t(msgtext).tree();
|
|
|
|
converse.chatboxes.onMessage(msg);
|
|
|
|
|
|
|
|
// Check that chatbox for impersonated user is not created.
|
|
|
|
var chatbox = converse.chatboxes.get(impersonated_jid);
|
|
|
|
expect(chatbox).not.toBeDefined();
|
|
|
|
|
|
|
|
// Check that the chatbox for the malicous user is not created
|
|
|
|
chatbox = converse.chatboxes.get(sender_jid);
|
|
|
|
expect(chatbox).not.toBeDefined();
|
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("received for a minimized chat box will increment a counter on its header", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-03-05 01:10:29 +01:00
|
|
|
var contact_name = mock.cur_names[0];
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-11-22 17:42:58 +01:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit').andCallThrough();
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var chatview = _converse.chatboxviews.get(contact_jid);
|
2016-11-22 17:42:58 +01:00
|
|
|
expect(chatview.$el.is(':visible')).toBeTruthy();
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
var message = 'This message is sent to a minimized chatbox';
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-03-09 12:10:57 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2016-11-22 17:42:58 +01:00
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var trimmed_chatboxes = _converse.minimized_chats;
|
2016-11-22 17:42:58 +01:00
|
|
|
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
|
|
|
var $count = trimmedview.$el.find('.chat-head-message-count');
|
|
|
|
expect(chatview.$el.is(':visible')).toBeFalsy();
|
|
|
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
|
|
|
expect($count.is(':visible')).toBeTruthy();
|
|
|
|
expect($count.html()).toBe('1');
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(
|
2016-11-22 17:42:58 +01:00
|
|
|
$msg({
|
|
|
|
from: mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2016-11-22 17:42:58 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('This message is also sent to a minimized chatbox').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree()
|
|
|
|
);
|
|
|
|
expect(chatview.$el.is(':visible')).toBeFalsy();
|
|
|
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
|
|
|
$count = trimmedview.$el.find('.chat-head-message-count');
|
|
|
|
expect($count.is(':visible')).toBeTruthy();
|
|
|
|
expect($count.html()).toBe('2');
|
|
|
|
trimmedview.$el.find('.restore-chat').click();
|
|
|
|
expect(trimmed_chatboxes.keys().length).toBe(0);
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will indicate when it has a time difference of more than a day between it and its predecessor", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2013-11-03 12:24:18 +01:00
|
|
|
var contact_name = mock.cur_names[1];
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
test_utils.clearChatBoxMessages(_converse, contact_jid);
|
2014-04-26 02:14:58 +02:00
|
|
|
var one_day_ago = moment();
|
2014-04-25 22:56:59 +02:00
|
|
|
one_day_ago.subtract('days', 1);
|
2013-11-03 12:24:18 +01:00
|
|
|
var message = 'This is a day old message';
|
2016-12-20 10:30:20 +01:00
|
|
|
var chatbox = _converse.chatboxes.get(contact_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(contact_jid);
|
2013-11-03 12:24:18 +01:00
|
|
|
var $chat_content = chatboxview.$el.find('.chat-content');
|
|
|
|
var msg_obj;
|
|
|
|
var msg_txt;
|
|
|
|
var sender_txt;
|
|
|
|
|
2013-12-16 14:27:07 +01:00
|
|
|
var msg = $msg({
|
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2013-12-16 14:27:07 +01:00
|
|
|
type: 'chat',
|
2014-04-25 22:56:59 +02:00
|
|
|
id: one_day_ago.unix()
|
2013-12-16 14:27:07 +01:00
|
|
|
}).c('body').t(message).up()
|
2014-04-25 22:56:59 +02:00
|
|
|
.c('delay', { xmlns:'urn:xmpp:delay', from: 'localhost', stamp: one_day_ago.format() })
|
2013-12-16 14:27:07 +01:00
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
|
|
|
msg_obj = chatbox.messages.models[0];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
2016-03-23 23:27:25 +01:00
|
|
|
expect(msg_obj.get('fullname')).toEqual(contact_name);
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(true);
|
2015-10-28 09:52:19 +01:00
|
|
|
msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text();
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(msg_txt).toEqual(message);
|
2015-10-28 09:52:19 +01:00
|
|
|
sender_txt = $chat_content.find('span.chat-msg-them').text();
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
|
|
|
|
2016-05-25 08:23:00 +02:00
|
|
|
var $time = $chat_content.find('time');
|
|
|
|
expect($time.length).toEqual(1);
|
|
|
|
expect($time.attr('class')).toEqual('chat-info chat-date');
|
|
|
|
expect($time.data('isodate')).toEqual(moment(one_day_ago.startOf('day')).format());
|
|
|
|
expect($time.text()).toEqual(moment(one_day_ago.startOf('day')).format("dddd MMM Do YYYY"));
|
|
|
|
|
2013-11-03 12:24:18 +01:00
|
|
|
message = 'This is a current message';
|
2013-12-16 14:27:07 +01:00
|
|
|
msg = $msg({
|
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2013-12-16 14:27:07 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: new Date().getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
2013-11-03 12:24:18 +01:00
|
|
|
// Check that there is a <time> element, with the required
|
|
|
|
// props.
|
2016-05-25 08:23:00 +02:00
|
|
|
$time = $chat_content.find('time');
|
|
|
|
expect($time.length).toEqual(2); // There are now two time elements
|
|
|
|
$time = $chat_content.find('time:last'); // We check the last one
|
2013-11-03 12:24:18 +01:00
|
|
|
var message_date = new Date();
|
2015-10-28 09:49:28 +01:00
|
|
|
expect($time.attr('class')).toEqual('chat-info chat-date');
|
2016-05-25 08:23:00 +02:00
|
|
|
expect($time.data('isodate')).toEqual(moment(message_date).startOf('day').format());
|
|
|
|
expect($time.text()).toEqual(moment(message_date).startOf('day').format("dddd MMM Do YYYY"));
|
2013-11-03 12:24:18 +01:00
|
|
|
|
|
|
|
// Normal checks for the 2nd message
|
|
|
|
expect(chatbox.messages.length).toEqual(2);
|
|
|
|
msg_obj = chatbox.messages.models[1];
|
|
|
|
expect(msg_obj.get('message')).toEqual(message);
|
2016-03-23 23:27:25 +01:00
|
|
|
expect(msg_obj.get('fullname')).toEqual(contact_name);
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
2015-10-28 09:52:19 +01:00
|
|
|
msg_txt = $chat_content.find('.chat-message').last().find('.chat-msg-content').text();
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(msg_txt).toEqual(message);
|
2015-10-28 09:52:19 +01:00
|
|
|
sender_txt = $chat_content.find('span.chat-msg-them').last().text();
|
2013-11-03 12:24:18 +01:00
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be sent from a chatbox, and will appear inside it", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-03 12:24:18 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2015-04-02 02:01:53 +02:00
|
|
|
var message = 'This message is sent from this chatbox';
|
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
expect(view.model.messages.length, 2);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit.mostRecentCall.args, ['messageSend', message]);
|
2015-10-28 09:52:19 +01:00
|
|
|
expect(view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content').text()).toEqual(message);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sanitized to prevent Javascript injection attacks", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-12-18 03:15:27 +01:00
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2014-03-05 03:29:10 +01:00
|
|
|
var message = '<p>This message contains <em>some</em> <b>markup</b></p>';
|
2013-12-18 03:15:27 +01:00
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2013-12-18 03:15:27 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
2015-10-28 09:52:19 +01:00
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
2014-03-05 03:29:10 +01:00
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<p>This message contains <em>some</em> <b>markup</b></p>');
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("should display emoticons correctly", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-03-05 03:29:10 +01:00
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2014-05-19 16:06:11 +02:00
|
|
|
var messages = [':)', ';)', ':D', ':P', '8)', '>:)', ':S', ':\\', '>:(', ':(', ':O', '(^.^)b', '<3'];
|
2014-05-19 16:12:55 +02:00
|
|
|
var emoticons = [
|
|
|
|
'<span class="emoticon icon-smiley"></span>', '<span class="emoticon icon-wink"></span>',
|
|
|
|
'<span class="emoticon icon-grin"></span>', '<span class="emoticon icon-tongue"></span>',
|
|
|
|
'<span class="emoticon icon-cool"></span>', '<span class="emoticon icon-evil"></span>',
|
|
|
|
'<span class="emoticon icon-confused"></span>', '<span class="emoticon icon-wondering"></span>',
|
|
|
|
'<span class="emoticon icon-angry"></span>', '<span class="emoticon icon-sad"></span>',
|
|
|
|
'<span class="emoticon icon-shocked"></span>', '<span class="emoticon icon-thumbs-up"></span>',
|
|
|
|
'<span class="emoticon icon-heart"></span>'
|
|
|
|
];
|
2014-05-19 16:06:11 +02:00
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
|
|
|
for (var i = 0; i < messages.length; i++) {
|
2014-05-19 16:12:55 +02:00
|
|
|
var message = messages[i];
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-05-19 16:12:55 +02:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
2015-10-28 09:52:19 +01:00
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
2014-05-19 16:12:55 +02:00
|
|
|
expect(msg.html()).toEqual(emoticons[i]);
|
2014-05-19 16:06:11 +02:00
|
|
|
}
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can contain hyperlinks, which will be clickable", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-03-05 03:29:10 +01:00
|
|
|
|
2016-05-28 13:13:49 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2016-05-28 13:13:49 +02:00
|
|
|
var message = 'This message contains a hyperlink: www.opkode.com';
|
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
|
|
|
runs(function () {
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
});
|
|
|
|
waits(500);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('This message contains a hyperlink: <a target="_blank" rel="noopener" href="http://www.opkode.com">www.opkode.com</a>');
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will have properly escaped URLs", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-05-28 13:13:49 +02:00
|
|
|
|
|
|
|
var message, msg;
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2014-03-05 03:29:10 +01:00
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
2016-05-28 13:13:49 +02:00
|
|
|
runs(function () {
|
|
|
|
message = "http://www.opkode.com/'onmouseover='alert(1)'whatever";
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
});
|
2016-05-28 13:28:32 +02:00
|
|
|
waits(50);
|
2016-05-28 13:13:49 +02:00
|
|
|
runs(function () {
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" rel="noopener" href="http://www.opkode.com/%27onmouseover=%27alert%281%29%27whatever">http://www.opkode.com/\'onmouseover=\'alert(1)\'whatever</a>');
|
2014-03-05 03:29:10 +01:00
|
|
|
|
2016-05-28 13:13:49 +02:00
|
|
|
message = 'http://www.opkode.com/"onmouseover="alert(1)"whatever';
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
});
|
2016-05-28 13:28:32 +02:00
|
|
|
waits(50);
|
2016-05-28 13:13:49 +02:00
|
|
|
runs(function () {
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" rel="noopener" href="http://www.opkode.com/%22onmouseover=%22alert%281%29%22whatever">http://www.opkode.com/"onmouseover="alert(1)"whatever</a>');
|
2014-03-05 03:29:10 +01:00
|
|
|
|
2016-05-28 13:13:49 +02:00
|
|
|
message = "https://en.wikipedia.org/wiki/Ender's_Game";
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
});
|
2016-05-28 13:28:32 +02:00
|
|
|
waits(50);
|
2016-05-28 13:13:49 +02:00
|
|
|
runs(function () {
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender\'s_Game</a>');
|
2014-03-09 04:51:21 +01:00
|
|
|
|
2016-05-28 13:13:49 +02:00
|
|
|
message = "https://en.wikipedia.org/wiki/Ender%27s_Game";
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
});
|
2016-05-28 13:28:32 +02:00
|
|
|
waits(50);
|
2016-05-28 13:13:49 +02:00
|
|
|
runs(function () {
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender%27s_Game</a>');
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will render images from their URLs", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2014-03-05 03:29:10 +01:00
|
|
|
|
2016-05-28 13:13:49 +02:00
|
|
|
if (/PhantomJS/.test(window.navigator.userAgent)) {
|
|
|
|
// Doesn't work when running tests in PhantomJS, since
|
|
|
|
// the page is loaded via file:///
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var message = document.URL.split(window.location.pathname)[0] + "/logo/conversejs.svg";
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2016-05-28 13:13:49 +02:00
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
|
|
|
runs(function () {
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
});
|
|
|
|
waits(500);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content');
|
|
|
|
expect(msg.html()).toEqual('<img src="'+message+'" class="chat-image">');
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2013-12-18 03:15:27 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2015-01-01 21:25:12 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Chat Status Notification", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("does not open automatically if a chat state notification is received", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-01 21:25:12 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2015-04-02 02:01:53 +02:00
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
// <composing> state
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2015-04-02 02:01:53 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2016-08-12 22:38:39 +02:00
|
|
|
}).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-04-02 02:01:53 +02:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("An active notification", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent when the user opens a chat box", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-02-15 15:55:34 +01:00
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2016-02-15 15:55:34 +01:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2016-02-15 15:55:34 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2016-02-15 15:55:34 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().length).toBe(3);
|
|
|
|
expect($stanza.children().get(0).tagName).toBe('active');
|
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
2016-02-15 15:55:34 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent when the user maximizes a minimized a chat box", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-11-22 17:42:58 +01:00
|
|
|
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
2016-11-22 17:42:58 +01:00
|
|
|
});
|
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2016-11-22 17:42:58 +01:00
|
|
|
view.model.minimize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2016-11-22 17:42:58 +01:00
|
|
|
view.model.maximize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2016-11-22 17:42:58 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(3);
|
|
|
|
expect($stanza.children().get(0).tagName).toBe('active');
|
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A composing notification", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent as soon as the user starts typing a message which is not a command", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-02-15 15:55:34 +01:00
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
|
|
|
runs(function () {
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2016-02-15 15:55:34 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2016-02-15 15:55:34 +01:00
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2016-02-15 15:55:34 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().get(0).tagName).toBe('composing');
|
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2016-02-15 15:55:34 +01:00
|
|
|
// The notification is not sent again
|
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit.callCount, 1);
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will be shown if received", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2015-01-09 09:02:35 +01:00
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
|
|
|
|
// <composing> state
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2015-01-09 09:02:35 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2015-01-09 09:02:35 +01:00
|
|
|
expect(chatboxview).toBeDefined();
|
|
|
|
// Check that the notification appears inside the chatbox in the DOM
|
|
|
|
var $events = chatboxview.$el.find('.chat-event');
|
2016-03-23 23:27:25 +01:00
|
|
|
expect($events.text()).toEqual(mock.cur_names[1] + ' is typing');
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2015-01-01 21:25:12 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A paused notification", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent if the user has stopped typing since 30 seconds", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-02-15 15:55:34 +01:00
|
|
|
var view, contact_jid;
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.TIMEOUTS.PAUSED = 200; // Make the timeout shorter so that we can test
|
2016-02-15 15:55:34 +01:00
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
2015-01-01 21:25:12 +01:00
|
|
|
runs(function () {
|
2016-02-15 15:55:34 +01:00
|
|
|
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(_converse.connection, 'send');
|
2016-02-15 15:55:34 +01:00
|
|
|
spyOn(view, 'setChatState').andCallThrough();
|
2015-01-01 21:25:12 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().get(0).tagName).toBe('composing');
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('paused');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[1][0].tree());
|
2015-01-01 21:25:12 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().length).toBe(3);
|
|
|
|
expect($stanza.children().get(0).tagName).toBe('paused');
|
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
2015-04-04 11:25:50 +02:00
|
|
|
// Test #359. A paused notification should not be sent
|
|
|
|
// out if the user simply types longer than the
|
|
|
|
// timeout.
|
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.setChatState).toHaveBeenCalled();
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
});
|
|
|
|
waits(100);
|
|
|
|
runs(function () {
|
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
});
|
|
|
|
waits(150);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will be shown if received", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
// TODO: only show paused state if the previous state was composing
|
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2015-01-09 09:02:35 +01:00
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
// <paused> state
|
2015-10-25 18:49:35 +01:00
|
|
|
var msg = $msg({
|
2015-01-09 09:02:35 +01:00
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2015-01-09 09:02:35 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2015-10-25 18:49:35 +01:00
|
|
|
var $events = chatboxview.$el.find('.chat-event');
|
2016-03-23 23:27:25 +01:00
|
|
|
expect($events.text()).toEqual(mock.cur_names[1] + ' has stopped typing');
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2015-01-01 21:25:12 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("An inactive notifciation", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent if the user has stopped typing since 2 minutes", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2015-01-01 21:25:12 +01:00
|
|
|
// Make the timeouts shorter so that we can test
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.TIMEOUTS.PAUSED = 200;
|
|
|
|
_converse.TIMEOUTS.INACTIVE = 200;
|
2015-01-01 21:25:12 +01:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2015-01-01 21:25:12 +01:00
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('paused');
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2015-01-01 21:25:12 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().length).toBe(3);
|
|
|
|
expect($stanza.children().get(0).tagName).toBe('inactive');
|
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
|
|
|
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent when the user a minimizes a chat box", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(_converse.connection, 'send');
|
2015-01-09 09:02:35 +01:00
|
|
|
view.minimize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2015-01-09 09:02:35 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().get(0).tagName).toBe('inactive');
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is sent if the user closes a chat box", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2016-02-15 15:55:34 +01:00
|
|
|
waits(300); // ChatBox.show() is debounced for 250ms
|
|
|
|
runs(function () {
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2016-02-15 15:55:34 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2016-02-15 15:55:34 +01:00
|
|
|
view.close();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(_converse.connection.send.argsForCall[0][0].tree());
|
2016-02-15 15:55:34 +01:00
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().length).toBe(3);
|
|
|
|
expect($stanza.children().get(0).tagName).toBe('inactive');
|
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
2016-02-15 15:55:34 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will clear any other chat status notifications if its received", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2015-01-01 21:25:12 +01:00
|
|
|
|
2015-01-09 09:02:35 +01:00
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2015-01-09 10:48:36 +01:00
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
2015-01-09 10:48:36 +01:00
|
|
|
expect(view.$el.find('.chat-event').length).toBe(0);
|
2017-01-26 15:49:02 +01:00
|
|
|
view.showStatusNotification(sender_jid+' is typing');
|
2015-01-09 10:48:36 +01:00
|
|
|
expect(view.$el.find('.chat-event').length).toBe(1);
|
2015-10-25 18:49:35 +01:00
|
|
|
var msg = $msg({
|
2015-01-09 10:48:36 +01:00
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2015-01-09 10:48:36 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
2015-01-09 10:48:36 +01:00
|
|
|
expect(view.$el.find('.chat-event').length).toBe(0);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2015-01-09 10:48:36 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2015-01-09 10:48:36 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A gone notifciation", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will be shown if received", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2015-01-09 09:02:35 +01:00
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
// <paused> state
|
2015-10-25 18:49:35 +01:00
|
|
|
var msg = $msg({
|
2015-01-09 09:02:35 +01:00
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2015-01-09 09:02:35 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('gone', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2015-10-25 18:49:35 +01:00
|
|
|
var $events = chatboxview.$el.find('.chat-event');
|
2016-03-23 23:27:25 +01:00
|
|
|
expect($events.text()).toEqual(mock.cur_names[1] + ' has gone away');
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("Special Messages", function () {
|
2014-03-05 03:29:10 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("'/clear' can be used to clear messages in a conversation", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
2013-11-02 12:37:38 +01:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2013-11-02 12:37:38 +01:00
|
|
|
var message = 'This message is another sent from this chatbox';
|
|
|
|
// Lets make sure there is at least one message already
|
|
|
|
// (e.g for when this test is run on its own).
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2013-11-03 21:28:44 +01:00
|
|
|
expect(view.model.messages.length > 0).toBeTruthy();
|
2014-06-30 19:21:16 +02:00
|
|
|
expect(view.model.messages.browserStorage.records.length > 0).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('messageSend', message);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
|
|
|
message = '/clear';
|
2015-07-04 10:10:21 +02:00
|
|
|
spyOn(view, 'onMessageSubmitted').andCallThrough();
|
2014-04-24 19:14:37 +02:00
|
|
|
spyOn(view, 'clearMessages').andCallThrough();
|
|
|
|
spyOn(window, 'confirm').andCallFake(function () {
|
|
|
|
return true;
|
|
|
|
});
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2015-07-04 10:10:21 +02:00
|
|
|
expect(view.onMessageSubmitted).toHaveBeenCalled();
|
2014-04-24 19:14:37 +02:00
|
|
|
expect(view.clearMessages).toHaveBeenCalled();
|
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(view.model.messages.length, 0); // The messages must be removed from the chatbox
|
2014-06-30 19:21:16 +02:00
|
|
|
expect(view.model.messages.browserStorage.records.length, 0); // And also from browserStorage
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit.callCount, 1);
|
|
|
|
expect(_converse.emit.mostRecentCall.args, ['messageSend', message]);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Message Counter", function () {
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is incremented when the message is received and the window is not focused", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
expect(_converse.msg_counter).toBe(0);
|
|
|
|
spyOn(_converse, 'incrementMsgCounter').andCallThrough();
|
|
|
|
var previous_state = _converse.windowState;
|
2013-11-02 12:37:38 +01:00
|
|
|
var message = 'This message will increment the message counter';
|
2015-10-25 18:49:35 +01:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2013-11-02 12:37:38 +01:00
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2013-11-02 12:37:38 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.incrementMsgCounter).toHaveBeenCalled();
|
|
|
|
expect(_converse.msg_counter).toBe(1);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
_converse.windowSate = previous_state;
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is cleared when the window is focused", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
spyOn(_converse, 'clearMsgCounter').andCallThrough();
|
2013-11-02 12:37:38 +01:00
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
_converse.saveWindowState(null, 'blur');
|
2013-11-02 12:37:38 +01:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.clearMsgCounter).toHaveBeenCalled();
|
2013-11-02 12:37:38 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("is not incremented when the message is received and the window is focused", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.msg_counter).toBe(0);
|
|
|
|
spyOn(_converse, 'incrementMsgCounter').andCallThrough();
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
2013-11-02 12:37:38 +01:00
|
|
|
var message = 'This message will not increment the message counter';
|
2015-10-25 18:49:35 +01:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2013-11-02 12:37:38 +01:00
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2013-11-02 12:37:38 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.incrementMsgCounter).not.toHaveBeenCalled();
|
|
|
|
expect(_converse.msg_counter).toBe(0);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|