Refactor ChatRoom tests (move code to utils.js)

This commit is contained in:
JC Brand 2013-11-03 12:02:25 +02:00
parent 13babe4fae
commit d7d8948eba
3 changed files with 23 additions and 16 deletions

View File

@ -1830,7 +1830,7 @@
this.connect(null); this.connect(null);
this.model.messages.on('add', this.onMessageAdded, this); this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('destroy', function (model, response, options) { this.model.on('destroy', function (model, response, options) {
this.$el.hide('fast'); this.hide();
converse.connection.muc.leave( converse.connection.muc.leave(
this.model.get('jid'), this.model.get('jid'),
this.model.get('nick'), this.model.get('nick'),

View File

@ -10,20 +10,10 @@
return describe("ChatRooms", $.proxy(function (mock, utils) { return describe("ChatRooms", $.proxy(function (mock, utils) {
describe("A Chat Room", $.proxy(function () { describe("A Chat Room", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach(function () {
utils.closeAllChatBoxes(); utils.closeAllChatBoxes();
utils.openControlBox(); utils.createNewChatRoom('lounge', 'dummy');
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));
it("shows users currently present in the room", $.proxy(function () { it("shows users currently present in the room", $.proxy(function () {
var chatroomview = this.chatboxesview.views['lounge@muc.localhost'], var chatroomview = this.chatboxesview.views['lounge@muc.localhost'],

View File

@ -10,8 +10,8 @@
var utils = {}; var utils = {};
utils.closeAllChatBoxes = function () { utils.closeAllChatBoxes = function () {
var i, chatbox, num_chatboxes = converse.chatboxes.models.length; var i, chatbox;
for (i=num_chatboxes-1; i>-1; i--) { for (i=converse.chatboxes.models.length-1; i>-1; i--) {
chatbox = converse.chatboxes.models[i]; chatbox = converse.chatboxes.models[i];
converse.chatboxesview.views[chatbox.get('id')].closeChat(); converse.chatboxesview.views[chatbox.get('id')].closeChat();
} }
@ -83,6 +83,23 @@
converse.rosterview.rosteritemviews[jid].openChat(mock.event); 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 () { utils.createCurrentContacts = function () {
// Create current (as opposed to requesting or pending) contacts // Create current (as opposed to requesting or pending) contacts
// for the user's roster. // for the user's roster.