2015-10-25 18:49:35 +01:00
|
|
|
/*global converse */
|
2014-06-21 23:01:56 +02:00
|
|
|
(function (root, factory) {
|
|
|
|
define([
|
2014-10-15 19:16:02 +02:00
|
|
|
"jquery",
|
2015-10-25 18:49:35 +01:00
|
|
|
"underscore",
|
2014-06-21 23:01:56 +02:00
|
|
|
"mock",
|
2014-08-08 22:06:01 +02:00
|
|
|
"test_utils"
|
2015-10-25 18:49:35 +01:00
|
|
|
], function ($, _, mock, test_utils) {
|
|
|
|
return factory($, _, mock, test_utils);
|
2014-06-21 23:01:56 +02:00
|
|
|
}
|
|
|
|
);
|
2015-10-25 18:49:35 +01:00
|
|
|
} (this, function ($, _, mock, test_utils) {
|
2015-02-01 16:15:34 +01:00
|
|
|
var $msg = converse_api.env.$msg;
|
|
|
|
|
2014-08-08 22:06:01 +02:00
|
|
|
return describe("The Minimized Chats Widget", $.proxy(function(mock, test_utils) {
|
2014-06-21 23:01:56 +02:00
|
|
|
beforeEach(function () {
|
|
|
|
runs(function () {
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.closeAllChatBoxes();
|
|
|
|
test_utils.removeControlBox();
|
2014-06-30 19:21:16 +02:00
|
|
|
converse.roster.browserStorage._clear();
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.initConverse();
|
2014-08-18 20:37:38 +02:00
|
|
|
test_utils.createContacts('current');
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openControlBox();
|
|
|
|
test_utils.openContactsPanel();
|
2014-06-30 19:21:16 +02:00
|
|
|
converse.minimized_chats.toggleview.model.browserStorage._clear();
|
2014-06-21 23:01:56 +02:00
|
|
|
converse.minimized_chats.initToggle();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shows chats that have been minimized", $.proxy(function () {
|
|
|
|
var contact_jid, chatview;
|
2014-06-30 20:26:45 +02:00
|
|
|
contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
chatview = converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
|
|
|
|
expect(this.minimized_chats.keys().length).toBe(1);
|
|
|
|
expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
|
|
|
|
|
2014-06-30 20:26:45 +02:00
|
|
|
contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
chatview = converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(chatview.model.get('minimized')).toBeFalsy();
|
|
|
|
chatview.$el.find('.toggle-chatbox-button').click();
|
|
|
|
expect(chatview.model.get('minimized')).toBeTruthy();
|
|
|
|
expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
|
|
|
|
expect(this.minimized_chats.keys().length).toBe(2);
|
|
|
|
expect(_.contains(this.minimized_chats.keys(), contact_jid)).toBeTruthy();
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("can be toggled to hide or show minimized chats", $.proxy(function () {
|
2014-06-30 20:26:45 +02:00
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
var chatview = converse.chatboxviews.get(contact_jid);
|
|
|
|
expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
|
|
|
|
expect(this.minimized_chats.keys().length).toBe(1);
|
|
|
|
expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
|
|
|
|
expect(this.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
|
|
|
|
expect(this.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
|
|
|
|
this.minimized_chats.$('#toggle-minimized-chats').click();
|
|
|
|
expect(this.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
|
|
|
|
expect(this.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
|
|
|
|
}, converse));
|
|
|
|
|
|
|
|
it("shows the number messages received to minimized chats", $.proxy(function () {
|
|
|
|
var i, contact_jid, chatview, msg;
|
|
|
|
this.minimized_chats.toggleview.model.set({'collapsed': true});
|
2014-06-29 15:59:39 +02:00
|
|
|
expect(this.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';
|
2014-08-08 22:06:01 +02:00
|
|
|
test_utils.openChatBoxFor(contact_jid);
|
2014-06-21 23:01:56 +02:00
|
|
|
chatview = converse.chatboxviews.get(contact_jid);
|
|
|
|
chatview.model.set({'minimized': true});
|
|
|
|
msg = $msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: this.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();
|
|
|
|
this.chatboxes.onMessage(msg);
|
2014-06-29 15:59:39 +02:00
|
|
|
expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy();
|
2014-06-29 18:30:01 +02:00
|
|
|
expect(this.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
|
|
|
|
this.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('composing', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
|
|
|
|
|
|
|
// <paused> state
|
|
|
|
this.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
|
|
|
|
|
|
|
// <gone> state
|
|
|
|
this.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('gone', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
|
|
|
|
|
|
|
// <inactive> state
|
|
|
|
this.chatboxes.onMessage($msg({
|
|
|
|
from: contact_jid,
|
|
|
|
to: this.connection.jid,
|
|
|
|
type: 'chat',
|
|
|
|
id: (new Date()).getTime()
|
|
|
|
}).c('inactive', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
|
|
|
|
expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
|
2014-06-21 23:01:56 +02:00
|
|
|
}, converse));
|
|
|
|
|
2014-08-08 22:06:01 +02:00
|
|
|
}, converse, mock, test_utils));
|
2014-06-21 23:01:56 +02:00
|
|
|
}));
|