2014-06-21 23:01:56 +02:00
|
|
|
(function (root, factory) {
|
2016-11-30 13:18:58 +01:00
|
|
|
define(["mock", "converse-api", "test_utils"], factory);
|
2016-12-20 10:30:20 +01:00
|
|
|
} (this, function (mock, converse, test_utils) {
|
|
|
|
var _ = converse.env._;
|
|
|
|
var $msg = converse.env.$msg;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
describe("The Minimized Chats Widget", function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("shows chats that have been minimized", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
_converse.minimized_chats.toggleview.model.browserStorage._clear();
|
|
|
|
_converse.minimized_chats.initToggle();
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2014-06-21 23:01:56 +02:00
|
|
|
var contact_jid, chatview;
|
2014-06-30 20:26:45 +02:00
|
|
|
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.minimized_chats.$el.is(':visible')).toBeFalsy();
|
2014-06-21 23:01:56 +02:00
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
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
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
2016-12-20 10:30:20 +01:00
|
|
|
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();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can be toggled to hide or show minimized chats", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
_converse.minimized_chats.toggleview.model.browserStorage._clear();
|
|
|
|
_converse.minimized_chats.initToggle();
|
2014-06-21 23:01:56 +02:00
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var chatview = _converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(_converse.minimized_chats.$el.is(':visible')).toBeFalsy();
|
2014-06-21 23:01:56 +02:00
|
|
|
chatview.model.set({'minimized': true});
|
2016-12-20 10:30:20 +01:00
|
|
|
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);
|
|
|
|
expect(_converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
|
|
|
|
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
|
|
|
|
_converse.minimized_chats.$('#toggle-minimized-chats').click();
|
|
|
|
expect(_converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
|
|
|
|
expect(_converse.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("shows the number messages received to minimized chats", mock.initConverse(function (_converse) {
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
_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});
|
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
|
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);
|
|
|
|
chatview = _converse.chatboxviews.get(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
msg = $msg({
|
|
|
|
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()
|
|
|
|
}).c('body').t('This message is sent to a minimized chatbox').up()
|
|
|
|
.c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage(msg);
|
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy();
|
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i+1).toString());
|
2014-06-21 23:01:56 +02:00
|
|
|
}
|
2014-10-30 11:48:58 +01:00
|
|
|
// Chat state notifications don't increment the unread messages counter
|
|
|
|
// <composing> state
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage($msg({
|
2014-10-30 11:48:58 +01:00
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-10-30 11:48:58 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('composing', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
2014-10-30 11:48:58 +01:00
|
|
|
|
|
|
|
// <paused> state
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage($msg({
|
2014-10-30 11:48:58 +01:00
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-10-30 11:48:58 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
2014-10-30 11:48:58 +01:00
|
|
|
|
|
|
|
// <gone> state
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage($msg({
|
2014-10-30 11:48:58 +01:00
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-10-30 11:48:58 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('gone', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
2014-10-30 11:48:58 +01:00
|
|
|
|
|
|
|
// <inactive> state
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.chatboxes.onMessage($msg({
|
2014-10-30 11:48:58 +01:00
|
|
|
from: contact_jid,
|
2016-12-20 10:30:20 +01:00
|
|
|
to: _converse.connection.jid,
|
2014-10-30 11:48:58 +01:00
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('inactive', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
2016-12-20 10:30:20 +01:00
|
|
|
expect(_converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
});
|
2014-06-21 23:01:56 +02:00
|
|
|
}));
|