2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2014-10-15 19:16:02 +02:00
|
|
|
"jquery",
|
2013-11-02 12:37:38 +01:00
|
|
|
"mock",
|
2014-08-08 22:06:01 +02:00
|
|
|
"test_utils"
|
2014-10-15 19:16:02 +02:00
|
|
|
], function ($, mock, test_utils) {
|
|
|
|
return factory($, mock, test_utils);
|
2013-11-02 12:37:38 +01:00
|
|
|
}
|
|
|
|
);
|
2014-10-15 19:16:02 +02:00
|
|
|
} (this, function ($, mock, test_utils) {
|
2014-08-08 22:06:01 +02:00
|
|
|
return describe("Chatboxes", $.proxy(function(mock, test_utils) {
|
2013-11-02 12:37:38 +01:00
|
|
|
describe("A Chatbox", $.proxy(function () {
|
2013-11-03 10:38:48 +01:00
|
|
|
beforeEach(function () {
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
|
|
|
test_utils.removeControlBox();
|
|
|
|
test_utils.clearBrowserStorage();
|
|
|
|
test_utils.initConverse();
|
2014-08-18 20:37:38 +02:00
|
|
|
test_utils.createContacts('current');
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.openContactsPanel();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2014-01-19 06:02:18 +01:00
|
|
|
});
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("is created when you click on a roster item", $.proxy(function () {
|
2014-08-01 20:09:32 +02:00
|
|
|
var i, $el, click, 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.
|
2013-11-03 10:38:48 +01:00
|
|
|
expect(this.chatboxes.length).toEqual(1);
|
2014-05-27 19:18:02 +02:00
|
|
|
spyOn(this.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
|
|
|
|
2014-07-19 19:14:29 +02:00
|
|
|
var online_contacts = this.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();
|
2014-06-01 16:26:51 +02:00
|
|
|
chatboxview = this.chatboxviews.get(jid);
|
2013-11-03 10:38:48 +01:00
|
|
|
expect(this.chatboxes.length).toEqual(i+2);
|
2014-05-27 19:18:02 +02:00
|
|
|
expect(this.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
|
|
|
}
|
|
|
|
}, converse));
|
|
|
|
|
2014-06-01 17:57:03 +02:00
|
|
|
it("can be trimmed to conserve space", $.proxy(function () {
|
2014-08-01 20:09:32 +02:00
|
|
|
var i, $el, click, jid, key, chatbox, chatboxview;
|
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.
|
2014-06-16 00:03:34 +02:00
|
|
|
var trimmed_chatboxes = converse.minimized_chats;
|
2014-06-01 17:57:03 +02:00
|
|
|
expect(this.chatboxes.length).toEqual(1);
|
|
|
|
spyOn(this.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
|
2014-06-16 00:03:34 +02:00
|
|
|
runs($.proxy(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
|
|
|
}, this));
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
// Test that they can be maximized again
|
|
|
|
var online_contacts = this.rosterview.$el.find('dt.roster-group').siblings('dd.current-xmpp-contact').find('a.open-chat');
|
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
$el = $(online_contacts[i]);
|
|
|
|
jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
$el.click();
|
|
|
|
expect(this.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
|
|
|
|
chatboxview = this.chatboxviews.get(jid);
|
|
|
|
spyOn(chatboxview, 'hide').andCallThrough();
|
|
|
|
chatboxview.model.set({'minimized': true});
|
|
|
|
expect(trimmed_chatboxes.addChat).toHaveBeenCalled();
|
|
|
|
expect(chatboxview.hide).toHaveBeenCalled();
|
|
|
|
trimmedview = trimmed_chatboxes.get(jid);
|
|
|
|
}
|
2014-06-16 00:03:34 +02:00
|
|
|
var key = this.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();
|
2014-06-16 00:03:34 +02:00
|
|
|
}, this));
|
|
|
|
waits(250);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
expect(trimmedview.restore).toHaveBeenCalled();
|
|
|
|
expect(chatbox.maximize).toHaveBeenCalled();
|
|
|
|
expect(this.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
}, this));
|
2014-06-01 17:57:03 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-04-24 19:39:03 +02:00
|
|
|
it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-01 20:09:32 +02:00
|
|
|
var i, $el, click, 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.
|
|
|
|
expect(this.chatboxes.length).toEqual(1);
|
2014-08-08 22:06:01 +02:00
|
|
|
chatbox = test_utils.openChatBoxFor(contact_jid);
|
2014-04-24 19:39:03 +02:00
|
|
|
chatboxview = this.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(chatboxview, 'focus');
|
2014-10-27 23:06:11 +01:00
|
|
|
|
|
|
|
// Test that they can be trimmed
|
|
|
|
runs($.proxy(function () {
|
|
|
|
converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
|
|
|
}, this));
|
|
|
|
waits(50);
|
|
|
|
runs($.proxy(function () {
|
|
|
|
$el = this.rosterview.$el.find('a.open-chat:contains("'+chatbox.get('fullname')+'")');
|
|
|
|
jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
$el.click();
|
|
|
|
expect(this.chatboxes.length).toEqual(2);
|
|
|
|
expect(chatboxview.focus).toHaveBeenCalled();
|
|
|
|
}, this));
|
2014-04-24 19:39:03 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-06-30 19:21:16 +02:00
|
|
|
it("can be saved to, and retrieved from, browserStorage", $.proxy(function () {
|
2013-12-16 14:27:07 +01:00
|
|
|
spyOn(converse, 'emit');
|
2014-05-27 19:18:02 +02:00
|
|
|
spyOn(this.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 () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxes(6);
|
2014-05-27 19:18:02 +02:00
|
|
|
expect(this.chatboxviews.trimChats).toHaveBeenCalled();
|
2014-02-28 03:04:52 +01:00
|
|
|
// We instantiate a new ChatBoxes collection, which by default
|
|
|
|
// will be empty.
|
|
|
|
var newchatboxes = new this.ChatBoxes();
|
|
|
|
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.
|
|
|
|
attrs = ['id', 'box_id', 'visible'];
|
|
|
|
for (i=0; i<attrs.length; i++) {
|
|
|
|
new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
|
|
}
|
|
|
|
this.rosterview.render();
|
|
|
|
}.bind(converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2014-03-04 12:22:49 +01:00
|
|
|
it("can be closed by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
var chatbox = test_utils.openChatBoxes(1)[0],
|
2014-03-04 14:54:36 +01:00
|
|
|
controlview = this.chatboxviews.get('controlbox'), // The controlbox is currently open
|
|
|
|
chatview = this.chatboxviews.get(chatbox.get('jid'));
|
2014-05-27 18:34:22 +02:00
|
|
|
spyOn(chatview, 'close').andCallThrough();
|
|
|
|
spyOn(controlview, 'close').andCallThrough();
|
2013-12-16 14:27:07 +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();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2014-03-04 12:22:49 +01:00
|
|
|
expect(converse.emit.callCount, 1);
|
|
|
|
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();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2014-03-04 12:22:49 +01:00
|
|
|
expect(converse.emit.callCount, 2);
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2014-06-02 05:13:53 +02:00
|
|
|
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
var chatbox = test_utils.openChatBoxes(1)[0],
|
2014-06-01 20:09:09 +02:00
|
|
|
chatview = this.chatboxviews.get(chatbox.get('jid')),
|
2014-06-16 00:03:34 +02:00
|
|
|
trimmed_chatboxes = this.minimized_chats,
|
|
|
|
trimmedview;
|
2014-06-02 05:13:53 +02:00
|
|
|
spyOn(chatview, 'minimize').andCallThrough();
|
2014-03-04 19:16:39 +01:00
|
|
|
spyOn(converse, 'emit');
|
|
|
|
// 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();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
|
2014-03-04 19:16:39 +01:00
|
|
|
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();
|
2014-07-14 23:29:08 +02: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();
|
|
|
|
});
|
|
|
|
}.bind(converse));
|
|
|
|
|
2014-06-30 19:21:16 +02:00
|
|
|
it("will be removed from browserStorage when closed", $.proxy(function () {
|
2013-12-16 14:27:07 +01:00
|
|
|
spyOn(converse, 'emit');
|
2014-05-27 19:18:02 +02:00
|
|
|
spyOn(converse.chatboxviews, 'trimChats');
|
2014-06-30 19:21:16 +02:00
|
|
|
this.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 () {
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2014-09-22 12:55:14 +02:00
|
|
|
expect(converse.chatboxes.length).toEqual(1);
|
|
|
|
expect(converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxes(6);
|
2014-05-27 19:18:02 +02:00
|
|
|
expect(converse.chatboxviews.trimChats).toHaveBeenCalled();
|
2014-09-22 12:55:14 +02:00
|
|
|
expect(converse.chatboxes.length).toEqual(7);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxOpened', jasmine.any(Object));
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
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 () {
|
2014-09-22 12:55:14 +02:00
|
|
|
expect(converse.chatboxes.length).toEqual(1);
|
|
|
|
expect(converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2014-02-28 03:04:52 +01:00
|
|
|
var newchatboxes = new this.ChatBoxes();
|
|
|
|
expect(newchatboxes.length).toEqual(0);
|
2014-09-22 12:55:14 +02: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");
|
2014-02-28 03:04:52 +01:00
|
|
|
}.bind(converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
2013-11-03 21:28:44 +01:00
|
|
|
describe("A chat toolbar", $.proxy(function () {
|
|
|
|
it("can be found on each chat box", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2013-11-03 21:28:44 +01:00
|
|
|
var chatbox = this.chatboxes.get(contact_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = this.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);
|
2013-11-03 21:28:44 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("contains a button for inserting emoticons", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
2013-11-03 21:28:44 +01:00
|
|
|
var $toolbar = view.$el.find('ul.chat-toolbar');
|
|
|
|
var $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
|
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
$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 ');
|
|
|
|
});
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("contains a button for starting an encrypted chat session", $.proxy(function () {
|
|
|
|
// 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';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = this.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);
|
|
|
|
});
|
|
|
|
|
|
|
|
}, converse));
|
2013-12-18 03:52:16 +01:00
|
|
|
|
2014-04-24 19:14:37 +02:00
|
|
|
it("can contain a button for starting a call", $.proxy(function () {
|
|
|
|
var view, callButton, $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
|
|
|
spyOn(converse, 'emit');
|
|
|
|
// First check that the button doesn't show if it's not enabled
|
|
|
|
// via "visible_toolbar_buttons"
|
2014-04-25 22:56:59 +02:00
|
|
|
converse.visible_toolbar_buttons.call = false;
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
view = this.chatboxviews.get(contact_jid);
|
|
|
|
$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
|
2014-04-25 22:56:59 +02:00
|
|
|
converse.visible_toolbar_buttons.call = true; // enable the button
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
view = this.chatboxviews.get(contact_jid);
|
|
|
|
$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();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
|
2014-04-24 19:14:37 +02:00
|
|
|
}, converse));
|
2013-12-18 03:52:16 +01:00
|
|
|
|
2014-04-24 19:14:37 +02:00
|
|
|
it("can contain a button for clearing messages", $.proxy(function () {
|
|
|
|
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"
|
2014-04-25 22:56:59 +02:00
|
|
|
converse.visible_toolbar_buttons.clear = false;
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
view = this.chatboxviews.get(contact_jid);
|
|
|
|
view = this.chatboxviews.get(contact_jid);
|
|
|
|
$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
|
2014-04-25 22:56:59 +02:00
|
|
|
converse.visible_toolbar_buttons.clear = true; // enable the button
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-04-24 19:14:37 +02:00
|
|
|
view = this.chatboxviews.get(contact_jid);
|
|
|
|
$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();
|
2013-12-18 03:52:16 +01:00
|
|
|
}, converse));
|
2014-04-24 19:14:37 +02:00
|
|
|
|
2013-11-03 21:28:44 +01:00
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
describe("A Chat Message", $.proxy(function () {
|
2014-03-05 00:23:45 +01:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
2014-03-05 00:23:45 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {});
|
|
|
|
});
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can be received which will open a chatbox and be displayed inside it", $.proxy(function () {
|
2013-12-16 14:27:07 +01:00
|
|
|
spyOn(converse, 'emit');
|
2013-11-02 12:37:38 +01:00
|
|
|
var message = 'This is a received message';
|
2014-06-30 20:26:45 +02:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2015-01-01 21:25:12 +01:00
|
|
|
var msg = $msg({
|
2013-11-02 12:37:38 +01:00
|
|
|
from: sender_jid,
|
|
|
|
to: this.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(this.chatboxes.get(sender_jid)).not.toBeDefined();
|
|
|
|
|
|
|
|
runs($.proxy(function () {
|
2014-03-05 00:23:45 +01:00
|
|
|
// onMessage is a handler for received XMPP messages
|
|
|
|
this.chatboxes.onMessage(msg);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
2014-04-18 17:42:11 +02:00
|
|
|
waits(250);
|
2013-11-02 12:37:38 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
// Check that the chatbox and its view now exist
|
|
|
|
var chatbox = this.chatboxes.get(sender_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var chatboxview = this.chatboxviews.get(sender_jid);
|
2013-11-02 12:37:38 +01: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);
|
|
|
|
// XXX: This is stupid, fullname is actually only the
|
|
|
|
// users first name
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(mock.cur_names[0].split(' ')[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-message-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
var sender_txt = $chat_content.find('span.chat-message-them').text();
|
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
|
|
|
|
2014-03-09 12:10:57 +01:00
|
|
|
it("received for a minimized chat box will increment a counter on its header", $.proxy(function () {
|
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';
|
2014-03-05 01:10:29 +01:00
|
|
|
spyOn(this, 'emit');
|
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-05 01:10:29 +01:00
|
|
|
var chatview = converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
});
|
2014-06-02 21:51:30 +02:00
|
|
|
waits(50);
|
2014-03-05 01:10:29 +01:00
|
|
|
runs($.proxy(function () {
|
|
|
|
var chatview = this.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
var message = 'This message is sent to a minimized chatbox';
|
2014-06-30 20:26:45 +02:00
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-03-09 12:10:57 +01:00
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2014-03-05 01:10:29 +01:00
|
|
|
this.chatboxes.onMessage(msg);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(this.emit).toHaveBeenCalledWith('message', msg);
|
2014-03-05 01:10:29 +01:00
|
|
|
}, converse));
|
2014-06-02 21:51:30 +02:00
|
|
|
waits(50);
|
2014-03-05 01:10:29 +01:00
|
|
|
runs($.proxy(function () {
|
2014-06-16 00:03:34 +02:00
|
|
|
var trimmed_chatboxes = this.minimized_chats;
|
2014-06-02 21:51:30 +02:00
|
|
|
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
|
|
|
var $count = trimmedview.$el.find('.chat-head-message-count');
|
2014-06-04 09:32:40 +02:00
|
|
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
2014-03-09 12:10:57 +01:00
|
|
|
expect($count.is(':visible')).toBeTruthy();
|
|
|
|
expect($count.html()).toBe('1');
|
|
|
|
this.chatboxes.onMessage(
|
|
|
|
$msg({
|
2014-06-30 20:26:45 +02:00
|
|
|
from: mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2014-03-09 12:10:57 +01:00
|
|
|
to: this.connection.jid,
|
|
|
|
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()
|
|
|
|
);
|
|
|
|
}, converse));
|
2014-06-02 21:51:30 +02:00
|
|
|
waits(50);
|
2014-03-09 12:10:57 +01:00
|
|
|
runs($.proxy(function () {
|
2014-06-16 00:03:34 +02:00
|
|
|
var trimmed_chatboxes = this.minimized_chats;
|
2014-06-04 09:32:40 +02:00
|
|
|
var trimmedview = trimmed_chatboxes.get(contact_jid);
|
|
|
|
var $count = trimmedview.$el.find('.chat-head-message-count');
|
|
|
|
expect(trimmedview.model.get('minimized')).toBeTruthy();
|
2014-03-09 12:10:57 +01:00
|
|
|
expect($count.is(':visible')).toBeTruthy();
|
|
|
|
expect($count.html()).toBe('2');
|
2014-06-04 09:32:40 +02:00
|
|
|
trimmedview.$el.find('.restore-chat').click();
|
2014-03-09 12:10:57 +01:00
|
|
|
}, converse));
|
2014-06-21 11:46:23 +02:00
|
|
|
waits(250);
|
2014-03-09 12:10:57 +01:00
|
|
|
runs($.proxy(function () {
|
2014-06-16 00:03:34 +02:00
|
|
|
var trimmed_chatboxes = this.minimized_chats;
|
2014-06-21 11:46:23 +02:00
|
|
|
expect(trimmed_chatboxes.keys().length).toBe(0);
|
2014-03-05 01:10:29 +01:00
|
|
|
}, converse));
|
|
|
|
}, converse));
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2014-03-14 20:52:03 +01:00
|
|
|
it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () {
|
2013-12-16 14:27:07 +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';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
test_utils.clearChatBoxMessages(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';
|
|
|
|
var chatbox = this.chatboxes.get(contact_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var chatboxview = this.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,
|
|
|
|
to: this.connection.jid,
|
|
|
|
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();
|
2014-03-05 00:23:45 +01:00
|
|
|
this.chatboxes.onMessage(msg);
|
2014-07-14 23:29:08 +02:00
|
|
|
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);
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(contact_name.split(' ')[0]);
|
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(true);
|
|
|
|
msg_txt = $chat_content.find('.chat-message').find('.chat-message-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
sender_txt = $chat_content.find('span.chat-message-them').text();
|
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
|
|
|
|
|
|
|
message = 'This is a current message';
|
2013-12-16 14:27:07 +01:00
|
|
|
msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: new Date().getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2014-03-05 00:23:45 +01:00
|
|
|
this.chatboxes.onMessage(msg);
|
2014-07-14 23:29:08 +02:00
|
|
|
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.
|
|
|
|
var $time = $chat_content.find('time');
|
|
|
|
var message_date = new Date();
|
|
|
|
expect($time.length).toEqual(1);
|
|
|
|
expect($time.attr('class')).toEqual('chat-date');
|
2014-04-19 01:30:48 +02:00
|
|
|
expect($time.attr('datetime')).toEqual(moment(message_date).format("YYYY-MM-DD"));
|
2014-04-25 22:56:59 +02:00
|
|
|
expect($time.text()).toEqual(moment(message_date).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);
|
|
|
|
expect(msg_obj.get('fullname')).toEqual(contact_name.split(' ')[0]);
|
|
|
|
expect(msg_obj.get('sender')).toEqual('them');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
|
|
|
msg_txt = $chat_content.find('.chat-message').last().find('.chat-message-content').text();
|
|
|
|
expect(msg_txt).toEqual(message);
|
|
|
|
sender_txt = $chat_content.find('span.chat-message-them').last().text();
|
|
|
|
expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy();
|
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
|
2013-12-16 14:27:07 +01:00
|
|
|
spyOn(converse, 'emit');
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-02-28 03:04:52 +01:00
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
2014-02-28 03:04:52 +01:00
|
|
|
var message = 'This message is sent from this chatbox';
|
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-02-28 03:04:52 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
expect(view.model.messages.length, 2);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit.mostRecentCall.args, ['messageSend', message]);
|
2014-03-09 05:02:38 +01:00
|
|
|
expect(view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text()).toEqual(message);
|
2014-02-28 03:04:52 +01:00
|
|
|
}.bind(converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
2013-12-18 03:15:27 +01:00
|
|
|
|
2014-03-05 03:29:10 +01:00
|
|
|
it("is sanitized to prevent Javascript injection attacks", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = this.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();
|
2014-03-05 03:29:10 +01:00
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<p>This message contains <em>some</em> <b>markup</b></p>');
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can contain hyperlinks, which will be clickable", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-09 05:02:38 +01:00
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
2014-03-05 03:29:10 +01:00
|
|
|
var message = 'This message contains a hyperlink: www.opkode.com';
|
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-03-05 03:29:10 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('This message contains a hyperlink: <a target="_blank" href="http://www.opkode.com">www.opkode.com</a>');
|
|
|
|
}, converse));
|
|
|
|
|
2014-05-19 16:06:11 +02:00
|
|
|
it("should display emoticons correctly", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-05-19 16:06:11 +02:00
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
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();
|
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.html()).toEqual(emoticons[i]);
|
2014-05-19 16:06:11 +02:00
|
|
|
}
|
|
|
|
}, converse));
|
2014-03-05 03:29:10 +01:00
|
|
|
|
|
|
|
it("will have properly escaped URLs", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-09 05:02:38 +01:00
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
2014-03-05 03:29:10 +01:00
|
|
|
spyOn(view, 'sendMessage').andCallThrough();
|
|
|
|
|
|
|
|
var message = "http://www.opkode.com/'onmouseover='alert(1)'whatever";
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-03-05 03:29:10 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" href="http://www.opkode.com/%27onmouseover=%27alert%281%29%27whatever">http://www.opkode.com/\'onmouseover=\'alert(1)\'whatever</a>');
|
|
|
|
|
2014-03-09 04:51:21 +01:00
|
|
|
message = 'http://www.opkode.com/"onmouseover="alert(1)"whatever';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-03-09 04:51:21 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" 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
|
|
|
message = "https://en.wikipedia.org/wiki/Ender's_Game";
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-03-05 03:29:10 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender\'s_Game</a>');
|
|
|
|
|
|
|
|
message = "https://en.wikipedia.org/wiki/Ender%27s_Game";
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
2014-03-05 03:29:10 +01:00
|
|
|
expect(view.sendMessage).toHaveBeenCalled();
|
|
|
|
msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content');
|
|
|
|
expect(msg.text()).toEqual(message);
|
|
|
|
expect(msg.html()).toEqual('<a target="_blank" href="https://en.wikipedia.org/wiki/Ender%27s_Game">https://en.wikipedia.org/wiki/Ender%27s_Game</a>');
|
2013-12-18 03:15:27 +01:00
|
|
|
}, converse));
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
2015-01-01 21:25:12 +01:00
|
|
|
|
|
|
|
describe("A Chat Status Notification", $.proxy(function () {
|
|
|
|
|
2015-01-09 09:02:35 +01:00
|
|
|
describe("An active notification", $.proxy(function () {
|
|
|
|
it("is sent when the user opens a chat box", $.proxy(function () {
|
|
|
|
spyOn(converse.connection, 'send');
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
expect(converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
|
|
|
expect($stanza.children().prop('tagName')).toBe('active');
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("is sent when the user maximizes a minimized a chat box", $.proxy(function () {
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
view.minimize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
|
|
|
spyOn(converse.connection, 'send');
|
|
|
|
view.maximize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
expect(converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
|
|
|
expect($stanza.children().prop('tagName')).toBe('active');
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("A composing notification", $.proxy(function () {
|
2015-01-01 21:25:12 +01:00
|
|
|
it("is sent as soon as the user starts typing a message which is not a command", $.proxy(function () {
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
spyOn(this.connection, 'send');
|
|
|
|
view.keyPressed({
|
|
|
|
target: view.$el.find('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
expect(this.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(this.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
|
|
|
expect($stanza.children().prop('tagName')).toBe('composing');
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2015-01-01 21:25:12 +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');
|
|
|
|
expect(converse.emit.callCount, 1);
|
|
|
|
}, converse));
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
it("will be shown if received", $.proxy(function () {
|
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
|
|
|
|
// <composing> state
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
this.chatboxes.onMessage(msg);
|
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var chatboxview = this.chatboxviews.get(sender_jid);
|
|
|
|
expect(chatboxview).toBeDefined();
|
|
|
|
// Check that the notification appears inside the chatbox in the DOM
|
|
|
|
var $events = chatboxview.$el.find('.chat-event');
|
|
|
|
expect($events.length).toBe(1);
|
|
|
|
expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' is typing');
|
|
|
|
}, converse));
|
2015-01-01 21:25:12 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("A paused notification", $.proxy(function () {
|
|
|
|
it("is sent if the user has stopped typing since 30 seconds", $.proxy(function () {
|
|
|
|
this.TIMEOUTS.PAUSED = 200; // Make the timeout shorter so that we can test
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
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');
|
|
|
|
spyOn(converse.connection, 'send');
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('paused');
|
|
|
|
expect(converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
|
|
|
expect($stanza.children().prop('tagName')).toBe('paused');
|
|
|
|
});
|
|
|
|
}, converse));
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
it("will be shown if received", $.proxy(function () {
|
|
|
|
// TODO: only show paused state if the previous state was composing
|
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
|
|
|
spyOn(converse, 'emit');
|
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
// <paused> state
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
this.chatboxes.onMessage(msg);
|
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var chatboxview = this.chatboxviews.get(sender_jid);
|
|
|
|
$events = chatboxview.$el.find('.chat-event');
|
|
|
|
expect($events.length).toBe(1);
|
|
|
|
expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' has stopped typing');
|
|
|
|
}, converse));
|
2015-01-01 21:25:12 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("An inactive notifciation", $.proxy(function () {
|
|
|
|
it("is sent if the user has stopped typing since 2 minutes", $.proxy(function () {
|
|
|
|
// Make the timeouts shorter so that we can test
|
2015-01-09 09:02:35 +01:00
|
|
|
this.TIMEOUTS.PAUSED = 200;
|
2015-01-01 21:25:12 +01:00
|
|
|
this.TIMEOUTS.INACTIVE = 200;
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
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');
|
|
|
|
spyOn(converse.connection, 'send');
|
|
|
|
});
|
|
|
|
waits(250);
|
|
|
|
runs(function () {
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
|
|
|
expect(converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
|
|
|
expect($stanza.children().prop('tagName')).toBe('inactive');
|
|
|
|
});
|
|
|
|
}, converse));
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
it("is sent when the user a minimizes a chat box", $.proxy(function () {
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(converse.connection, 'send');
|
|
|
|
view.minimize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
|
|
|
expect(converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
|
|
|
expect($stanza.children().prop('tagName')).toBe('inactive');
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("is sent if the user closes a chat box", $.proxy(function () {
|
2015-01-01 21:25:12 +01:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
|
|
|
var view = this.chatboxviews.get(contact_jid);
|
2015-01-09 09:02:35 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
spyOn(converse.connection, 'send');
|
|
|
|
view.close();
|
2015-01-09 10:48:36 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
2015-01-09 09:02:35 +01:00
|
|
|
expect(converse.connection.send).toHaveBeenCalled();
|
|
|
|
var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
expect($stanza.children().length).toBe(1);
|
2015-01-09 10:48:36 +01:00
|
|
|
expect($stanza.children().prop('tagName')).toBe('inactive');
|
2015-01-01 21:25:12 +01:00
|
|
|
}, converse));
|
|
|
|
|
2015-01-09 10:48:36 +01:00
|
|
|
it("will clear any other chat status notifications if its received", $.proxy(function () {
|
2015-01-09 09:02:35 +01:00
|
|
|
// See XEP-0085 http://xmpp.org/extensions/xep-0085.html#definitions
|
2015-01-09 10:48:36 +01:00
|
|
|
spyOn(converse, 'emit');
|
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(sender_jid);
|
|
|
|
var view = this.chatboxviews.get(sender_jid);
|
|
|
|
expect(view.$el.find('.chat-event').length).toBe(0);
|
|
|
|
view.showStatusNotification(sender_jid+' '+'is typing');
|
|
|
|
expect(view.$el.find('.chat-event').length).toBe(1);
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
this.chatboxes.onMessage(msg);
|
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
expect(view.$el.find('.chat-event').length).toBe(0);
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("A gone notifciation", $.proxy(function () {
|
|
|
|
it("will be shown if received", $.proxy(function () {
|
2015-01-09 09:02:35 +01:00
|
|
|
spyOn(converse, 'emit');
|
|
|
|
var sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
// <paused> state
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('gone', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
this.chatboxes.onMessage(msg);
|
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
|
|
|
var chatboxview = this.chatboxviews.get(sender_jid);
|
|
|
|
$events = chatboxview.$el.find('.chat-event');
|
|
|
|
expect($events.length).toBe(1);
|
2015-01-09 10:48:36 +01:00
|
|
|
expect($events.text()).toEqual(mock.cur_names[1].split(' ')[0] + ' has gone away');
|
2015-01-09 09:02:35 +01:00
|
|
|
}, converse));
|
|
|
|
}, converse));
|
2015-01-01 21:25:12 +01:00
|
|
|
}, converse));
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("Special Messages", $.proxy(function () {
|
2014-03-05 03:29:10 +01:00
|
|
|
beforeEach(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
|
|
|
test_utils.removeControlBox();
|
2014-08-03 23:02:25 +02:00
|
|
|
converse.roster.browserStorage._clear();
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.initConverse();
|
2014-08-18 20:37:38 +02:00
|
|
|
test_utils.createContacts('current');
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.openContactsPanel();
|
2014-03-05 03:29:10 +01:00
|
|
|
});
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
it("'/clear' can be used to clear messages in a conversation", $.proxy(function () {
|
2013-12-16 14:27:07 +01:00
|
|
|
spyOn(converse, 'emit');
|
2013-11-02 12:37:38 +01:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = this.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();
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('messageSend', message);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
|
|
|
message = '/clear';
|
|
|
|
var old_length = view.model.messages.length;
|
|
|
|
spyOn(view, 'sendMessage').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);
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(view.sendMessage).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
|
2013-12-16 14:27:07 +01:00
|
|
|
expect(converse.emit.callCount, 1);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit.mostRecentCall.args, ['messageSend', message]);
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
describe("A Message Counter", $.proxy(function () {
|
|
|
|
beforeEach($.proxy(function () {
|
|
|
|
converse.clearMsgCounter();
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("is incremented when the message is received and the window is not focused", $.proxy(function () {
|
2013-12-16 14:27:07 +01:00
|
|
|
spyOn(converse, 'emit');
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(this.msg_counter).toBe(0);
|
|
|
|
spyOn(converse, 'incrementMsgCounter').andCallThrough();
|
|
|
|
$(window).trigger('blur');
|
|
|
|
var message = 'This message will increment the message counter';
|
2014-06-30 20:26:45 +02: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,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2014-03-05 00:23:45 +01:00
|
|
|
this.chatboxes.onMessage(msg);
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(converse.incrementMsgCounter).toHaveBeenCalled();
|
|
|
|
expect(this.msg_counter).toBe(1);
|
2014-07-14 23:29:08 +02:00
|
|
|
expect(converse.emit).toHaveBeenCalledWith('message', msg);
|
2013-11-02 12:37:38 +01:00
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("is cleared when the window is focused", $.proxy(function () {
|
|
|
|
spyOn(converse, 'clearMsgCounter').andCallThrough();
|
|
|
|
runs(function () {
|
2014-04-19 01:52:44 +02:00
|
|
|
$(window).triggerHandler('blur');
|
|
|
|
$(window).triggerHandler('focus');
|
2013-11-02 12:37:38 +01:00
|
|
|
});
|
|
|
|
waits(50);
|
|
|
|
runs(function () {
|
|
|
|
expect(converse.clearMsgCounter).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("is not incremented when the message is received and the window is focused", $.proxy(function () {
|
|
|
|
expect(this.msg_counter).toBe(0);
|
|
|
|
spyOn(converse, 'incrementMsgCounter').andCallThrough();
|
|
|
|
$(window).trigger('focus');
|
|
|
|
var message = 'This message will not increment the message counter';
|
2014-06-30 20:26:45 +02: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,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t(message).up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2014-03-05 00:23:45 +01:00
|
|
|
this.chatboxes.onMessage(msg);
|
2013-11-02 12:37:38 +01:00
|
|
|
expect(converse.incrementMsgCounter).not.toHaveBeenCalled();
|
|
|
|
expect(this.msg_counter).toBe(0);
|
|
|
|
}, converse));
|
|
|
|
}, converse));
|
2014-08-08 22:06:01 +02:00
|
|
|
}, converse, mock, test_utils));
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|