2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2018-01-04 12:41:03 +01:00
|
|
|
"jquery",
|
2017-06-19 11:08:57 +02:00
|
|
|
"jasmine",
|
2016-03-28 12:49:52 +02:00
|
|
|
"utils",
|
2017-02-14 15:08:39 +01:00
|
|
|
"converse-core",
|
2013-11-02 12:37:38 +01:00
|
|
|
"mock",
|
2017-04-05 11:01:31 +02:00
|
|
|
"test-utils"
|
2016-03-28 12:49:52 +02:00
|
|
|
], factory);
|
2017-07-11 10:41:11 +02:00
|
|
|
} (this, function ($, jasmine, 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._;
|
2017-12-03 12:21:57 +01:00
|
|
|
var $iq = converse.env.$iq;
|
2016-12-20 10:30:20 +01:00
|
|
|
var $msg = converse.env.$msg;
|
|
|
|
var Strophe = converse.env.Strophe;
|
2018-01-03 20:02:05 +01:00
|
|
|
var u = converse.env.utils;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2018-02-02 19:33:19 +01:00
|
|
|
return describe("Chatboxes", function () {
|
2018-04-16 18:08:00 +02:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Chatbox", function () {
|
2014-01-19 06:02:18 +01:00
|
|
|
|
2018-01-15 18:41:04 +01:00
|
|
|
it("has a /help command to show the available commands",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.openControlBox();
|
|
|
|
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
test_utils.sendMessage(view, '/help');
|
|
|
|
|
|
|
|
const info_messages = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info:not(.chat-date)'), 0);
|
|
|
|
expect(info_messages.length).toBe(3);
|
|
|
|
expect(info_messages.pop().textContent).toBe('/help: Show this menu');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/me: Write in the third person');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/clear: Remove messages');
|
2018-01-15 20:32:24 +01:00
|
|
|
|
|
|
|
var msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('hello world').tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(view.content.lastElementChild.textContent.trim().indexOf('hello world')).not.toBe(-1);
|
2018-01-15 18:41:04 +01:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("supports the /me command",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2018-03-13 19:11:49 +01:00
|
|
|
var view;
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2018-02-08 09:49:05 +01:00
|
|
|
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
|
2018-05-02 14:55:10 +02:00
|
|
|
.then(() => test_utils.waitUntil(() => _converse.xmppstatus.get('fullname')), 300)
|
2017-12-03 12:21:57 +01:00
|
|
|
.then(function () {
|
|
|
|
test_utils.openControlBox();
|
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var message = '/me is tired';
|
|
|
|
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();
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
2018-03-13 19:11:49 +01:00
|
|
|
view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return u.isVisible(view.el);
|
|
|
|
}).then(function () {
|
2018-05-02 14:55:10 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-action').length).toBe(1);
|
2018-03-13 19:11:49 +01:00
|
|
|
expect(_.includes(view.el.querySelector('.chat-msg-author').textContent, '**Max Frankfurter')).toBeTruthy();
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($(view.el).find('.chat-msg-text').text()).toBe(' is tired');
|
2018-03-13 19:11:49 +01:00
|
|
|
|
|
|
|
message = '/me is as well';
|
|
|
|
test_utils.sendMessage(view, message);
|
2018-05-02 14:55:10 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-action').length).toBe(2);
|
2018-05-03 20:05:45 +02:00
|
|
|
|
|
|
|
return test_utils.waitUntil(() => $(view.el).find('.chat-msg-author:last').text() === '**Max Mustermann');
|
|
|
|
}).then(function () {
|
2018-04-27 16:58:49 +02:00
|
|
|
expect($(view.el).find('.chat-msg-text:last').text()).toBe(' is as well');
|
2018-04-30 16:23:52 +02:00
|
|
|
expect($(view.el).find('.chat-msg:last').hasClass('chat-msg-followup')).toBe(false);
|
2018-05-02 14:55:10 +02:00
|
|
|
|
|
|
|
// Check that /me messages after a normal message don't
|
|
|
|
// get the 'chat-msg-followup' class.
|
|
|
|
message = 'This a normal message';
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
let message_el = view.el.querySelector('.message:last-child');
|
|
|
|
expect(u.hasClass('chat-msg-followup', message_el)).toBeFalsy();
|
|
|
|
|
|
|
|
message = '/me wrote a 3rd person message';
|
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
message_el = view.el.querySelector('.message:last-child');
|
|
|
|
expect(view.el.querySelectorAll('.chat-action').length).toBe(3);
|
|
|
|
expect($(view.el).find('.chat-msg-text:last').text()).toBe(' wrote a 3rd person message');
|
|
|
|
expect($(view.el).find('.chat-msg-author:last').is(':visible')).toBeTruthy();
|
|
|
|
expect(u.hasClass('chat-msg-followup', message_el)).toBeFalsy();
|
|
|
|
|
|
|
|
|
|
|
|
message = 'This a normal message';
|
|
|
|
|
2018-03-13 19:11:49 +01:00
|
|
|
done();
|
|
|
|
});
|
2017-12-03 12:21:57 +01:00
|
|
|
});
|
2017-02-15 22:03:02 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("is created when you click on a roster item",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
|
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
|
|
|
|
2017-12-20 20:29:57 +01:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group li').length;
|
2017-12-20 20:29:57 +01:00
|
|
|
}, 700).then(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
var online_contacts = $(_converse.rosterview.el).find('.roster-group .current-xmpp-contact a.open-chat');
|
2017-12-20 20:29:57 +01:00
|
|
|
expect(online_contacts.length).toBe(15);
|
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
$el = $(online_contacts[i]);
|
|
|
|
jid = $el.text().trim().replace(/ /g,'.').toLowerCase() + '@localhost';
|
2018-01-03 20:02:05 +01:00
|
|
|
$el[0].click();
|
2017-12-20 20:29:57 +01:00
|
|
|
chatboxview = _converse.chatboxviews.get(jid);
|
|
|
|
expect(_converse.chatboxes.length).toEqual(i+2);
|
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
// 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'));
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be trimmed to conserve space",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(trimmed_chatboxes, 'addChat').and.callThrough();
|
|
|
|
spyOn(trimmed_chatboxes, 'removeChat').and.callThrough();
|
2014-06-01 17:57:03 +02:00
|
|
|
expect($("#conversejs .chatbox").length).toBe(1); // Controlbox is open
|
|
|
|
|
2017-12-20 20:29:57 +01:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attached.
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group li').length;
|
2017-12-20 20:29:57 +01:00
|
|
|
}, 700).then(function () {
|
2014-10-27 23:06:11 +01:00
|
|
|
// Test that they can be maximized again
|
2018-01-03 20:02:05 +01:00
|
|
|
var online_contacts = $(_converse.rosterview.el).find('.roster-group .current-xmpp-contact a.open-chat');
|
2017-12-20 13:17:58 +01:00
|
|
|
expect(online_contacts.length).toBe(15);
|
2014-10-27 23:06:11 +01:00
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
$el = $(online_contacts[i]);
|
2017-12-20 13:17:58 +01:00
|
|
|
jid = _.trim($el.text().trim()).replace(/ /g,'.').toLowerCase() + '@localhost';
|
2018-01-03 20:02:05 +01:00
|
|
|
$el[0].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);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(chatboxview, 'minimize').and.callThrough();
|
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
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
2017-12-20 13:17:58 +01:00
|
|
|
return _converse.chatboxviews.keys().length > 1;
|
|
|
|
}, 500);
|
2017-04-05 11:01:31 +02:00
|
|
|
}).then(function () {
|
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;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(chatbox, 'maximize').and.callThrough();
|
|
|
|
spyOn(trimmedview, 'restore').and.callThrough();
|
2014-06-16 00:03:34 +02:00
|
|
|
trimmedview.delegateEvents();
|
2018-01-03 20:02:05 +01:00
|
|
|
trimmedview.el.querySelector("a.restore-chat").click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be opened in minimized mode initially",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-23 15:38:48 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2018-03-13 19:11:49 +01:00
|
|
|
var chat = _converse.api.chats.create(sender_jid, {
|
2017-04-23 15:38:48 +02:00
|
|
|
minimized: true
|
|
|
|
});
|
|
|
|
|
|
|
|
var chatBoxView = _converse.chatboxviews.get(sender_jid);
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatBoxView.el)).toBeFalsy();
|
2017-04-23 15:38:48 +02:00
|
|
|
|
|
|
|
var minimized_chat = _converse.minimized_chats.get(sender_jid);
|
|
|
|
expect(minimized_chat).toBeTruthy();
|
2018-01-03 20:02:05 +01:00
|
|
|
expect($(minimized_chat.el).is(':visible')).toBeTruthy();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-04-23 15:38:48 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is focused if its already open and you click on its corresponding roster item",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2017-07-11 10:41:11 +02:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced.
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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';
|
2017-07-11 10:41:11 +02:00
|
|
|
var $el, jid, 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);
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
chatbox = test_utils.openChatBoxFor(_converse, contact_jid);
|
2018-05-05 20:28:41 +02:00
|
|
|
$el = $(_converse.rosterview.el).find('a.open-chat:contains("'+chatbox.getDisplayName()+'")');
|
2017-07-11 10:41:11 +02:00
|
|
|
jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost';
|
2018-03-14 14:03:13 +01:00
|
|
|
|
|
|
|
spyOn(_converse, 'emit');
|
2018-01-03 20:02:05 +01:00
|
|
|
$el[0].click();
|
2018-03-14 14:03:13 +01:00
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _converse.emit.calls.count();
|
|
|
|
}, 300).then(function () {
|
|
|
|
expect(_converse.chatboxes.length).toEqual(2);
|
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('chatBoxFocused', jasmine.any(Object));
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be saved to, and retrieved from, browserStorage",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2014-04-24 19:39:03 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
|
|
|
|
test_utils.openChatBoxes(_converse, 6);
|
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
// We instantiate a new ChatBoxes collection, which by default
|
|
|
|
// will be empty.
|
|
|
|
var newchatboxes = new _converse.ChatBoxes();
|
|
|
|
expect(newchatboxes.length).toEqual(0);
|
|
|
|
// The chatboxes will then be fetched from browserStorage inside the
|
|
|
|
// onConnected method
|
|
|
|
newchatboxes.onConnected();
|
|
|
|
expect(newchatboxes.length).toEqual(7);
|
|
|
|
// Check that the chatboxes items retrieved from browserStorage
|
|
|
|
// have the same attributes values as the original ones.
|
|
|
|
var attrs = ['id', 'box_id', 'visible'];
|
|
|
|
var new_attrs, old_attrs;
|
|
|
|
for (var i=0; i<attrs.length; i++) {
|
|
|
|
new_attrs = _.map(_.map(newchatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
old_attrs = _.map(_.map(_converse.chatboxes.models, 'attributes'), attrs[i]);
|
|
|
|
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
|
|
|
|
}
|
|
|
|
_converse.rosterview.render();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be closed by clicking a DOM element with class 'close-chatbox-button'",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-03-14 14:03:13 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
|
|
|
}, 300).then(function () {
|
2017-04-05 11:01:31 +02: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'));
|
|
|
|
spyOn(chatview, 'close').and.callThrough();
|
|
|
|
spyOn(controlview, 'close').and.callThrough();
|
|
|
|
spyOn(_converse, 'emit');
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2017-04-05 11:01:31 +02: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
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
controlview.el.querySelector('.close-chatbox-button').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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));
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.emit.calls.count(), 1);
|
2018-01-03 20:02:05 +01:00
|
|
|
chatview.el.querySelector('.close-chatbox-button').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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));
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.emit.calls.count(), 2);
|
|
|
|
done();
|
2014-02-28 03:04:52 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
var chatview;
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-04-05 11:01:31 +02:00
|
|
|
}, 300)
|
|
|
|
.then(function () {
|
|
|
|
var chatbox = test_utils.openChatBoxes(_converse, 1)[0],
|
|
|
|
trimmed_chatboxes = _converse.minimized_chats,
|
|
|
|
trimmedview;
|
|
|
|
chatview = _converse.chatboxviews.get(chatbox.get('jid'));
|
|
|
|
spyOn(chatview, 'minimize').and.callThrough();
|
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
// We need to rebind all events otherwise our spy won't be called
|
|
|
|
chatview.delegateEvents();
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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));
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.emit.calls.count(), 2);
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(chatview.el)).toBeFalsy();
|
2014-03-04 19:16:39 +01:00
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
2018-01-03 20:02:05 +01:00
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
2014-06-01 20:09:09 +02:00
|
|
|
trimmedview = trimmed_chatboxes.get(chatview.model.get('id'));
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(trimmedview, 'restore').and.callThrough();
|
2014-06-16 00:03:34 +02:00
|
|
|
trimmedview.delegateEvents();
|
2018-01-03 20:02:05 +01:00
|
|
|
trimmedview.el.querySelector("a.restore-chat").click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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));
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(chatview.el).find('.chat-body').is(':visible');
|
2017-06-12 20:30:58 +02:00
|
|
|
}, 500);
|
2017-04-05 11:01:31 +02:00
|
|
|
}).then(function () {
|
2018-03-14 20:01:33 +01:00
|
|
|
expect($(chatview.el).find('.toggle-chatbox-button').hasClass('fa-minus')).toBeTruthy();
|
|
|
|
expect($(chatview.el).find('.toggle-chatbox-button').hasClass('fa-plus')).toBeFalsy();
|
2014-03-04 19:16:39 +01:00
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2014-03-04 19:16:39 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be removed from browserStorage when closed",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-03-17 00:37:52 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
|
|
|
}, 300).then(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
|
|
|
_converse.chatboxes.browserStorage._clear();
|
2014-03-04 19:16:39 +01:00
|
|
|
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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);
|
2017-04-05 11:01:31 +02:00
|
|
|
|
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");
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
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
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be found on each chat box",
|
2017-07-15 07:09:59 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
|
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();
|
2018-01-03 20:02:05 +01:00
|
|
|
var $toolbar = $(view.el).find('ul.chat-toolbar');
|
2013-11-03 21:28:44 +01:00
|
|
|
expect($toolbar.length).toBe(1);
|
2018-04-16 14:22:27 +02:00
|
|
|
expect($toolbar.children('li').length).toBe(2);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("contains a button for inserting emojis",
|
2017-07-15 07:09:59 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2013-11-03 21:28:44 +01:00
|
|
|
|
2017-11-17 11:13:27 +01:00
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2017-07-15 15:15:37 +02:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
2017-11-17 11:13:27 +01:00
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
var toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
|
|
expect(toolbar.querySelectorAll('li.toggle-smiley').length).toBe(1);
|
2017-07-15 15:15:37 +02:00
|
|
|
// Register spies
|
|
|
|
spyOn(view, 'toggleEmojiMenu').and.callThrough();
|
|
|
|
spyOn(view, 'insertEmoji').and.callThrough();
|
|
|
|
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2017-11-17 11:13:27 +01:00
|
|
|
toolbar.querySelector('li.toggle-smiley').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2018-03-14 18:25:34 +01:00
|
|
|
var timeout = false;
|
|
|
|
|
2017-07-15 15:15:37 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2017-11-17 11:13:27 +01:00
|
|
|
return utils.isVisible(view.el.querySelector('.toggle-smiley .emoji-picker-container'));
|
|
|
|
}, 150).then(function () {
|
|
|
|
var picker = view.el.querySelector('.toggle-smiley .emoji-picker-container');
|
|
|
|
var items = picker.querySelectorAll('.emoji-picker li');
|
|
|
|
items[0].click()
|
2017-07-15 11:55:07 +02:00
|
|
|
expect(view.insertEmoji).toHaveBeenCalled();
|
2018-03-14 18:25:34 +01:00
|
|
|
|
|
|
|
setTimeout(function () { timeout = true; }, 100);
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return timeout;
|
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
timeout = false;
|
2017-11-17 11:13:27 +01:00
|
|
|
toolbar.querySelector('li.toggle-smiley').click(); // Close the panel again
|
|
|
|
return test_utils.waitUntil(function () {
|
2017-07-15 15:15:37 +02:00
|
|
|
return !view.el.querySelector('.toggle-smiley .toolbar-menu').offsetHeight;
|
2018-03-14 18:25:34 +01:00
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
setTimeout(function () { timeout = true; }, 100);
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return timeout;
|
|
|
|
}, 300);
|
2017-11-17 11:13:27 +01:00
|
|
|
}).then(function () {
|
|
|
|
toolbar.querySelector('li.toggle-smiley').click();
|
2017-08-09 14:07:46 +02:00
|
|
|
expect(view.toggleEmojiMenu).toHaveBeenCalled();
|
2017-11-17 11:13:27 +01:00
|
|
|
return test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
var $picker = $(view.el).find('.toggle-smiley .emoji-picker-container');
|
|
|
|
return u.isVisible($picker[0]);
|
2017-11-17 11:13:27 +01:00
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
var nodes = view.el.querySelectorAll('.toggle-smiley ul li');
|
|
|
|
nodes[nodes.length-1].click();
|
|
|
|
expect(view.el.querySelector('textarea.chat-textarea').value).toBe(':grinning: ');
|
2017-08-09 14:07:46 +02:00
|
|
|
expect(view.insertEmoji).toHaveBeenCalled();
|
|
|
|
done();
|
2017-11-17 11:13:27 +01:00
|
|
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("contains a button for starting an encrypted chat session",
|
2017-07-15 07:09:59 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2018-03-14 19:25:33 +01:00
|
|
|
var timeout = true, $toolbar, view;
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2013-11-03 21:28:44 +01:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-03-14 19:25:33 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
|
|
|
}, 300).then(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
// TODO: More tests can be added here...
|
|
|
|
var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
2018-03-14 19:25:33 +01:00
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
$toolbar = $(view.el).find('ul.chat-toolbar');
|
|
|
|
expect($toolbar.find('.toggle-otr').length).toBe(1);
|
2017-04-05 11:01:31 +02:00
|
|
|
// Register spies
|
|
|
|
spyOn(view, 'toggleOTRMenu').and.callThrough();
|
|
|
|
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
|
2013-11-03 21:28:44 +01:00
|
|
|
|
2018-03-14 19:25:33 +01:00
|
|
|
timeout = false;
|
2018-03-14 18:25:34 +01:00
|
|
|
$toolbar[0].querySelector('.toggle-otr').click();
|
2018-03-14 19:25:33 +01:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return view.el.querySelector('.otr-menu').offsetHeight;
|
|
|
|
}, 300)
|
|
|
|
}).then(function () {
|
2013-11-03 21:28:44 +01:00
|
|
|
expect(view.toggleOTRMenu).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2013-11-03 21:28:44 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can contain a button for starting a call",
|
2017-07-15 07:09:59 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2013-12-18 03:52:16 +01:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
var view;
|
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);
|
2018-01-03 20:02:05 +01:00
|
|
|
var toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
|
|
var call_button = toolbar.querySelector('.toggle-call');
|
|
|
|
expect(_.isNull(call_button)).toBeTruthy();
|
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);
|
2018-01-04 12:31:04 +01:00
|
|
|
toolbar = view.el.querySelector('ul.chat-toolbar');
|
2018-01-03 20:02:05 +01:00
|
|
|
call_button = toolbar.querySelector('.toggle-call');
|
|
|
|
call_button.click();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
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 Status Notification", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2018-04-06 13:56:14 +02:00
|
|
|
it("does not open a new chatbox",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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({
|
2018-04-18 16:55:26 +02:00
|
|
|
'from': sender_jid,
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'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);
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
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
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is sent when the user opens a chat box",
|
2018-04-06 13:56:14 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-04-05 11:01:31 +02:00
|
|
|
}, 300).then(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();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(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');
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-02-15 15:55:34 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-08-08 17:35:17 +02:00
|
|
|
it("is sent when the user maximizes a minimized a chat box", mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-08-09 14:07:46 +02:00
|
|
|
}, 500).then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
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();
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return view.model.get('chat_state') === 'active';
|
2017-12-20 20:29:57 +01:00
|
|
|
}, 700);
|
2017-04-05 11:01:31 +02:00
|
|
|
}).then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-08-08 17:35:17 +02:00
|
|
|
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
return call.args[0] instanceof Strophe.Builder;
|
|
|
|
});
|
|
|
|
expect(calls.length).toBe(1);
|
|
|
|
var $stanza = $(calls[0].args[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');
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-11-22 17:42:58 +01:00
|
|
|
});
|
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
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is sent as soon as the user starts typing a message which is not a command",
|
2017-08-09 14:07:46 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-12-19 21:26:09 +01:00
|
|
|
}, 300).then(function () {
|
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
|
|
|
spyOn(_converse.connection, 'send');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'emit');
|
2016-02-15 15:55:34 +01:00
|
|
|
view.keyPressed({
|
2018-01-03 20:02:05 +01:00
|
|
|
target: $(view.el).find('textarea.chat-textarea'),
|
2016-02-15 15:55:34 +01:00
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(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({
|
2018-01-03 20:02:05 +01:00
|
|
|
target: $(view.el).find('textarea.chat-textarea'),
|
2016-02-15 15:55:34 +01:00
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.emit.calls.count(), 1);
|
|
|
|
done();
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be shown if received",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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';
|
2017-12-24 16:46:49 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
// <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);
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-05-04 17:26:43 +02:00
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
expect(view).toBeDefined();
|
|
|
|
|
|
|
|
test_utils.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1])
|
|
|
|
.then(function () {
|
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
// Check that the notification appears inside the chatbox in the DOM
|
|
|
|
var events = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(events.length).toBe(1);
|
|
|
|
expect(events[0].textContent).toEqual(mock.cur_names[1] + ' is typing');
|
|
|
|
|
|
|
|
// Check that it doesn't appear twice
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
events = view.el.querySelectorAll('.chat-state-notification');
|
|
|
|
expect(events.length).toBe(1);
|
|
|
|
expect(events[0].textContent).toEqual(mock.cur_names[1] + ' is typing');
|
|
|
|
done();
|
|
|
|
})
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-03-16 16:28:59 +01:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be a composing carbon message that this user sent from a different client",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
var contact, sent_stanza, IQ_id, stanza;
|
2018-02-08 09:49:05 +01:00
|
|
|
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
|
2017-12-03 12:21:57 +01:00
|
|
|
.then(function () {
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return _converse.xmppstatus.get('fullname');
|
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
// Send a message from a different resource
|
|
|
|
spyOn(_converse, 'log');
|
|
|
|
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, recipient_jid);
|
|
|
|
var msg = $msg({
|
|
|
|
'from': _converse.bare_jid,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('sent', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': _converse.bare_jid+'/another-resource',
|
|
|
|
'to': recipient_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
2017-03-16 16:28:59 +01:00
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
// Check that the chatbox and its view now exist
|
|
|
|
var chatbox = _converse.chatboxes.get(recipient_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(recipient_jid);
|
|
|
|
// 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('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
|
|
|
|
expect(msg_obj.get('sender')).toEqual('me');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_content = $(chatboxview.el).find('.chat-content');
|
2018-04-06 13:56:14 +02:00
|
|
|
var status_text = $chat_content.find('.chat-info.chat-state-notification').text();
|
2017-12-03 12:21:57 +01:00
|
|
|
expect(status_text).toBe('Typing from another device');
|
|
|
|
done();
|
|
|
|
});
|
2017-03-16 16:28:59 +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 paused notification", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is sent if the user has stopped typing since 30 seconds",
|
2018-04-06 13:56:14 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
var view, contact_jid;
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group li').length;
|
2017-12-20 20:29:57 +01:00
|
|
|
}, 700).then(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
_converse.TIMEOUTS.PAUSED = 200; // Make the timeout shorter so that we can test
|
2016-11-03 11:01:09 +01:00
|
|
|
|
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');
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(view, 'setChatState').and.callThrough();
|
2015-01-01 21:25:12 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
view.keyPressed({
|
2018-01-03 20:02:05 +01:00
|
|
|
target: $(view.el).find('textarea.chat-textarea'),
|
2015-01-01 21:25:12 +01:00
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().get(0).tagName).toBe('composing');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return view.model.get('chat_state') === 'paused';
|
2017-06-12 20:30:58 +02:00
|
|
|
}, 500);
|
2017-12-20 20:29:57 +01:00
|
|
|
}).then(function () {
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-08-08 17:35:17 +02:00
|
|
|
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
return call.args[0] instanceof Strophe.Builder;
|
|
|
|
});
|
|
|
|
expect(calls.length).toBe(2);
|
|
|
|
var $stanza = $(calls[1].args[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({
|
2018-01-03 20:02:05 +01:00
|
|
|
target: $(view.el).find('textarea.chat-textarea'),
|
2015-04-04 11:25:50 +02:00
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.setChatState).toHaveBeenCalled();
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2015-04-04 11:25:50 +02:00
|
|
|
view.keyPressed({
|
2018-01-03 20:02:05 +01:00
|
|
|
target: $(view.el).find('textarea.chat-textarea'),
|
2015-04-04 11:25:50 +02:00
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be shown if received",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-04-05 11:01:31 +02:00
|
|
|
}, 300)
|
|
|
|
.then(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
|
|
|
|
var msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-05-04 17:26:43 +02:00
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
test_utils.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1])
|
|
|
|
.then(function () {
|
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
var event = view.el.querySelector('.chat-info.chat-state-notification');
|
|
|
|
expect(event.textContent).toEqual(mock.cur_names[1] + ' has stopped typing');
|
|
|
|
done();
|
|
|
|
});
|
2017-04-05 11:01:31 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-03-16 16:28:59 +01:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can be a paused carbon message that this user sent from a different client",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
var contact, sent_stanza, IQ_id, stanza;
|
2018-02-08 09:49:05 +01:00
|
|
|
test_utils.waitUntilDiscoConfirmed(_converse, 'localhost', [], ['vcard-temp'])
|
2017-12-03 12:21:57 +01:00
|
|
|
.then(function () {
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return _converse.xmppstatus.get('fullname');
|
|
|
|
}, 300);
|
|
|
|
}).then(function () {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
// Send a message from a different resource
|
|
|
|
spyOn(_converse, 'log');
|
|
|
|
var recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, recipient_jid);
|
|
|
|
var msg = $msg({
|
|
|
|
'from': _converse.bare_jid,
|
|
|
|
'id': (new Date()).getTime(),
|
|
|
|
'to': _converse.connection.jid,
|
|
|
|
'type': 'chat',
|
|
|
|
'xmlns': 'jabber:client'
|
|
|
|
}).c('sent', {'xmlns': 'urn:xmpp:carbons:2'})
|
|
|
|
.c('forwarded', {'xmlns': 'urn:xmpp:forward:0'})
|
|
|
|
.c('message', {
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': _converse.bare_jid+'/another-resource',
|
|
|
|
'to': recipient_jid,
|
|
|
|
'type': 'chat'
|
|
|
|
}).c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
2017-03-16 16:28:59 +01:00
|
|
|
|
2017-12-03 12:21:57 +01:00
|
|
|
// Check that the chatbox and its view now exist
|
|
|
|
var chatbox = _converse.chatboxes.get(recipient_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(recipient_jid);
|
|
|
|
// 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('fullname')).toEqual(_converse.xmppstatus.get('fullname'));
|
|
|
|
expect(msg_obj.get('sender')).toEqual('me');
|
|
|
|
expect(msg_obj.get('delayed')).toEqual(false);
|
2018-01-03 20:02:05 +01:00
|
|
|
var $chat_content = $(chatboxview.el).find('.chat-content');
|
2018-04-06 13:56:14 +02:00
|
|
|
var status_text = $chat_content.find('.chat-info.chat-state-notification').text();
|
2017-12-03 12:21:57 +01:00
|
|
|
expect(status_text).toBe('Stopped typing on the other device');
|
|
|
|
done();
|
|
|
|
});
|
2017-03-16 16:28:59 +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("An inactive notifciation", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is sent if the user has stopped typing since 2 minutes",
|
2017-08-09 14:07:46 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
var view, contact_jid;
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-08-16 14:16:24 +02:00
|
|
|
}, 500).then(function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
// Make the timeouts shorter so that we can test
|
|
|
|
_converse.TIMEOUTS.PAUSED = 200;
|
|
|
|
_converse.TIMEOUTS.INACTIVE = 200;
|
|
|
|
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2017-08-16 14:16:24 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return view.model.get('chat_state') === 'active';
|
|
|
|
}, 500);
|
|
|
|
}).then(function () {
|
|
|
|
console.log('chat_state set to active');
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2015-01-01 21:25:12 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
view.keyPressed({
|
2018-01-03 20:02:05 +01:00
|
|
|
target: $(view.el).find('textarea.chat-textarea'),
|
2015-01-01 21:25:12 +01:00
|
|
|
keyCode: 1
|
|
|
|
});
|
2017-08-16 14:16:24 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return view.model.get('chat_state') === 'composing';
|
|
|
|
}, 500);
|
|
|
|
}).then(function () {
|
|
|
|
console.log('chat_state set to composing');
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
2015-01-01 21:25:12 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
2017-08-16 14:16:24 +02:00
|
|
|
return view.model.get('chat_state') === 'paused';
|
|
|
|
}, 500);
|
2017-04-05 11:01:31 +02:00
|
|
|
}).then(function () {
|
2017-08-16 14:16:24 +02:00
|
|
|
console.log('chat_state set to paused');
|
2017-04-05 11:01:31 +02:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return view.model.get('chat_state') === 'inactive';
|
2017-08-16 14:16:24 +02:00
|
|
|
}, 500);
|
2017-04-05 11:01:31 +02:00
|
|
|
}).then(function () {
|
2017-08-16 14:16:24 +02:00
|
|
|
console.log('chat_state set to inactive');
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2017-08-08 17:35:17 +02:00
|
|
|
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
return call.args[0] instanceof Strophe.Builder;
|
|
|
|
});
|
|
|
|
expect(calls.length).toBe(2);
|
|
|
|
var $stanza = $(calls[0].args[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);
|
2017-04-05 11:01:31 +02:00
|
|
|
expect($stanza.children().get(0).tagName).toBe('paused');
|
2016-05-30 18:53:31 +02:00
|
|
|
expect($stanza.children().get(1).tagName).toBe('no-store');
|
|
|
|
expect($stanza.children().get(2).tagName).toBe('no-permanent-store');
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
$stanza = $(_converse.connection.send.calls.mostRecent().args[0].tree());
|
|
|
|
expect($stanza.attr('to')).toBe(contact_jid);
|
|
|
|
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');
|
2017-12-19 20:17:38 +01:00
|
|
|
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
|
|
|
|
.then(done);
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is sent when the user a minimizes a chat box",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(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');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is sent if the user closes a chat box",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2017-04-05 11:01:31 +02:00
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-04-05 11:01:31 +02:00
|
|
|
}, 300).then(function () {
|
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
|
|
|
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();
|
2017-04-05 11:01:31 +02:00
|
|
|
var $stanza = $(_converse.connection.send.calls.argsFor(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');
|
2017-04-05 11:01:31 +02:00
|
|
|
done();
|
2016-02-15 15:55:34 +01:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2018-04-06 13:56:14 +02:00
|
|
|
it("will clear any other chat status notifications",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
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);
|
2018-04-06 13:56:14 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-event').length).toBe(0);
|
|
|
|
// Insert <composing> message, to also check that
|
|
|
|
// text messages are inserted correctly with
|
|
|
|
// temporary chat events in the chat contents.
|
2015-10-25 18:49:35 +01:00
|
|
|
var msg = $msg({
|
2018-04-06 13:56:14 +02:00
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
|
|
|
|
.tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(1);
|
|
|
|
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);
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-04-06 13:56:14 +02:00
|
|
|
expect($(view.el).find('.chat-state-notification').length).toBe(0);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
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
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be shown if received",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
|
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);
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-05-04 17:26:43 +02:00
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
test_utils.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1])
|
|
|
|
.then(function () {
|
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
var event = view.el.querySelector('.chat-state-notification');
|
|
|
|
expect(event.textContent).toEqual(mock.cur_names[1] + ' has gone away');
|
|
|
|
done();
|
|
|
|
});
|
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
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("'/clear' can be used to clear messages in a conversation",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
|
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';
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(view, 'onMessageSubmitted').and.callThrough();
|
|
|
|
spyOn(view, 'clearMessages').and.callThrough();
|
|
|
|
spyOn(window, 'confirm').and.callFake(function () {
|
2014-04-24 19:14:37 +02:00
|
|
|
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
|
2017-04-05 11:01:31 +02:00
|
|
|
expect(_converse.emit.calls.count(), 1);
|
|
|
|
expect(_converse.emit.calls.mostRecent().args, ['messageSend', message]);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2015-10-07 10:57:11 +02:00
|
|
|
describe("A Message Counter", function () {
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is incremented when the message is received and the window is not focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
spyOn(_converse, 'emit');
|
|
|
|
expect(_converse.msg_counter).toBe(0);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'incrementMsgCounter').and.callThrough();
|
2017-05-03 09:06:28 +02:00
|
|
|
spyOn(_converse, 'clearMsgCounter').and.callThrough();
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
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()
|
2017-05-03 09:06:28 +02:00
|
|
|
.c('active', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.incrementMsgCounter).toHaveBeenCalled();
|
2017-05-03 09:06:28 +02:00
|
|
|
expect(_converse.clearMsgCounter).not.toHaveBeenCalled();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.msg_counter).toBe(1);
|
2017-04-21 12:11:33 +02:00
|
|
|
expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.windowSate = previous_state;
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is cleared when the window is focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.windowState = 'hidden';
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'clearMsgCounter').and.callThrough();
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
_converse.saveWindowState(null, 'blur');
|
|
|
|
expect(_converse.clearMsgCounter).toHaveBeenCalled();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is not incremented when the message is received and the window is focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.msg_counter).toBe(0);
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'incrementMsgCounter').and.callThrough();
|
2016-12-20 10:30:20 +01:00
|
|
|
_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()
|
2017-05-03 09:06:28 +02:00
|
|
|
.c('active', {'xmlns': Strophe.NS.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);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-05-01 13:05:58 +02:00
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is incremented from zero when chatbox was closed after viewing previously received messages and the window is not focused now",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-01 13:05:58 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
// initial state
|
|
|
|
expect(_converse.msg_counter).toBe(0);
|
|
|
|
|
|
|
|
var message = 'This message will always increment the message counter from zero',
|
|
|
|
sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
2017-07-15 11:55:07 +02:00
|
|
|
msgFactory = function () {
|
|
|
|
return $msg({
|
2017-05-01 13:05:58 +02:00
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
})
|
|
|
|
.c('body').t(message).up()
|
2017-05-03 09:06:28 +02:00
|
|
|
.c('active', {'xmlns': Strophe.NS.CHATSTATES})
|
2017-05-01 13:05:58 +02:00
|
|
|
.tree();
|
|
|
|
};
|
|
|
|
|
|
|
|
// leave converse-chat page
|
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(_converse.msg_counter).toBe(1);
|
|
|
|
|
|
|
|
// come back to converse-chat page
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
var view = _converse.chatboxviews.get(sender_jid);
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(view.el)).toBeTruthy();
|
2017-05-01 13:05:58 +02:00
|
|
|
expect(_converse.msg_counter).toBe(0);
|
|
|
|
|
|
|
|
// close chatbox and leave converse-chat page again
|
|
|
|
view.close();
|
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
|
|
|
|
// check that msg_counter is incremented from zero again
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
view = _converse.chatboxviews.get(sender_jid);
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible(view.el)).toBeTruthy();
|
2017-05-01 13:05:58 +02:00
|
|
|
expect(_converse.msg_counter).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-01 13:05:58 +02:00
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2017-05-03 09:06:28 +02:00
|
|
|
|
|
|
|
describe("A ChatBox's Unread Message Count", function () {
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is incremented when the message is received and ChatBoxView is scrolled up",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is not incremented when the message is received and ChatBoxView is scrolled down",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be read');
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(chatbox.get('num_unread')).toBe(0);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is incremeted when message is received, chatbox is scrolled down and the window is not focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
};
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
|
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is incremeted when message is received, chatbox is scrolled up and the window is not focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
};
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
|
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is cleared when ChatBoxView was scrolled down and the window become focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
};
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
|
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
expect(chatbox.get('num_unread')).toBe(0);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is not cleared when ChatBoxView was scrolled up and the windows become focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
};
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
|
|
|
|
_converse.windowState = 'hidden';
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("A RosterView's Unread Message Count", function () {
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is updated when message is received and chatbox is scrolled up",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-05-03 09:06:28 +02:00
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
|
|
|
|
var msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
|
2017-06-05 14:50:29 +02:00
|
|
|
var msgIndicatorSelector = 'a.open-chat:contains("' + chatbox.get('fullname') + '") .msgs-indicator',
|
2018-01-03 20:02:05 +01:00
|
|
|
$msgIndicator = $($(_converse.rosterview.el).find(msgIndicatorSelector));
|
2017-05-03 09:06:28 +02:00
|
|
|
|
|
|
|
expect($msgIndicator.text()).toBe('1');
|
|
|
|
|
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread too');
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
$msgIndicator = $($(_converse.rosterview.el).find(msgIndicatorSelector));
|
2017-05-03 09:06:28 +02:00
|
|
|
expect($msgIndicator.text()).toBe('2');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is updated when message is received and chatbox is minimized",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-05-03 09:06:28 +02:00
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatboxview.minimize();
|
|
|
|
|
|
|
|
var msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
|
2017-06-05 14:50:29 +02:00
|
|
|
var msgIndicatorSelector = 'a.open-chat:contains("' + chatbox.get('fullname') + '") .msgs-indicator',
|
2018-01-03 20:02:05 +01:00
|
|
|
$msgIndicator = $($(_converse.rosterview.el).find(msgIndicatorSelector));
|
2017-05-03 09:06:28 +02:00
|
|
|
|
|
|
|
expect($msgIndicator.text()).toBe('1');
|
|
|
|
|
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread too');
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
$msgIndicator = $($(_converse.rosterview.el).find(msgIndicatorSelector));
|
2017-05-03 09:06:28 +02:00
|
|
|
expect($msgIndicator.text()).toBe('2');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is cleared when chatbox is maximzied after receiving messages in minimized mode",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-05-03 09:06:28 +02:00
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2017-06-05 14:50:29 +02:00
|
|
|
var msgsIndicatorSelector = 'a.open-chat:contains("' + chatbox.get('fullname') + '") .msgs-indicator';
|
2018-01-03 20:02:05 +01:00
|
|
|
var selectMsgsIndicator = function () { return $($(_converse.rosterview.el).find(msgsIndicatorSelector)); };
|
2017-07-15 11:55:07 +02:00
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
2017-05-03 09:06:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
chatboxview.minimize();
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(selectMsgsIndicator().text()).toBe('1');
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(selectMsgsIndicator().text()).toBe('2');
|
|
|
|
|
|
|
|
chatboxview.maximize();
|
|
|
|
expect(selectMsgsIndicator().length).toBe(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is cleared when unread messages are viewed which were received in scrolled-up chatbox",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-05-03 09:06:28 +02:00
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2017-07-15 11:55:07 +02:00
|
|
|
var msgFactory = function () {
|
2017-05-03 09:06:28 +02:00
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
|
|
|
};
|
2017-06-05 14:50:29 +02:00
|
|
|
var msgsIndicatorSelector = 'a.open-chat:contains("' + chatbox.get('fullname') + '") .msgs-indicator',
|
2018-01-03 20:02:05 +01:00
|
|
|
selectMsgsIndicator = function () { return $($(_converse.rosterview.el).find(msgsIndicatorSelector)); };
|
2017-05-03 09:06:28 +02:00
|
|
|
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(selectMsgsIndicator().text()).toBe('1');
|
|
|
|
|
|
|
|
chatboxview.viewUnreadMessages();
|
|
|
|
_converse.rosterview.render();
|
|
|
|
expect(selectMsgsIndicator().length).toBe(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is not cleared after user clicks on roster view when chatbox is already opened and scrolled up",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
test_utils.waitUntil(function () {
|
2018-01-03 20:02:05 +01:00
|
|
|
return $(_converse.rosterview.el).find('.roster-group').length;
|
2017-05-03 09:06:28 +02:00
|
|
|
}, 500)
|
|
|
|
.then(function () {
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
2017-07-15 11:55:07 +02:00
|
|
|
var msgFactory = function () {
|
2017-05-03 09:06:28 +02:00
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
|
|
|
};
|
2017-06-05 14:50:29 +02:00
|
|
|
var msgsIndicatorSelector = 'a.open-chat:contains("' + chatbox.get('fullname') + '") .msgs-indicator',
|
2018-01-03 20:02:05 +01:00
|
|
|
selectMsgsIndicator = function () { return $($(_converse.rosterview.el).find(msgsIndicatorSelector)); };
|
2017-05-03 09:06:28 +02:00
|
|
|
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
expect(selectMsgsIndicator().text()).toBe('1');
|
|
|
|
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
expect(selectMsgsIndicator().text()).toBe('1');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("A Minimized ChatBoxView's Unread Message Count", function () {
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is displayed when scrolled up chatbox is minimized after receiving unread messages",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
|
|
|
};
|
|
|
|
var selectUnreadMsgCount = function () {
|
|
|
|
var minimizedChatBoxView = _converse.minimized_chats.get(sender_jid);
|
2018-03-14 19:25:33 +01:00
|
|
|
return $(minimizedChatBoxView.el).find('.message-count');
|
2017-05-03 09:06:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatboxview.minimize();
|
|
|
|
|
|
|
|
var $unreadMsgCount = selectUnreadMsgCount();
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible($unreadMsgCount[0])).toBeTruthy();
|
2017-05-03 09:06:28 +02:00
|
|
|
expect($unreadMsgCount.html()).toBe('1');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is incremented when message is received and windows is not focused",
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-03 09:06:28 +02:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
|
|
|
|
var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
var msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
|
|
|
};
|
|
|
|
var selectUnreadMsgCount = function () {
|
|
|
|
var minimizedChatBoxView = _converse.minimized_chats.get(sender_jid);
|
2018-03-14 19:25:33 +01:00
|
|
|
return $(minimizedChatBoxView.el).find('.message-count');
|
2017-05-03 09:06:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatboxview.minimize();
|
|
|
|
|
|
|
|
_converse.chatboxes.onMessage(msgFactory());
|
|
|
|
|
|
|
|
var $unreadMsgCount = selectUnreadMsgCount();
|
2018-01-03 20:02:05 +01:00
|
|
|
expect(u.isVisible($unreadMsgCount[0])).toBeTruthy();
|
2017-05-03 09:06:28 +02:00
|
|
|
expect($unreadMsgCount.html()).toBe('1');
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
2018-03-31 18:29:01 +02:00
|
|
|
|
|
|
|
it("will render Openstreetmap-URL from geo-URI",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
var base_url = document.URL.split(window.location.pathname)[0];
|
|
|
|
var message = "geo:37.786971,-122.399677";
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
2018-04-16 14:22:27 +02:00
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
2018-03-31 18:29:01 +02:00
|
|
|
test_utils.sendMessage(view, message);
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
2018-04-27 16:58:49 +02:00
|
|
|
return $(view.el).find('.chat-content').find('.chat-msg').length;
|
2018-03-31 18:29:01 +02:00
|
|
|
}, 1000).then(function () {
|
2018-04-16 14:22:27 +02:00
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2018-04-27 16:58:49 +02:00
|
|
|
var msg = $(view.el).find('.chat-content').find('.chat-msg').last().find('.chat-msg-text');
|
2018-03-31 18:29:01 +02:00
|
|
|
expect(msg.html()).toEqual(
|
|
|
|
'<a target="_blank" rel="noopener" href="https://www.openstreetmap.org/?mlat=37.786971&'+
|
|
|
|
'mlon=-122.399677#map=18/37.786971/-122.399677">https://www.openstreetmap.org/?mlat=37.7869'+
|
|
|
|
'71&mlon=-122.399677#map=18/37.786971/-122.399677</a>');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
2017-05-03 09:06:28 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|