Commit d7d8948e authored by JC Brand's avatar JC Brand

Refactor ChatRoom tests (move code to utils.js)

parent 13babe4f
......@@ -1830,7 +1830,7 @@
this.connect(null);
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('destroy', function (model, response, options) {
this.$el.hide('fast');
this.hide();
converse.connection.muc.leave(
this.model.get('jid'),
this.model.get('nick'),
......
......@@ -10,20 +10,10 @@
return describe("ChatRooms", $.proxy(function (mock, utils) {
describe("A Chat Room", $.proxy(function () {
beforeEach($.proxy(function () {
beforeEach(function () {
utils.closeAllChatBoxes();
utils.openControlBox();
utils.openRoomsPanel();
var roomspanel = this.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $nick = roomspanel.$el.find('input.new-chatroom-nick');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('lounge');
$nick.val('dummy');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
$('.toggle-online-users').click();
}, converse));
utils.createNewChatRoom('lounge', 'dummy');
});
it("shows users currently present in the room", $.proxy(function () {
var chatroomview = this.chatboxesview.views['lounge@muc.localhost'],
......
......@@ -10,8 +10,8 @@
var utils = {};
utils.closeAllChatBoxes = function () {
var i, chatbox, num_chatboxes = converse.chatboxes.models.length;
for (i=num_chatboxes-1; i>-1; i--) {
var i, chatbox;
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i];
converse.chatboxesview.views[chatbox.get('id')].closeChat();
}
......@@ -83,6 +83,23 @@
converse.rosterview.rosteritemviews[jid].openChat(mock.event);
};
utils.createNewChatRoom = function (room, nick) {
var controlbox_was_visible = $("#controlbox").is(':visible');
utils.openControlBox();
utils.openRoomsPanel();
var roomspanel = converse.chatboxesview.views.controlbox.roomspanel;
var $input = roomspanel.$el.find('input.new-chatroom-name');
var $nick = roomspanel.$el.find('input.new-chatroom-nick');
var $server = roomspanel.$el.find('input.new-chatroom-server');
$input.val('lounge');
$nick.val('dummy');
$server.val('muc.localhost');
roomspanel.$el.find('form').submit();
if (!controlbox_was_visible) {
utils.closeControlBox();
}
};
utils.createCurrentContacts = function () {
// Create current (as opposed to requesting or pending) contacts
// for the user's roster.
......
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