Commit 4b8196cd authored by JC Brand's avatar JC Brand

Add more tests around minimized chats.

parent c3dcbbc6
......@@ -2690,11 +2690,7 @@
initialize: function () {
this.initToggle();
this.model.on("add", function (item) {
if (item.get('minimized')) {
this.addChat(item);
}
}, this);
this.model.on("add", this.onChanged, this);
this.model.on("destroy", this.removeChat, this);
this.model.on("change:minimized", this.onChanged, this);
},
......@@ -2722,14 +2718,14 @@
if (ev && ev.preventDefault) {
ev.preventDefault();
}
this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')})
this.toggleview.model.save({'collapsed': !this.toggleview.model.get('collapsed')});
this.$('.minimized-chats-flyout').toggle();
},
onChanged: function (item) {
if (item.get('minimized')) {
if (item.get('id') !== 'controlbox' && item.get('minimized')) {
this.addChat(item);
} else {
} else if (this.get(item.get('id'))) {
this.removeChat(item);
}
},
......
......@@ -13,16 +13,10 @@
runs(function () {
utils.closeAllChatBoxes();
utils.removeControlBox();
});
waits(250);
runs(function () {
converse.roster.localStorage._clear();
utils.initConverse();
utils.createCurrentContacts();
utils.openControlBox();
});
waits(250);
runs(function () {
utils.openContactsPanel();
});
});
......@@ -462,9 +456,6 @@
spyOn(this, 'emit');
runs(function () {
utils.openChatBoxFor(contact_jid);
});
waits(50);
runs(function () {
var chatview = converse.chatboxviews.get(contact_jid);
expect(chatview.model.get('minimized')).toBeFalsy();
chatview.$el.find('.toggle-chatbox-button').click();
......@@ -521,7 +512,7 @@
expect(trimmed_chatboxes.keys().length).toBe(0);
}, converse));
}, converse));
it("will indicate when it has a time difference of more than a day between it and its predecessor", $.proxy(function () {
spyOn(converse, 'emit');
var contact_name = mock.cur_names[1];
......
(function (root, factory) {
define([
"mock",
"utils"
], function (mock, utils) {
return factory(mock, utils);
}
);
} (this, function (mock, utils) {
return describe("The Minimized Chats Widget", $.proxy(function(mock, utils) {
beforeEach(function () {
runs(function () {
utils.closeAllChatBoxes();
utils.removeControlBox();
converse.roster.localStorage._clear();
utils.initConverse();
utils.createCurrentContacts();
utils.openControlBox();
utils.openContactsPanel();
converse.minimized_chats.toggleview.model.localStorage._clear();
converse.minimized_chats.initToggle();
});
});
it("shows chats that have been minimized", $.proxy(function () {
var contact_jid, chatview;
contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid);
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);
contact_jid = mock.cur_names[1].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid);
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 () {
var contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid);
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;
var sender_jid = mock.cur_names[4].replace(' ','.').toLowerCase() + '@localhost';
this.minimized_chats.toggleview.model.set({'collapsed': true});
for (i=0; i<3; i++) {
contact_jid = mock.cur_names[i].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid);
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);
}
}, converse));
}, converse, mock, utils));
}));
......@@ -63,7 +63,8 @@ require([
"spec/eventemitter",
"spec/controlbox",
"spec/chatbox",
"spec/chatroom"
"spec/chatroom",
"spec/minchats"
], function () {
// Make sure this callback is only called once.
delete converse.callback;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment