2013-11-02 12:37:38 +01:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2017-06-19 11:08:57 +02:00
|
|
|
"jasmine",
|
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);
|
2019-03-25 23:31:05 +01:00
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2016-06-23 08:55:25 +02:00
|
|
|
"use strict";
|
2018-07-30 18:16:32 +02:00
|
|
|
const _ = converse.env._;
|
|
|
|
const $msg = converse.env.$msg;
|
|
|
|
const Strophe = converse.env.Strophe;
|
|
|
|
const u = converse.env.utils;
|
|
|
|
const sizzle = converse.env.sizzle;
|
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
|
|
|
|
2019-10-11 16:38:01 +02:00
|
|
|
it("has a /help command to show the available commands", mock.initConverse(['rosterGroupsFetched', 'chatBoxesFetched'], {}, async function (done, _converse) {
|
2018-01-15 18:41:04 +01:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-01-15 18:41:04 +01:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
test_utils.sendMessage(view, '/help');
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
const info_messages = Array.prototype.slice.call(view.el.querySelectorAll('.chat-info:not(.chat-date)'), 0);
|
2019-11-15 09:41:01 +01:00
|
|
|
expect(info_messages.length).toBe(4);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(info_messages.pop().textContent).toBe('/help: Show this menu');
|
|
|
|
expect(info_messages.pop().textContent).toBe('/me: Write in the third person');
|
2019-11-15 09:41:01 +01:00
|
|
|
expect(info_messages.pop().textContent).toBe('/close: Close this chat');
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(info_messages.pop().textContent).toBe('/clear: Remove messages');
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
const msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('hello world').tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.content.querySelectorAll('.chat-msg').length);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(view.content.lastElementChild.textContent.trim().indexOf('hello world')).not.toBe(-1);
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2018-01-15 18:41:04 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
|
2019-10-11 16:38:01 +02:00
|
|
|
it("supports the /me command", mock.initConverse(['rosterGroupsFetched'], {}, async function (done, _converse) {
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'montague.lit', [], ['vcard-temp']);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'));
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-13 23:25:01 +02:00
|
|
|
let message = '/me is tired';
|
|
|
|
const 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();
|
2017-12-03 12:21:57 +01:00
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-10-13 23:25:01 +02:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg--action').length).toBe(1);
|
2019-06-03 07:58:51 +02:00
|
|
|
expect(_.includes(view.el.querySelector('.chat-msg__author').textContent, '**Mercutio')).toBeTruthy();
|
2018-11-03 12:43:24 +01:00
|
|
|
expect(view.el.querySelector('.chat-msg__text').textContent).toBe('is tired');
|
2018-10-13 23:25:01 +02:00
|
|
|
message = '/me is as well';
|
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
expect(view.el.querySelectorAll('.chat-msg--action').length).toBe(2);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => sizzle('.chat-msg__author:last', view.el).pop().textContent.trim() === '**Romeo Montague');
|
2019-06-19 11:04:09 +02:00
|
|
|
const last_el = sizzle('.chat-msg__text:last', view.el).pop();
|
2019-03-25 23:31:05 +01:00
|
|
|
expect(last_el.textContent).toBe('is as well');
|
|
|
|
expect(u.hasClass('chat-msg--followup', last_el)).toBe(false);
|
2018-10-13 23:25:01 +02:00
|
|
|
// Check that /me messages after a normal message don't
|
|
|
|
// get the 'chat-msg--followup' class.
|
|
|
|
message = 'This a normal message';
|
|
|
|
await test_utils.sendMessage(view, message);
|
2019-06-19 11:04:09 +02:00
|
|
|
let message_el = view.el.querySelector('.message:last-child');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', message_el)).toBeFalsy();
|
|
|
|
message = '/me wrote a 3rd person message';
|
|
|
|
await test_utils.sendMessage(view, message);
|
2019-06-19 11:04:09 +02:00
|
|
|
message_el = view.el.querySelector('.message:last-child');
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-msg--action').length).toBe(3);
|
2019-06-19 11:04:09 +02:00
|
|
|
expect(sizzle('.chat-msg__text:last', view.el).pop().textContent).toBe('wrote a 3rd person message');
|
|
|
|
expect(u.isVisible(sizzle('.chat-msg__author:last', view.el).pop())).toBeTruthy();
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(u.hasClass('chat-msg--followup', message_el)).toBeFalsy();
|
|
|
|
done();
|
2017-02-15 22:03:02 +01:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is created when you click on a roster item", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
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');
|
2018-07-30 18:16:32 +02:00
|
|
|
expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(1); // Controlbox is open
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length, 700);
|
2018-11-22 09:31:00 +01:00
|
|
|
const online_contacts = _converse.rosterview.el.querySelectorAll('.roster-group .current-xmpp-contact a.open-chat');
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(online_contacts.length).toBe(17);
|
2018-11-22 09:31:00 +01:00
|
|
|
let el = online_contacts[0];
|
|
|
|
el.click();
|
2019-07-11 12:30:51 +02:00
|
|
|
await u.waitUntil(() => document.querySelectorAll("#conversejs .chatbox").length == 2);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
online_contacts[1].click();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length == 3);
|
2018-11-22 09:31:00 +01:00
|
|
|
el = online_contacts[1];
|
|
|
|
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(document.querySelectorAll("#conversejs .chatbox").length).toBe(3);
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("opens when a new message is received", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {'allow_non_roster_messaging': true},
|
2019-01-10 21:10:29 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 0);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-02-12 14:21:45 +01:00
|
|
|
const stanza = u.toStanza(`
|
|
|
|
<message from="${sender_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-02-12 14:21:45 +01:00
|
|
|
<body>Hey\nHave you heard the news?</body>
|
|
|
|
</message>`);
|
2019-01-10 21:10:29 +01:00
|
|
|
|
|
|
|
const message_promise = new Promise(resolve => _converse.api.listen.on('message', resolve));
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-11-01 16:04:55 +01:00
|
|
|
await new Promise(resolve => _converse.api.listen.once('chatBoxInitialized', resolve));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => message_promise);
|
2019-01-10 21:10:29 +01:00
|
|
|
expect(_converse.chatboxviews.keys().length).toBe(2);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("doesn't open when a message without body is received", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-01-10 21:10:29 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-02-12 14:21:45 +01:00
|
|
|
const stanza = u.toStanza(`
|
2019-01-10 21:10:29 +01:00
|
|
|
<message from="${sender_jid}"
|
|
|
|
type="chat"
|
2019-06-03 07:58:51 +02:00
|
|
|
to="romeo@montague.lit/orchard">
|
2019-01-10 21:10:29 +01:00
|
|
|
<composing xmlns="http://jabber.org/protocol/chatstates"/>
|
2019-02-12 14:21:45 +01:00
|
|
|
</message>`);
|
2019-01-10 21:10:29 +01:00
|
|
|
const message_promise = new Promise(resolve => _converse.api.listen.on('message', resolve))
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => message_promise);
|
2019-01-10 21:10:29 +01:00
|
|
|
expect(_converse.chatboxviews.keys().length).toBe(1);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be trimmed to conserve space",
|
2019-10-11 16:38:01 +02:00
|
|
|
mock.initConverse(['rosterGroupsFetched', 'emojisInitialized'], {},
|
2018-10-26 10:15:01 +02:00
|
|
|
async function (done, _converse) {
|
2018-07-30 18:16:32 +02:00
|
|
|
|
|
|
|
spyOn(_converse.chatboxviews, 'trimChats');
|
|
|
|
|
|
|
|
const trimmed_chatboxes = _converse.minimized_chats;
|
|
|
|
spyOn(trimmed_chatboxes, 'addChat').and.callThrough();
|
|
|
|
spyOn(trimmed_chatboxes, 'removeChat').and.callThrough();
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
let jid, chatboxview;
|
2014-06-01 17:57:03 +02:00
|
|
|
// openControlBox was called earlier, so the controlbox is
|
|
|
|
// visible, but no other chat boxes have been created.
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
2018-07-30 18:16:32 +02:00
|
|
|
expect(document.querySelectorAll("#conversejs .chatbox").length).toBe(1); // Controlbox is open
|
2014-06-01 17:57:03 +02:00
|
|
|
|
2017-12-20 20:29:57 +01:00
|
|
|
_converse.rosterview.update(); // XXX: Hack to make sure $roster element is attached.
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length);
|
2018-10-26 10:15:01 +02:00
|
|
|
// Test that they can be maximized again
|
|
|
|
const online_contacts = _converse.rosterview.el.querySelectorAll('.roster-group .current-xmpp-contact a.open-chat');
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(online_contacts.length).toBe(17);
|
2018-10-26 10:15:01 +02:00
|
|
|
let i;
|
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
const el = online_contacts[i];
|
|
|
|
el.click();
|
|
|
|
}
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length == 16);
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats.calls.count()).toBe(17);
|
2018-10-26 10:15:01 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
_converse.api.chatviews.get().forEach(v => spyOn(v, 'onMinimized').and.callThrough());
|
2018-10-26 10:15:01 +02:00
|
|
|
for (i=0; i<online_contacts.length; i++) {
|
|
|
|
const el = online_contacts[i];
|
2019-06-03 07:58:51 +02:00
|
|
|
jid = _.trim(el.textContent.trim()).replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-10-26 10:15:01 +02:00
|
|
|
chatboxview = _converse.chatboxviews.get(jid);
|
|
|
|
chatboxview.model.set({'minimized': true});
|
|
|
|
expect(trimmed_chatboxes.addChat).toHaveBeenCalled();
|
2019-06-26 16:32:23 +02:00
|
|
|
expect(chatboxview.onMinimized).toHaveBeenCalled();
|
2018-10-26 10:15:01 +02:00
|
|
|
}
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxviews.keys().length);
|
2018-10-26 10:15:01 +02:00
|
|
|
var key = _converse.chatboxviews.keys()[1];
|
|
|
|
const trimmedview = trimmed_chatboxes.get(key);
|
|
|
|
const chatbox = trimmedview.model;
|
|
|
|
spyOn(chatbox, 'maximize').and.callThrough();
|
|
|
|
spyOn(trimmedview, 'restore').and.callThrough();
|
|
|
|
trimmedview.delegateEvents();
|
|
|
|
trimmedview.el.querySelector("a.restore-chat").click();
|
|
|
|
|
|
|
|
expect(trimmedview.restore).toHaveBeenCalled();
|
|
|
|
expect(chatbox.maximize).toHaveBeenCalled();
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats.calls.count()).toBe(18);
|
2018-10-26 10:15:01 +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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-02-24 11:44:34 +01:00
|
|
|
async function (done, _converse) {
|
2017-04-23 15:38:48 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-09 16:01:38 +02:00
|
|
|
await _converse.api.chats.create(sender_jid, {'minimized': true});
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length > 1);
|
2019-02-24 11:44:34 +01:00
|
|
|
const 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
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
const minimized_chat = _converse.minimized_chats.get(sender_jid);
|
2017-04-23 15:38:48 +02:00
|
|
|
expect(minimized_chat).toBeTruthy();
|
2019-03-25 23:31:05 +01:00
|
|
|
expect(u.isVisible(minimized_chat.el)).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",
|
2019-10-11 16:38:01 +02:00
|
|
|
mock.initConverse(['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2019-02-24 11:44:34 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-09-13 06:29:43 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-02-24 11:44:34 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const el = sizzle('a.open-chat:contains("'+view.model.getDisplayName()+'")', _converse.rosterview.el).pop();
|
2019-09-13 06:29:43 +02:00
|
|
|
await u.waitUntil(() => u.isVisible(el));
|
|
|
|
const textarea = view.el.querySelector('.chat-textarea');
|
|
|
|
await u.waitUntil(() => u.isVisible(textarea));
|
|
|
|
textarea.blur();
|
|
|
|
spyOn(view.model, 'maybeShow').and.callThrough();
|
|
|
|
spyOn(view, 'focus').and.callThrough();
|
2019-02-24 11:44:34 +01:00
|
|
|
el.click();
|
2019-09-13 06:29:43 +02:00
|
|
|
await u.waitUntil(() => view.model.maybeShow.calls.count(), 1000);
|
|
|
|
expect(view.model.maybeShow).toHaveBeenCalled();
|
|
|
|
expect(view.focus).toHaveBeenCalled();
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(2);
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-07-12 12:41:21 +02:00
|
|
|
spyOn(_converse.ChatBoxViews.prototype, 'trimChats');
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2014-04-24 19:39:03 +02:00
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
|
|
|
test_utils.openChatBoxes(_converse, 6);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length == 7);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
// We instantiate a new ChatBoxes collection, which by default
|
|
|
|
// will be empty.
|
|
|
|
const newchatboxes = new _converse.ChatBoxes();
|
|
|
|
expect(newchatboxes.length).toEqual(0);
|
|
|
|
// The chatboxes will then be fetched from browserStorage inside the
|
|
|
|
// onConnected method
|
|
|
|
newchatboxes.onConnected();
|
2019-10-24 14:29:15 +02:00
|
|
|
await new Promise(resolve => _converse.api.listen.on('chatBoxesFetched', resolve));
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(newchatboxes.length).toEqual(7);
|
|
|
|
// Check that the chatboxes items retrieved from browserStorage
|
|
|
|
// have the same attributes values as the original ones.
|
|
|
|
const attrs = ['id', 'box_id', 'visible'];
|
|
|
|
let 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();
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2019-01-25 11:53:07 +01:00
|
|
|
it("can be closed by clicking a DOM element with class 'close-chatbox-button'",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[7].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const controlview = _converse.chatboxviews.get('controlbox'), // The controlbox is currently open
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
|
|
|
|
spyOn(chatview, 'close').and.callThrough();
|
|
|
|
spyOn(controlview, 'close').and.callThrough();
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
// We need to rebind all events otherwise our spy won't be called
|
|
|
|
controlview.delegateEvents();
|
|
|
|
chatview.delegateEvents();
|
2014-02-28 03:04:52 +01:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
controlview.el.querySelector('.close-chatbox-button').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(controlview.close).toHaveBeenCalled();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
|
|
|
expect(_converse.api.trigger.calls.count(), 1);
|
2018-11-22 09:31:00 +01:00
|
|
|
chatview.el.querySelector('.close-chatbox-button').click();
|
2017-04-05 11:01:31 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatview.close).toHaveBeenCalled();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
|
|
|
expect(_converse.api.trigger.calls.count(), 2);
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
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'",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[7].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const trimmed_chatboxes = _converse.minimized_chats;
|
|
|
|
const chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(chatview, 'minimize').and.callThrough();
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-11-22 09:31:00 +01:00
|
|
|
// We need to rebind all events otherwise our spy won't be called
|
|
|
|
chatview.delegateEvents();
|
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
|
|
|
|
|
|
|
expect(chatview.minimize).toHaveBeenCalled();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxMinimized', jasmine.any(Object));
|
|
|
|
expect(_converse.api.trigger.calls.count(), 2);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(u.isVisible(chatview.el)).toBeFalsy();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
|
|
|
const trimmedview = trimmed_chatboxes.get(chatview.model.get('id'));
|
|
|
|
spyOn(trimmedview, 'restore').and.callThrough();
|
|
|
|
trimmedview.delegateEvents();
|
|
|
|
trimmedview.el.querySelector("a.restore-chat").click();
|
|
|
|
|
|
|
|
expect(trimmedview.restore).toHaveBeenCalled();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxMaximized', jasmine.any(Object));
|
2019-03-25 23:31:05 +01:00
|
|
|
const toggle_el = sizzle('.toggle-chatbox-button', chatview.el).pop();
|
|
|
|
expect(u.hasClass('fa-minus', toggle_el)).toBeTruthy();
|
|
|
|
expect(u.hasClass('fa-plus', toggle_el)).toBeFalsy();
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be removed from browserStorage when closed",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-07-12 12:41:21 +02:00
|
|
|
spyOn(_converse.ChatBoxViews.prototype, 'trimChats');
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2014-03-04 19:16:39 +01:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
test_utils.closeControlBox();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
|
|
|
test_utils.openChatBoxes(_converse, 6);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxes.length == 7)
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.chatboxviews.trimChats).toHaveBeenCalled();
|
|
|
|
expect(_converse.chatboxes.length).toEqual(7);
|
2019-05-16 11:40:30 +02:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxInitialized', jasmine.any(Object));
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.closeAllChatBoxes(_converse);
|
2018-11-22 09:31:00 +01:00
|
|
|
|
|
|
|
expect(_converse.chatboxes.length).toEqual(1);
|
|
|
|
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
|
2019-10-24 14:29:15 +02:00
|
|
|
const newchatboxes = new _converse.ChatBoxes();
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(newchatboxes.length).toEqual(0);
|
|
|
|
expect(_converse.chatboxes.pluck('id')).toEqual(['controlbox']);
|
|
|
|
// onConnected will fetch chatboxes in browserStorage, but
|
|
|
|
// because there aren't any open chatboxes, there won't be any
|
|
|
|
// in browserStorage either. XXX except for the controlbox
|
|
|
|
newchatboxes.onConnected();
|
2019-10-24 14:29:15 +02:00
|
|
|
await new Promise(resolve => _converse.api.listen.on('chatBoxesFetched', resolve));
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(newchatboxes.length).toEqual(1);
|
|
|
|
expect(newchatboxes.models[0].id).toBe("controlbox");
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 3);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatbox).toBeDefined();
|
|
|
|
expect(view).toBeDefined();
|
|
|
|
const toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
|
|
expect(_.isElement(toolbar)).toBe(true);
|
2018-12-13 15:36:37 +01:00
|
|
|
expect(toolbar.querySelectorAll(':scope > li').length).toBe(2);
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2019-06-16 14:16:35 +02:00
|
|
|
it("shows the remaining character count if a message_limit is configured",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {'message_limit': 200},
|
2019-06-16 14:16:35 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 3);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-16 14:16:35 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const toolbar = view.el.querySelector('.chat-toolbar');
|
|
|
|
const counter = toolbar.querySelector('.message-limit');
|
|
|
|
expect(counter.textContent).toBe('200');
|
|
|
|
view.insertIntoTextArea('hello world');
|
|
|
|
expect(counter.textContent).toBe('188');
|
|
|
|
|
2019-10-29 11:30:31 +01:00
|
|
|
toolbar.querySelector('a.toggle-smiley').click();
|
|
|
|
const picker = await u.waitUntil(() => view.el.querySelector('.emoji-picker__lists'));
|
2019-08-16 10:18:35 +02:00
|
|
|
const item = await u.waitUntil(() => picker.querySelector('.emoji-picker li.insert-emoji'));
|
|
|
|
item.click()
|
2019-08-23 07:04:56 +02:00
|
|
|
expect(counter.textContent).toBe('179');
|
2019-06-16 14:16:35 +02:00
|
|
|
|
|
|
|
const textarea = view.el.querySelector('.chat-textarea');
|
|
|
|
const ev = {
|
|
|
|
target: textarea,
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2019-06-16 14:16:35 +02:00
|
|
|
keyCode: 13 // Enter
|
|
|
|
};
|
|
|
|
view.onKeyDown(ev);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2019-06-16 14:16:35 +02:00
|
|
|
view.onKeyUp(ev);
|
|
|
|
expect(counter.textContent).toBe('200');
|
|
|
|
|
|
|
|
textarea.value = 'hello world';
|
|
|
|
view.onKeyUp(ev);
|
|
|
|
expect(counter.textContent).toBe('189');
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it("does not show a remaining character count if message_limit is zero",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {'message_limit': 0},
|
2019-06-16 14:16:35 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current', 3);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-16 14:16:35 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
const counter = view.el.querySelector('.chat-toolbar .message-limit');
|
|
|
|
expect(counter).toBe(null);
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("can contain a button for starting a call",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-26 10:15:01 +02:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2013-12-18 03:52:16 +01:00
|
|
|
|
2018-10-26 10:15:01 +02:00
|
|
|
let toolbar, call_button;
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
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;
|
2018-10-26 10:15:01 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
let view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
|
|
call_button = toolbar.querySelector('.toggle-call');
|
2019-08-05 01:39:57 +02:00
|
|
|
expect(call_button === null).toBeTruthy();
|
2018-10-26 10:15:01 +02:00
|
|
|
view.close();
|
|
|
|
// Now check that it's shown if enabled and that it emits
|
|
|
|
// callButtonClicked
|
|
|
|
_converse.visible_toolbar_buttons.call = true; // enable the button
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
toolbar = view.el.querySelector('ul.chat-toolbar');
|
|
|
|
call_button = toolbar.querySelector('.toggle-call');
|
|
|
|
call_button.click();
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object));
|
2018-10-26 10:15:01 +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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-11-01 16:04:55 +01:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2019-01-25 11:53:07 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2015-01-01 21:25:12 +01:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2015-04-02 02:01:53 +02:00
|
|
|
// <composing> state
|
2019-11-01 16:04:55 +01:00
|
|
|
const stanza = $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();
|
2019-11-01 16:04:55 +01:00
|
|
|
|
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(stanza));
|
|
|
|
await u.waitUntil(() => _converse.api.trigger.calls.count());
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2019-11-01 16:04:55 +01:00
|
|
|
expect(_converse.chatboxviews.keys().length).toBe(1);
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-22 09:31:00 +01:00
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-03-25 23:31:05 +01:00
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
expect(stanza.getAttribute('to')).toBe(contact_jid);
|
|
|
|
expect(stanza.childNodes.length).toBe(3);
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('active');
|
|
|
|
expect(stanza.childNodes[1].tagName).toBe('no-store');
|
|
|
|
expect(stanza.childNodes[2].tagName).toBe('no-permanent-store');
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is sent when the user maximizes a minimized a chat box", mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
2019-03-25 23:31:05 +01:00
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
2018-11-22 09:31:00 +01:00
|
|
|
view.model.minimize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
view.model.maximize();
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.get('chat_state') === 'active', 1000);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
const calls = _.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
return call.args[0] instanceof Strophe.Builder;
|
|
|
|
});
|
|
|
|
expect(calls.length).toBe(1);
|
2019-03-25 23:31:05 +01:00
|
|
|
const stanza = calls[0].args[0].tree();
|
|
|
|
expect(stanza.getAttribute('to')).toBe(contact_jid);
|
|
|
|
expect(stanza.childNodes.length).toBe(3);
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('active');
|
|
|
|
expect(stanza.childNodes[1].tagName).toBe('no-store');
|
|
|
|
expect(stanza.childNodes[2].tagName).toBe('no-permanent-store');
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
spyOn(_converse.connection, 'send');
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-11-22 09:31:00 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
2015-01-01 21:25:12 +01:00
|
|
|
});
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-03-25 23:31:05 +01:00
|
|
|
|
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
expect(stanza.getAttribute('to')).toBe(contact_jid);
|
|
|
|
expect(stanza.childNodes.length).toBe(3);
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('composing');
|
|
|
|
expect(stanza.childNodes[1].tagName).toBe('no-store');
|
|
|
|
expect(stanza.childNodes[2].tagName).toBe('no-permanent-store');
|
2018-11-22 09:31:00 +01:00
|
|
|
|
|
|
|
// The notification is not sent again
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-11-22 09:31:00 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger.calls.count(), 1);
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2019-08-02 11:34:24 +02:00
|
|
|
it("is NOT sent out if send_chat_state_notifications doesn't allow it",
|
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {'send_chat_state_notifications': []},
|
2019-08-02 11:34:24 +02:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-08-02 11:34:24 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
|
|
|
|
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
|
|
|
view.onKeyDown({
|
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
expect(_converse.connection.send).not.toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be shown if received",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2019-03-04 17:49:44 +01:00
|
|
|
// See XEP-0085 https://xmpp.org/extensions/xep-0085.html#definitions
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2019-01-31 19:22:30 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
|
|
|
// <composing> state
|
2019-01-25 11:53:07 +01:00
|
|
|
let 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()
|
2019-11-01 16:04:55 +01:00
|
|
|
}).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
|
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(msg));
|
|
|
|
await u.waitUntil(() => _converse.api.trigger.calls.count());
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2019-11-01 16:04:55 +01:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2018-05-04 17:26:43 +02:00
|
|
|
expect(view).toBeDefined();
|
|
|
|
|
2019-10-24 17:55:20 +02:00
|
|
|
const event = await u.waitUntil(() => view.el.querySelector('.chat-state-notification'));
|
|
|
|
expect(event.textContent).toEqual(mock.cur_names[1] + ' is typing');
|
2018-05-04 17:26:43 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// Check that it doesn't appear twice
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2019-01-31 19:22:30 +01:00
|
|
|
}).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-24 17:55:20 +02:00
|
|
|
const events = view.el.querySelectorAll('.chat-state-notification');
|
2018-10-13 23:25:01 +02:00
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'montague.lit', [], ['vcard-temp']);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'));
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2018-11-22 09:31:00 +01:00
|
|
|
// Send a message from a different resource
|
2019-06-03 07:58:51 +02:00
|
|
|
const recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, recipient_jid);
|
2019-03-25 23:31:05 +01:00
|
|
|
const msg = $msg({
|
2018-11-22 09:31:00 +01:00
|
|
|
'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();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
// Check that the chatbox and its view now exist
|
2019-03-25 23:31:05 +01:00
|
|
|
const chatbox = _converse.chatboxes.get(recipient_jid);
|
|
|
|
const chatboxview = _converse.chatboxviews.get(recipient_jid);
|
2018-11-22 09:31:00 +01:00
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
2019-03-25 23:31:05 +01:00
|
|
|
const msg_obj = chatbox.messages.models[0];
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(msg_obj.get('sender')).toEqual('me');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
2019-03-25 23:31:05 +01:00
|
|
|
const chat_content = chatboxview.el.querySelector('.chat-content');
|
2019-10-24 17:55:20 +02:00
|
|
|
const el = await u.waitUntil(() => chat_content.querySelector('.chat-info.chat-state-notification'));
|
|
|
|
const status_text = el.textContent;
|
2018-11-22 09:31:00 +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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group li').length, 700);
|
2018-11-22 09:31:00 +01:00
|
|
|
_converse.TIMEOUTS.PAUSED = 200; // Make the timeout shorter so that we can test
|
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(_converse.connection, 'send');
|
2019-07-10 09:47:13 +02:00
|
|
|
spyOn(view.model, 'setChatState').and.callThrough();
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-11-22 09:31:00 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-03-25 23:31:05 +01:00
|
|
|
let stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('composing');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.get('chat_state') === 'paused', 500);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
|
|
|
var calls = _.filter(_converse.connection.send.calls.all(), function (call) {
|
|
|
|
return call.args[0] instanceof Strophe.Builder;
|
|
|
|
});
|
|
|
|
expect(calls.length).toBe(2);
|
2019-03-25 23:31:05 +01:00
|
|
|
stanza = calls[1].args[0].tree();
|
|
|
|
expect(stanza.getAttribute('to')).toBe(contact_jid);
|
|
|
|
expect(stanza.childNodes.length).toBe(3);
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('paused');
|
|
|
|
expect(stanza.childNodes[1].tagName).toBe('no-store');
|
|
|
|
expect(stanza.childNodes[2].tagName).toBe('no-permanent-store');
|
2018-11-22 09:31:00 +01:00
|
|
|
|
|
|
|
// Test #359. A paused notification should not be sent
|
|
|
|
// out if the user simply types longer than the
|
|
|
|
// timeout.
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-11-22 09:31:00 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
2019-07-10 09:47:13 +02:00
|
|
|
expect(view.model.setChatState).toHaveBeenCalled();
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-11-22 09:31:00 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
|
|
|
expect(view.model.get('chat_state')).toBe('composing');
|
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("will be shown if received",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-10-13 23:25:01 +02:00
|
|
|
// TODO: only show paused state if the previous state was composing
|
2019-03-04 17:49:44 +01:00
|
|
|
// See XEP-0085 https://xmpp.org/extensions/xep-0085.html#definitions
|
2019-03-29 21:10:45 +01:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-01-31 19:22:30 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, sender_jid);
|
2018-10-13 23:25:01 +02:00
|
|
|
// <paused> state
|
2018-11-22 09:31:00 +01:00
|
|
|
const msg = $msg({
|
2018-10-13 23:25:01 +02:00
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2019-01-31 19:22:30 +01:00
|
|
|
}).c('paused', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1])
|
2019-10-24 17:55:20 +02:00
|
|
|
const event = await u.waitUntil(() => view.el.querySelector('.chat-state-notification'));
|
2018-10-13 23:25:01 +02:00
|
|
|
expect(event.textContent).toEqual(mock.cur_names[1] + ' has stopped 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 paused carbon message that this user sent from a different client",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
await test_utils.waitUntilDiscoConfirmed(_converse, 'montague.lit', [], ['vcard-temp']);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.xmppstatus.vcard.get('fullname'));
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2018-11-22 09:31:00 +01:00
|
|
|
// Send a message from a different resource
|
2019-06-03 07:58:51 +02:00
|
|
|
const recipient_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, recipient_jid);
|
|
|
|
const 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();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
// Check that the chatbox and its view now exist
|
2019-03-25 23:31:05 +01:00
|
|
|
const chatbox = _converse.chatboxes.get(recipient_jid);
|
|
|
|
const chatboxview = _converse.chatboxviews.get(recipient_jid);
|
2018-11-22 09:31:00 +01:00
|
|
|
// Check that the message was received and check the message parameters
|
|
|
|
expect(chatbox.messages.length).toEqual(1);
|
2019-03-25 23:31:05 +01:00
|
|
|
const msg_obj = chatbox.messages.models[0];
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(msg_obj.get('sender')).toEqual('me');
|
|
|
|
expect(msg_obj.get('is_delayed')).toEqual(false);
|
2019-10-24 17:55:20 +02:00
|
|
|
const el = await u.waitUntil(() => chatboxview.el.querySelector('.chat-info.chat-state-notification'));
|
|
|
|
expect(el.textContent).toBe('Stopped typing on the other device');
|
2018-11-22 09:31:00 +01:00
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2018-08-02 08:30:37 +02:00
|
|
|
|
2019-07-12 00:46:17 +02:00
|
|
|
const sent_stanzas = _converse.connection.sent_stanzas;
|
2018-08-02 08:30:37 +02:00
|
|
|
// Make the timeouts shorter so that we can test
|
2019-07-12 00:46:17 +02:00
|
|
|
_converse.TIMEOUTS.PAUSED = 100;
|
|
|
|
_converse.TIMEOUTS.INACTIVE = 100;
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 1000);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
2019-07-12 00:46:17 +02:00
|
|
|
await u.waitUntil(() => view.model.get('chat_state') === 'active');
|
|
|
|
let messages = await u.waitUntil(() => sent_stanzas.filter(s => s.matches('message')));
|
|
|
|
expect(messages.length).toBe(1);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-11-22 09:31:00 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
|
|
|
keyCode: 1
|
|
|
|
});
|
2019-07-12 00:46:17 +02:00
|
|
|
await u.waitUntil(() => view.model.get('chat_state') === 'composing', 600);
|
|
|
|
messages = sent_stanzas.filter(s => s.matches('message'));
|
|
|
|
expect(messages.length).toBe(2);
|
|
|
|
|
|
|
|
await u.waitUntil(() => view.model.get('chat_state') === 'paused', 600);
|
|
|
|
messages = sent_stanzas.filter(s => s.matches('message'));
|
|
|
|
expect(messages.length).toBe(3);
|
|
|
|
|
|
|
|
await u.waitUntil(() => view.model.get('chat_state') === 'inactive', 600);
|
|
|
|
messages = sent_stanzas.filter(s => s.matches('message'));
|
|
|
|
expect(messages.length).toBe(4);
|
|
|
|
|
|
|
|
expect(Strophe.serialize(messages[0])).toBe(
|
|
|
|
`<message id="${messages[0].getAttribute('id')}" to="mercutio@montague.lit" type="chat" xmlns="jabber:client">`+
|
|
|
|
`<active xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<no-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`<no-permanent-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`</message>`);
|
|
|
|
expect(Strophe.serialize(messages[1])).toBe(
|
|
|
|
`<message id="${messages[1].getAttribute('id')}" to="mercutio@montague.lit" type="chat" xmlns="jabber:client">`+
|
|
|
|
`<composing xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<no-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`<no-permanent-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`</message>`);
|
|
|
|
expect(Strophe.serialize(messages[2])).toBe(
|
|
|
|
`<message id="${messages[2].getAttribute('id')}" to="mercutio@montague.lit" type="chat" xmlns="jabber:client">`+
|
|
|
|
`<paused xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<no-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`<no-permanent-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`</message>`);
|
|
|
|
expect(Strophe.serialize(messages[3])).toBe(
|
|
|
|
`<message id="${messages[3].getAttribute('id')}" to="mercutio@montague.lit" type="chat" xmlns="jabber:client">`+
|
|
|
|
`<inactive xmlns="http://jabber.org/protocol/chatstates"/>`+
|
|
|
|
`<no-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`<no-permanent-store xmlns="urn:xmpp:hints"/>`+
|
|
|
|
`</message>`);
|
2018-11-22 09:31:00 +01:00
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2015-01-09 09:02:35 +01:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
view.minimize();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-03-25 23:31:05 +01:00
|
|
|
var stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
expect(stanza.getAttribute('to')).toBe(contact_jid);
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('inactive');
|
2018-11-22 09:31:00 +01: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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length);
|
2018-11-22 09:31:00 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
expect(view.model.get('chat_state')).toBe('active');
|
|
|
|
spyOn(_converse.connection, 'send');
|
|
|
|
view.close();
|
|
|
|
expect(view.model.get('chat_state')).toBe('inactive');
|
|
|
|
expect(_converse.connection.send).toHaveBeenCalled();
|
2019-03-25 23:31:05 +01:00
|
|
|
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
|
|
|
|
expect(stanza.getAttribute('to')).toBe(contact_jid);
|
|
|
|
expect(stanza.childNodes.length).toBe(3);
|
|
|
|
expect(stanza.childNodes[0].tagName).toBe('inactive');
|
|
|
|
expect(stanza.childNodes[1].tagName).toBe('no-store');
|
|
|
|
expect(stanza.childNodes[2].tagName).toBe('no-permanent-store');
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2018-04-06 13:56:14 +02:00
|
|
|
it("will clear any other chat status notifications",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-10-25 08:21:38 +02:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-03-04 17:49:44 +01:00
|
|
|
// See XEP-0085 https://xmpp.org/extensions/xep-0085.html#definitions
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-10-25 08:21:38 +02:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
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.
|
|
|
|
let msg = $msg({
|
|
|
|
'to': _converse.bare_jid,
|
|
|
|
'xmlns': 'jabber:client',
|
|
|
|
'from': sender_jid,
|
|
|
|
'type': 'chat'})
|
|
|
|
.c('composing', {'xmlns': Strophe.NS.CHATSTATES}).up()
|
|
|
|
.tree();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2019-10-24 17:55:20 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chat-state-notification'));
|
2018-10-25 08:21:38 +02:00
|
|
|
expect(view.el.querySelectorAll('.chat-state-notification').length).toBe(1);
|
|
|
|
msg = $msg({
|
|
|
|
from: sender_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2019-11-01 16:04:55 +01:00
|
|
|
}).c('inactive', {'xmlns': Strophe.NS.CHATSTATES}).tree();
|
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => (view.model.messages.length > 1));
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2019-10-24 17:55:20 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-state-notification').length === 0);
|
2018-10-25 08:21:38 +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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 3);
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2015-01-09 09:02:35 +01:00
|
|
|
// <paused> state
|
2018-11-22 09:31:00 +01:00
|
|
|
const 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();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-11-22 09:31:00 +01:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.vcard.get('fullname') === mock.cur_names[1]);
|
2019-10-24 17:55:20 +02:00
|
|
|
const event = await u.waitUntil(() => view.el.querySelector('.chat-state-notification'));
|
2018-11-22 09:31:00 +01:00
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-06-03 07:58:51 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2019-08-01 10:26:35 +02:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
let message = 'This message is another sent from this chatbox';
|
2018-12-20 12:29:55 +01:00
|
|
|
await test_utils.sendMessage(view, message);
|
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(view.model.messages.length === 1).toBeTruthy();
|
|
|
|
let stored_messages = await view.model.messages.browserStorage.findAll();
|
|
|
|
expect(stored_messages.length).toBe(1);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelector('.chat-msg'));
|
2018-11-22 09:31:00 +01:00
|
|
|
|
|
|
|
message = '/clear';
|
|
|
|
spyOn(view, 'clearMessages').and.callThrough();
|
|
|
|
spyOn(window, 'confirm').and.callFake(function () {
|
|
|
|
return true;
|
2014-04-24 19:14:37 +02:00
|
|
|
});
|
2018-12-20 12:29:55 +01:00
|
|
|
view.el.querySelector('.chat-textarea').value = message;
|
2019-05-26 10:58:52 +02:00
|
|
|
view.onKeyDown({
|
2018-12-20 12:29:55 +01:00
|
|
|
target: view.el.querySelector('textarea.chat-textarea'),
|
2019-08-05 11:14:49 +02:00
|
|
|
preventDefault: function preventDefault () {},
|
2018-12-20 12:29:55 +01:00
|
|
|
keyCode: 13
|
|
|
|
});
|
2019-10-24 14:29:15 +02:00
|
|
|
expect(view.clearMessages.calls.all().length).toBe(1);
|
|
|
|
await view.clearMessages.calls.all()[0].returnValue;
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(window.confirm).toHaveBeenCalled();
|
|
|
|
expect(view.model.messages.length, 0); // The messages must be removed from the chatbox
|
2019-10-24 14:29:15 +02:00
|
|
|
stored_messages = await view.model.messages.browserStorage.findAll();
|
|
|
|
expect(stored_messages.length).toBe(0);
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger.calls.count(), 1);
|
|
|
|
expect(_converse.api.trigger.calls.mostRecent().args, ['messageSend', message]);
|
2018-11-22 09:31:00 +01: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",
|
2019-10-15 12:55:11 +02:00
|
|
|
mock.initConverse(
|
|
|
|
['rosterGroupsFetched'], {},
|
|
|
|
async function (done, _converse) {
|
2018-12-06 12:45:30 +01:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Converse Tests');
|
2018-12-06 12:45:30 +01:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-12-06 12:45:30 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, sender_jid)
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
const previous_state = _converse.windowState;
|
|
|
|
const message = 'This message will increment the message counter';
|
2018-12-06 12:45:30 +01:00
|
|
|
const msg = $msg({
|
2013-11-02 12:37:38 +01:00
|
|
|
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';
|
2018-12-06 12:45:30 +01:00
|
|
|
|
2019-03-29 21:10:45 +01:00
|
|
|
spyOn(_converse.api, "trigger").and.callThrough();
|
2018-12-06 12:45:30 +01:00
|
|
|
spyOn(_converse, 'incrementMsgCounter').and.callThrough();
|
|
|
|
spyOn(_converse, 'clearMsgCounter').and.callThrough();
|
|
|
|
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-10-09 16:01:38 +02:00
|
|
|
await new Promise(resolve => view.once('messageInserted', resolve));
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(_converse.incrementMsgCounter).toHaveBeenCalled();
|
|
|
|
expect(_converse.clearMsgCounter).not.toHaveBeenCalled();
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Messages (1) Converse Tests');
|
2019-03-29 21:10:45 +01:00
|
|
|
expect(_converse.api.trigger).toHaveBeenCalledWith('message', jasmine.any(Object));
|
2018-11-22 09:31:00 +01:00
|
|
|
_converse.windowSate = previous_state;
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-02-24 11:44:34 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched'], {},
|
2019-01-25 11:53:07 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2013-11-02 12:37:38 +01:00
|
|
|
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Converse Tests');
|
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');
|
2019-01-25 11:53:07 +01:00
|
|
|
const message = 'This message will not increment the message counter';
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
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();
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.incrementMsgCounter).not.toHaveBeenCalled();
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Converse Tests');
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'emojisInitialized'], {},
|
2018-10-13 23:25:01 +02:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2017-05-01 13:05:58 +02:00
|
|
|
// initial state
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Converse Tests');
|
2018-08-18 11:28:51 +02:00
|
|
|
const message = 'This message will always increment the message counter from zero',
|
2019-06-03 07:58:51 +02:00
|
|
|
sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
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';
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msgFactory());
|
2018-10-13 23:25:01 +02:00
|
|
|
let view = _converse.chatboxviews.get(sender_jid);
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Messages (1) Converse Tests');
|
2017-05-01 13:05:58 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// come back to converse-chat page
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
2019-11-01 16:04:55 +01:00
|
|
|
await u.waitUntil(() => u.isVisible(view.el));
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Converse Tests');
|
2017-05-01 13:05:58 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// close chatbox and leave converse-chat page again
|
|
|
|
view.close();
|
|
|
|
_converse.windowState = 'hidden';
|
2017-05-01 13:05:58 +02:00
|
|
|
|
2018-10-13 23:25:01 +02:00
|
|
|
// check that msg_counter is incremented from zero again
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msgFactory());
|
2018-10-13 23:25:01 +02:00
|
|
|
view = _converse.chatboxviews.get(sender_jid);
|
|
|
|
expect(u.isVisible(view.el)).toBeTruthy();
|
2019-10-15 12:55:11 +02:00
|
|
|
expect(document.title).toBe('Messages (1) Converse Tests');
|
2018-10-13 23:25:01 +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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2018-07-30 18:16:32 +02:00
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, sender_jid)
|
|
|
|
view.model.save('scrolled', true);
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(view.model.get('num_unread')).toBe(1);
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit',
|
2018-07-30 18:16:32 +02:00
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be read');
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatbox.get('num_unread')).toBe(0);
|
|
|
|
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",
|
2019-10-11 16:38:01 +02:00
|
|
|
mock.initConverse(['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current');
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-08-18 11:28:51 +02:00
|
|
|
const msgFactory = function () {
|
2017-05-03 09:06:28 +02:00
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
};
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
_converse.windowState = 'hidden';
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const msgFactory = () => test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
_converse.windowState = 'hidden';
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const msgFactory = () => test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
_converse.windowState = 'hidden';
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
expect(chatbox.get('num_unread')).toBe(0);
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const msgFactory = () => test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
_converse.windowState = 'hidden';
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
_converse.saveWindowState(null, 'focus');
|
|
|
|
expect(chatbox.get('num_unread')).toBe(1);
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2018-11-22 09:31:00 +01:00
|
|
|
let msg, indicator_el;
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 500);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2019-02-24 11:44:34 +01:00
|
|
|
const selector = 'a.open-chat:contains("' + chatbox.get('nickname') + '") .msgs-indicator';
|
2018-11-22 09:31:00 +01:00
|
|
|
indicator_el = sizzle(selector, _converse.rosterview.el).pop();
|
|
|
|
expect(indicator_el.textContent).toBe('1');
|
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread too');
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length > 1);
|
2018-11-22 09:31:00 +01:00
|
|
|
indicator_el = sizzle(selector, _converse.rosterview.el).pop();
|
|
|
|
expect(indicator_el.textContent).toBe('2');
|
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is updated when message is received and chatbox is minimized",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
let indicator_el, msg;
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 500);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
var chatboxview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatboxview.minimize();
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread');
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2019-02-24 11:44:34 +01:00
|
|
|
const selector = 'a.open-chat:contains("' + chatbox.get('nickname') + '") .msgs-indicator';
|
2018-11-22 09:31:00 +01:00
|
|
|
indicator_el = sizzle(selector, _converse.rosterview.el).pop();
|
|
|
|
expect(indicator_el.textContent).toBe('1');
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
msg = test_utils.createChatMessage(_converse, sender_jid, 'This message will be unread too');
|
2019-11-01 16:04:55 +01:00
|
|
|
await _converse.handleMessageStanza(msg);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length === 2);
|
2018-11-22 09:31:00 +01:00
|
|
|
indicator_el = sizzle(selector, _converse.rosterview.el).pop();
|
|
|
|
expect(indicator_el.textContent).toBe('2');
|
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is cleared when chatbox is maximzied after receiving messages in minimized mode",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const msgFactory = () => test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 500);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-02-24 11:44:34 +01:00
|
|
|
const selector = 'a.open-chat:contains("' + chatbox.get('nickname') + '") .msgs-indicator';
|
|
|
|
const select_msgs_indicator = () => sizzle(selector, _converse.rosterview.el).pop();
|
2018-11-22 09:31:00 +01:00
|
|
|
view.minimize();
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator().textContent).toBe('1');
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length > 1);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator().textContent).toBe('2');
|
2019-06-27 11:27:05 +02:00
|
|
|
view.model.maximize();
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator()).toBeUndefined();
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
2017-07-15 11:55:07 +02:00
|
|
|
it("is cleared when unread messages are viewed which were received in scrolled-up chatbox",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
await test_utils.openControlBox(_converse);
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 500);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
const msgFactory = () => test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
2019-07-11 12:30:51 +02:00
|
|
|
const selector = `a.open-chat:contains("${chatbox.get('nickname')}") .msgs-indicator`;
|
2019-02-24 11:44:34 +01:00
|
|
|
const select_msgs_indicator = () => sizzle(selector, _converse.rosterview.el).pop();
|
2018-11-22 09:31:00 +01:00
|
|
|
chatbox.save('scrolled', true);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 12:30:51 +02:00
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator().textContent).toBe('1');
|
2018-11-22 09:31:00 +01:00
|
|
|
view.viewUnreadMessages();
|
|
|
|
_converse.rosterview.render();
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator()).toBeUndefined();
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => _converse.rosterview.el.querySelectorAll('.roster-group').length, 500);
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
const view = _converse.chatboxviews.get(sender_jid);
|
2019-02-24 11:44:34 +01:00
|
|
|
const msg = 'This message will be received as unread, but eventually will be read';
|
|
|
|
const msgFactory = () => test_utils.createChatMessage(_converse, sender_jid, msg);
|
|
|
|
const selector = 'a.open-chat:contains("' + chatbox.get('nickname') + '") .msgs-indicator';
|
|
|
|
const select_msgs_indicator = () => sizzle(selector, _converse.rosterview.el).pop();
|
2018-11-22 09:31:00 +01:00
|
|
|
chatbox.save('scrolled', true);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator().textContent).toBe('1');
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
2019-02-24 11:44:34 +01:00
|
|
|
expect(select_msgs_indicator().textContent).toBe('1');
|
2018-11-22 09:31:00 +01:00
|
|
|
done();
|
2017-05-03 09:06:28 +02:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, sender_jid);
|
|
|
|
const msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid, 'This message will be received as unread, but eventually will be read');
|
|
|
|
};
|
|
|
|
const selectUnreadMsgCount = function () {
|
|
|
|
const minimizedChatBoxView = _converse.minimized_chats.get(sender_jid);
|
|
|
|
return minimizedChatBoxView.el.querySelector('.message-count');
|
|
|
|
};
|
|
|
|
const chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
chatbox.save('scrolled', true);
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => chatbox.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
const chatboxview = _converse.chatboxviews.get(sender_jid);
|
|
|
|
chatboxview.minimize();
|
2017-05-03 09:06:28 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
const unread_count = selectUnreadMsgCount();
|
|
|
|
expect(u.isVisible(unread_count)).toBeTruthy();
|
|
|
|
expect(unread_count.innerHTML).toBe('1');
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched', 'emojisInitialized'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2017-07-11 10:41:11 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2019-06-03 07:58:51 +02:00
|
|
|
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-11-22 09:31:00 +01:00
|
|
|
const view = await test_utils.openChatBoxFor(_converse, sender_jid)
|
|
|
|
const msgFactory = function () {
|
|
|
|
return test_utils.createChatMessage(_converse, sender_jid,
|
|
|
|
'This message will be received as unread, but eventually will be read');
|
|
|
|
};
|
|
|
|
const selectUnreadMsgCount = function () {
|
|
|
|
const minimizedChatBoxView = _converse.minimized_chats.get(sender_jid);
|
|
|
|
return minimizedChatBoxView.el.querySelector('.message-count');
|
|
|
|
};
|
|
|
|
view.minimize();
|
2019-11-01 16:04:55 +01:00
|
|
|
_converse.handleMessageStanza(msgFactory());
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.model.messages.length);
|
2018-11-22 09:31:00 +01:00
|
|
|
const unread_count = selectUnreadMsgCount();
|
|
|
|
expect(u.isVisible(unread_count)).toBeTruthy();
|
|
|
|
expect(unread_count.innerHTML).toBe('1');
|
|
|
|
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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2018-11-22 09:31:00 +01:00
|
|
|
async function (done, _converse) {
|
2018-03-31 18:29:01 +02:00
|
|
|
|
2019-02-24 11:44:34 +01:00
|
|
|
await test_utils.waitForRoster(_converse, 'current', 1);
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2019-10-09 16:01:38 +02:00
|
|
|
const message = "geo:37.786971,-122.399677",
|
2019-06-03 07:58:51 +02:00
|
|
|
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
|
2018-07-30 18:16:32 +02:00
|
|
|
|
2018-11-22 09:31:00 +01:00
|
|
|
await test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
const view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(view.model, 'sendMessage').and.callThrough();
|
|
|
|
test_utils.sendMessage(view, message);
|
2019-07-11 22:50:30 +02:00
|
|
|
await u.waitUntil(() => view.el.querySelectorAll('.chat-content .chat-msg').length, 1000);
|
2018-11-22 09:31:00 +01:00
|
|
|
expect(view.model.sendMessage).toHaveBeenCalled();
|
2019-03-25 23:31:05 +01:00
|
|
|
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view.el).pop();
|
|
|
|
expect(msg.innerHTML).toEqual(
|
2018-11-22 09:31:00 +01:00
|
|
|
'<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();
|
2018-07-30 18:16:32 +02:00
|
|
|
}));
|
2017-05-03 09:06:28 +02:00
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}));
|
2019-07-11 12:30:51 +02:00
|
|
|
|