2014-06-21 23:01:56 +02:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jquery", "jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function ($, jasmine, mock, test_utils) {
|
2018-07-30 18:16:32 +02:00
|
|
|
const _ = converse.env._;
|
|
|
|
const $msg = converse.env.$msg;
|
|
|
|
const u = converse.env.utils;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The Minimized Chats Widget", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows chats that have been minimized",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2018-07-30 18:16:32 +02:00
|
|
|
_converse.emit('rosterContactsFetched');
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.minimized_chats.toggleview.model.browserStorage._clear();
|
|
|
|
_converse.minimized_chats.initToggle();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2018-07-30 18:16:32 +02:00
|
|
|
let contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
let chatview;
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid)
|
|
|
|
.then(() => {
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
expect($(_converse.minimized_chats.el).is(':visible')).toBeFalsy();
|
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
expect($(_converse.minimized_chats.el).is(':visible')).toBeTruthy();
|
|
|
|
expect(_converse.minimized_chats.keys().length).toBe(1);
|
|
|
|
expect(_converse.minimized_chats.keys()[0]).toBe(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
|
2018-07-30 18:16:32 +02:00
|
|
|
contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
return test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
}).then(() => {
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
chatview.el.querySelector('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
expect($(_converse.minimized_chats.el).is(':visible')).toBeTruthy();
|
|
|
|
expect(_converse.minimized_chats.keys().length).toBe(2);
|
|
|
|
expect(_.includes(_converse.minimized_chats.keys(), contact_jid)).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("can be toggled to hide or show minimized chats",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2018-07-30 18:16:32 +02:00
|
|
|
_converse.emit('rosterContactsFetched');
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.minimized_chats.toggleview.model.browserStorage._clear();
|
|
|
|
_converse.minimized_chats.initToggle();
|
2014-06-21 23:01:56 +02:00
|
|
|
|
2018-07-30 18:16:32 +02:00
|
|
|
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid)
|
|
|
|
.then(() => {
|
|
|
|
const chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(u.isVisible(_converse.minimized_chats.el)).toBeFalsy();
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
expect(u.isVisible(_converse.minimized_chats.el)).toBeTruthy();
|
|
|
|
expect(_converse.minimized_chats.keys().length).toBe(1);
|
|
|
|
expect(_converse.minimized_chats.keys()[0]).toBe(contact_jid);
|
|
|
|
expect(u.isVisible(_converse.minimized_chats.el.querySelector('.minimized-chats-flyout'))).toBeTruthy();
|
|
|
|
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
|
|
|
|
_converse.minimized_chats.el.querySelector('#toggle-minimized-chats').click();
|
|
|
|
return test_utils.waitUntil(() => u.isVisible(_converse.minimized_chats.el.querySelector('.minimized-chats-flyout')));
|
|
|
|
}).then(() => {
|
2018-01-03 14:58:05 +01:00
|
|
|
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows the number messages received to minimized chats",
|
|
|
|
mock.initConverseWithPromises(
|
2018-07-30 18:16:32 +02:00
|
|
|
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
|
2017-07-11 10:41:11 +02:00
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.createContacts(_converse, 'current');
|
2018-07-30 18:16:32 +02:00
|
|
|
_converse.emit('rosterContactsFetched');
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.minimized_chats.toggleview.model.browserStorage._clear();
|
|
|
|
_converse.minimized_chats.initToggle();
|
2014-06-21 23:01:56 +02:00
|
|
|
|
|
|
|
var i, contact_jid, chatview, msg;
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.minimized_chats.toggleview.model.set({'collapsed': true});
|
2018-07-30 18:16:32 +02:00
|
|
|
|
|
|
|
const unread_el = _converse.minimized_chats.toggleview.el.querySelector('.unread-message-count');
|
|
|
|
expect(_.isNull(unread_el)).toBe(true);
|
|
|
|
|
2014-06-21 23:01:56 +02:00
|
|
|
for (i=0; i<3; i++) {
|
2014-06-30 20:26:45 +02:00
|
|
|
contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
2018-07-30 18:16:32 +02:00
|
|
|
}
|
|
|
|
return test_utils.waitUntil(() => _converse.chatboxes.length == 4).then(() => {
|
|
|
|
for (i=0; i<3; i++) {
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('body').t('This message is sent to a minimized chatbox').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).is(':visible')).toBeTruthy();
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).text()).toBe((i+1).toString());
|
|
|
|
}
|
|
|
|
// Chat state notifications don't increment the unread messages counter
|
|
|
|
// <composing> state
|
|
|
|
_converse.chatboxes.onMessage($msg({
|
2014-06-21 23:01:56 +02:00
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-06-21 23:01:56 +02:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
2018-07-30 18:16:32 +02:00
|
|
|
}).c('composing', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).text()).toBe((i).toString());
|
|
|
|
|
|
|
|
// <paused> state
|
|
|
|
_converse.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).text()).toBe((i).toString());
|
|
|
|
|
|
|
|
// <gone> state
|
|
|
|
_converse.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('gone', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).text()).toBe((i).toString());
|
|
|
|
|
|
|
|
// <inactive> state
|
|
|
|
_converse.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: _converse.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('inactive', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).text()).toBe((i).toString());
|
|
|
|
done();
|
|
|
|
});
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2017-05-23 18:38:33 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("shows the number messages received to minimized groupchats",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-05-23 18:38:33 +02:00
|
|
|
var room_jid = 'kitchen@conference.shakespeare.lit';
|
|
|
|
test_utils.openAndEnterChatRoom(
|
2017-07-12 09:55:43 +02:00
|
|
|
_converse, 'kitchen', 'conference.shakespeare.lit', 'fires').then(function () {
|
|
|
|
var view = _converse.chatboxviews.get(room_jid);
|
|
|
|
view.model.set({'minimized': true});
|
|
|
|
|
|
|
|
var contact_jid = mock.cur_names[5].replace(/ /g,'.').toLowerCase() + '@localhost';
|
|
|
|
var message = 'fires: Your attention is required';
|
|
|
|
var nick = mock.chatroom_names[0],
|
|
|
|
msg = $msg({
|
|
|
|
from: room_jid+'/'+nick,
|
|
|
|
id: (new Date()).getTime(),
|
|
|
|
to: 'dummy@localhost',
|
|
|
|
type: 'groupchat'
|
|
|
|
}).c('body').t(message).tree();
|
2018-04-08 19:44:53 +02:00
|
|
|
view.model.onMessage(msg);
|
2017-05-23 18:38:33 +02:00
|
|
|
|
2018-01-03 20:02:05 +01:00
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).is(':visible')).toBeTruthy();
|
|
|
|
expect($(_converse.minimized_chats.toggleview.el.querySelector('.unread-message-count')).text()).toBe('1');
|
2017-07-12 09:55:43 +02:00
|
|
|
done();
|
|
|
|
});
|
2017-05-23 18:38:33 +02:00
|
|
|
}));
|
2016-11-03 11:01:09 +01:00
|
|
|
});
|
2014-06-21 23:01:56 +02:00
|
|
|
}));
|