Commit c6a32b84 authored by JC Brand's avatar JC Brand

Fix chatroom tests

parent ef9fd961
...@@ -1314,6 +1314,7 @@ ...@@ -1314,6 +1314,7 @@
} else { } else {
this.model.trigger('hide'); this.model.trigger('hide');
} }
converse.emit('onChatBoxClosed', this);
return this; return this;
}, },
...@@ -1323,6 +1324,7 @@ ...@@ -1323,6 +1324,7 @@
this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el).show(); this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el).show();
this.focus(); this.focus();
converse.refreshWebkit(); converse.refreshWebkit();
converse.emit('onChatBoxMaximized', this);
this.model.trigger('maximized', this.model); this.model.trigger('maximized', this.model);
}, },
...@@ -1334,7 +1336,7 @@ ...@@ -1334,7 +1336,7 @@
'time_minimized': moment().format() 'time_minimized': moment().format()
}); });
this.$el.hide('fast', converse.refreshwebkit); this.$el.hide('fast', converse.refreshwebkit);
converse.emit('onChatBoxToggled', this); converse.emit('onChatBoxMinimized', this);
}, },
updateVCard: function () { updateVCard: function () {
......
...@@ -181,12 +181,12 @@ ...@@ -181,12 +181,12 @@
}); });
}, converse)); }, converse));
it("can be toggled 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.chatboxviews.trimmed_chatboxes_view;
spyOn(chatview, 'maximize').andCallThrough(); spyOn(chatview, 'maximize').andCallThrough();
spyOn(chatview, 'toggle').andCallThrough(); spyOn(chatview, 'minimize').andCallThrough();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(trimmed_chatboxes, 'onChanged').andCallThrough(); 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
...@@ -197,8 +197,8 @@ ...@@ -197,8 +197,8 @@
}); });
waits(50); waits(50);
runs(function () { runs(function () {
expect(chatview.toggle).toHaveBeenCalled(); expect(chatview.minimize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxMinimized', jasmine.any(Object));
expect(converse.emit.callCount, 2); expect(converse.emit.callCount, 2);
expect(chatview.$el.is(':visible')).toBeFalsy(); expect(chatview.$el.is(':visible')).toBeFalsy();
expect(chatview.model.get('minimized')).toBeTruthy(); expect(chatview.model.get('minimized')).toBeTruthy();
...@@ -211,6 +211,7 @@ ...@@ -211,6 +211,7 @@
runs(function () { runs(function () {
expect(trimmed_chatboxes.onChanged).toHaveBeenCalled(); expect(trimmed_chatboxes.onChanged).toHaveBeenCalled();
expect(chatview.maximize).toHaveBeenCalled(); expect(chatview.maximize).toHaveBeenCalled();
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();
expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-plus')).toBeFalsy(); expect(chatview.$el.find('.toggle-chatbox-button').hasClass('icon-plus')).toBeFalsy();
......
...@@ -139,33 +139,34 @@ ...@@ -139,33 +139,34 @@
this.rosterview.render(); this.rosterview.render();
}, converse)); }, converse));
it("can be toggled 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 view = this.chatboxviews.get('lounge@muc.localhost'), var view = this.chatboxviews.get('lounge@muc.localhost'),
chatroom = view.model, $el; trimmed_chatboxes = this.chatboxviews.trimmed_chatboxes_view;
spyOn(view, 'toggle').andCallThrough();
spyOn(view, 'minimize').andCallThrough();
spyOn(view, 'maximize').andCallThrough();
spyOn(converse, 'emit'); spyOn(converse, 'emit');
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
runs(function () { runs(function () {
view.$el.find('.toggle-chatbox-button').click(); view.$el.find('.toggle-chatbox-button').click();
}); });
waits(250); waits(50);
runs(function () { runs(function () {
expect(view.toggle).toHaveBeenCalled(); expect(view.minimize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxMinimized', jasmine.any(Object));
expect(converse.emit.callCount, 2); expect(converse.emit.callCount, 2);
expect(view.$el.find('.chat-body').is(':visible')).toBeFalsy(); expect(view.$el.is(':visible')).toBeFalsy();
expect(view.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeFalsy();
expect(view.$el.find('.toggle-chatbox-button').hasClass('icon-plus')).toBeTruthy();
expect(view.model.get('minimized')).toBeTruthy(); expect(view.model.get('minimized')).toBeTruthy();
view.$el.find('.toggle-chatbox-button').click(); expect(view.minimize).toHaveBeenCalled();
trimmedview = trimmed_chatboxes.get(view.model.get('id'));
trimmedview.$("a.restore-chat").click();
}); });
waits(250); waits(50);
runs(function () { runs(function () {
expect(view.toggle).toHaveBeenCalled(); expect(view.maximize).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxToggled', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxMaximized', jasmine.any(Object));
expect(view.$el.find('.chat-body').is(':visible')).toBeTruthy(); expect(view.$el.is(':visible')).toBeTruthy();
expect(view.$el.find('.toggle-chatbox-button').hasClass('icon-minus')).toBeTruthy();
expect(view.$el.find('.toggle-chatbox-button').hasClass('icon-plus')).toBeFalsy();
expect(view.model.get('minimized')).toBeFalsy(); expect(view.model.get('minimized')).toBeFalsy();
expect(converse.emit.callCount, 3); expect(converse.emit.callCount, 3);
}); });
...@@ -181,7 +182,7 @@ ...@@ -181,7 +182,7 @@
runs(function () { runs(function () {
view.$el.find('.close-chatbox-button').click(); view.$el.find('.close-chatbox-button').click();
}); });
waits(250); waits(50);
runs(function () { runs(function () {
expect(view.close).toHaveBeenCalled(); expect(view.close).toHaveBeenCalled();
expect(this.connection.muc.leave).toHaveBeenCalled(); expect(this.connection.muc.leave).toHaveBeenCalled();
......
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