Commit 1bea7a1a authored by JC Brand's avatar JC Brand

Fix trimming/minimize tests broken after recent refactor

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