Fix trimming/minimize tests broken after recent refactor

This commit is contained in:
JC Brand 2014-06-16 00:03:34 +02:00
parent c9d7e17a10
commit 1bea7a1a97
2 changed files with 31 additions and 32 deletions

View File

@ -25,8 +25,6 @@
runs(function () {
utils.openContactsPanel();
});
waits(250);
runs(function () {});
});
it("is created when you click on a roster item", $.proxy(function () {
@ -57,13 +55,14 @@
}, converse));
it("can be trimmed to conserve space", $.proxy(function () {
var i, $el, click, jid, key, view, chatboxview;
var i, $el, click, jid, key, view, chatbox, 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;
var trimmed_chatboxes = converse.minimized_chats;
expect(this.chatboxes.length).toEqual(1);
spyOn(this.chatboxviews, 'trimChats');
spyOn(trimmed_chatboxes, 'onChanged').andCallThrough();
spyOn(trimmed_chatboxes, 'addChat').andCallThrough();
spyOn(trimmed_chatboxes, 'removeChat').andCallThrough();
expect($("#conversejs .chatbox").length).toBe(1); // Controlbox is open
// Test that they can be trimmed
@ -72,33 +71,34 @@
$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, 'hide').andCallThrough();
chatboxview.model.set({'minimized': true});
expect(trimmed_chatboxes.onChanged).toHaveBeenCalled();
expect(trimmed_chatboxes.addChat).toHaveBeenCalled();
expect(chatboxview.hide).toHaveBeenCalled();
trimmedview = trimmed_chatboxes.get(jid);
expect(trimmedview.$el.is(":visible")).toBeTruthy();
}
// Test that they can be maximized again
var chatboxviews = this.chatboxviews.getAll();
var keys = _.keys(chatboxviews);
for (i=0; i<keys.length; i++) {
key = keys[i];
if (key === 'controlbox') {
continue;
}
chatboxview = chatboxviews[key];
runs($.proxy(function () {
var key = this.chatboxviews.keys()[1];
trimmedview = trimmed_chatboxes.get(key);
spyOn(chatboxview, 'maximize').andCallThrough();
chatbox = trimmedview.model;
spyOn(chatbox, 'maximize').andCallThrough();
spyOn(trimmedview, 'restore').andCallThrough();
trimmedview.delegateEvents();
trimmedview.$("a.restore-chat").click();
expect(trimmed_chatboxes.onChanged).toHaveBeenCalled();
expect(chatboxview.maximize).toHaveBeenCalled();
}
}, this));
waits(250);
runs($.proxy(function () {
expect(trimmedview.restore).toHaveBeenCalled();
expect(chatbox.maximize).toHaveBeenCalled();
expect(this.chatboxviews.trimChats).toHaveBeenCalled();
}, this));
}, converse));
it("is focused if its already open and you click on its corresponding roster item", $.proxy(function () {
@ -184,18 +184,17 @@
it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", function () {
var chatbox = utils.openChatBoxes(1)[0],
chatview = this.chatboxviews.get(chatbox.get('jid')),
trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
spyOn(chatview, 'maximize').andCallThrough();
trimmed_chatboxes = this.minimized_chats,
trimmedview;
spyOn(chatview, 'minimize').andCallThrough();
spyOn(converse, 'emit');
spyOn(trimmed_chatboxes, 'onChanged').andCallThrough();
// We need to rebind all events otherwise our spy won't be called
chatview.delegateEvents();
runs(function () {
chatview.$el.find('.toggle-chatbox-button').click();
});
waits(50);
waits(250);
runs(function () {
expect(chatview.minimize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxMinimized', jasmine.any(Object));
@ -203,14 +202,14 @@
expect(chatview.$el.is(':visible')).toBeFalsy();
expect(chatview.model.get('minimized')).toBeTruthy();
chatview.$el.find('.toggle-chatbox-button').click();
trimmedview = trimmed_chatboxes.get(chatview.model.get('id'));
spyOn(trimmedview, 'restore').andCallThrough();
trimmedview.delegateEvents();
trimmedview.$("a.restore-chat").click();
});
waits(50);
waits(250);
runs(function () {
expect(trimmed_chatboxes.onChanged).toHaveBeenCalled();
expect(chatview.maximize).toHaveBeenCalled();
expect(trimmedview.restore).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxMaximized', jasmine.any(Object));
expect(chatview.$el.find('.chat-body').is(':visible')).toBeTruthy();
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
@ -488,7 +487,7 @@
}, converse));
waits(50);
runs($.proxy(function () {
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
var trimmed_chatboxes = this.minimized_chats;
var trimmedview = trimmed_chatboxes.get(contact_jid);
var $count = trimmedview.$el.find('.chat-head-message-count');
expect(trimmedview.model.get('minimized')).toBeTruthy();
@ -507,7 +506,7 @@
}, converse));
waits(50);
runs($.proxy(function () {
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
var trimmed_chatboxes = this.minimized_chats;
var trimmedview = trimmed_chatboxes.get(contact_jid);
var $count = trimmedview.$el.find('.chat-head-message-count');
expect(trimmedview.model.get('minimized')).toBeTruthy();
@ -518,7 +517,7 @@
}, converse));
waits(50);
runs($.proxy(function () {
var trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
var trimmed_chatboxes = this.minimized_chats;
var trimmedview = trimmed_chatboxes.get(contact_jid);
var $count = trimmedview.$el.find('.chat-head-message-count');
expect(trimmedview.model.get('minimized')).toBeFalsy();

View File

@ -14,7 +14,7 @@
});
});
it("can be opened by clicking a DOM element with class 'toggle-online-users'", $.proxy(function () {
it("can be opened by clicking a DOM element with class 'toggle-controlbox'", $.proxy(function () {
runs(function () {
utils.closeControlBox();
});
@ -28,7 +28,7 @@
spyOn(converse, 'emit');
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
this.controlboxtoggle.delegateEvents();
$('.toggle-online-users').click();
$('.toggle-controlbox').click();
}.bind(converse));
waits(250);
runs(function () {