Commit c594e5a1 authored by JC Brand's avatar JC Brand

Add new test for trimmed chats

parent 9d96b1bf
...@@ -2666,15 +2666,7 @@ ...@@ -2666,15 +2666,7 @@
initialize: function () { initialize: function () {
this.model.on("change:trimmed", function (item) { this.model.on("change:trimmed", function (item) {
var view; this.onChanged(item);
if (item.get('trimmed')) {
view = new converse.TrimmedChatBoxView({model: item});
this.$('.box-flyout').append(view.render());
this.add(item.get('id'), view);
} else {
view = this.get(item.get('id'));
view.restore();
}
}, this); }, this);
}, },
...@@ -2682,7 +2674,7 @@ ...@@ -2682,7 +2674,7 @@
return this.$el; return this.$el;
}, },
_ensureElement: function() { _ensureElement: function () {
/* Override method from backbone.js /* Override method from backbone.js
* Make sure that the el and $el attributes point to a DOM snippet * Make sure that the el and $el attributes point to a DOM snippet
* from src/templates/trimmed_chats.html * from src/templates/trimmed_chats.html
...@@ -2694,6 +2686,18 @@ ...@@ -2694,6 +2686,18 @@
this.setElement(_.result(this, 'el'), false); this.setElement(_.result(this, 'el'), false);
} }
}, },
onChanged: function (item) {
var view;
if (item.get('trimmed')) {
view = new converse.TrimmedChatBoxView({model: item});
this.$('.box-flyout').append(view.render());
this.add(item.get('id'), view);
} else {
view = this.get(item.get('id'));
view.restore();
}
}
}); });
this.RosterItem = Backbone.Model.extend({ this.RosterItem = Backbone.Model.extend({
......
...@@ -56,6 +56,38 @@ ...@@ -56,6 +56,38 @@
} }
}, converse)); }, converse));
it("can be trimmed to conserve space", $.proxy(function () {
var i, $el, click, jid, view, chatboxview;
// openControlBox was called earlier, so the controlbox is
// visible, but no other chat boxes have been created.
var trimmed_chatboxes = converse.chatboxviews.trimmed_chatboxes_view;
expect(this.chatboxes.length).toEqual(1);
spyOn(this.chatboxviews, 'trimChats');
spyOn(trimmed_chatboxes, 'onChanged').andCallThrough();
expect($("#conversejs .chatbox").length).toBe(1); // Controlbox is open
var online_contacts = this.rosterview.$el.find('dt#xmpp-contacts').siblings('dd.current-xmpp-contact').find('a.open-chat');
for (i=0; i<online_contacts.length; i++) {
$el = $(online_contacts[i]);
jid = $el.text().replace(' ','.').toLowerCase() + '@localhost';
view = this.rosterview.get(jid);
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
$el.click();
expect(this.chatboxviews.trimChats).toHaveBeenCalled();
chatboxview = this.chatboxviews.get(jid);
spyOn(chatboxview, 'trim').andCallThrough();
chatboxview.model.set({'trimmed': true});
expect(trimmed_chatboxes.onChanged).toHaveBeenCalled();
expect(chatboxview.trim).toHaveBeenCalled();
trimmedview = trimmed_chatboxes.get(jid);
expect(trimmedview.$el.is(":visible")).toBeTruthy();
}
}, converse));
it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () { it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () {
var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[2].replace(' ','.').toLowerCase() + '@localhost';
var i, $el, click, jid, view, chatboxview, chatbox; var i, $el, click, jid, view, chatboxview, chatbox;
......
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