Commit 11b59b31 authored by JC Brand's avatar JC Brand

Fix tests after all the refactoring...

parent b9cf7950
...@@ -356,7 +356,6 @@ span.spinner.hor_centered { ...@@ -356,7 +356,6 @@ span.spinner.hor_centered {
padding: 4px 8px; padding: 4px 8px;
margin-right: 5px; margin-right: 5px;
color: white; color: white;
display: none;
} }
#connecting-to-chat { #connecting-to-chat {
......
...@@ -605,7 +605,7 @@ ...@@ -605,7 +605,7 @@
window.sessionStorage[hex_sha1(jid+'priv_key')] = window.sessionStorage[hex_sha1(jid+'priv_key')] =
cipher.encrypt(CryptoJS.algo.AES, key.packPrivate(), pass).toString(); cipher.encrypt(CryptoJS.algo.AES, key.packPrivate(), pass).toString();
window.sessionStorage[hex_sha1(jid+'instance_tag')] = instance_tag; window.sessionStorage[hex_sha1(jid+'instance_tag')] = instance_tag;
window.sessionStorage[hex_sha1(jid+'pass_check')] = window.sessionStorage[hex_sha1(jid+'pass_check')] =
cipher.encrypt(CryptoJS.algo.AES, 'match', pass).toString(); cipher.encrypt(CryptoJS.algo.AES, 'match', pass).toString();
} }
} }
...@@ -866,7 +866,7 @@ ...@@ -866,7 +866,7 @@
this.updateVCard(); this.updateVCard();
this.$el.appendTo(converse.chatboxesview.$el); this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true}); this.render().show().focus().model.messages.fetch({add: true});
if (this.model.get('status')) { if (this.model.get('status')) {
this.showStatusMessage(this.model.get('status')); this.showStatusMessage(this.model.get('status'));
...@@ -897,6 +897,7 @@ ...@@ -897,6 +897,7 @@
) )
); );
this.renderToolbar().renderAvatar(); this.renderToolbar().renderAvatar();
converse.emit('onChatBoxOpened', this);
return this; return this;
}, },
...@@ -1349,7 +1350,7 @@ ...@@ -1349,7 +1350,7 @@
FINISHED: FINISHED, FINISHED: FINISHED,
UNENCRYPTED: UNENCRYPTED, UNENCRYPTED: UNENCRYPTED,
UNVERIFIED: UNVERIFIED, UNVERIFIED: UNVERIFIED,
VERIFIED: VERIFIED, VERIFIED: VERIFIED,
allow_otr: converse.allow_otr && !this.is_chatroom, allow_otr: converse.allow_otr && !this.is_chatroom,
label_end_encrypted_conversation: __('End encrypted conversation'), label_end_encrypted_conversation: __('End encrypted conversation'),
label_refresh_encrypted_conversation: __('Refresh encrypted conversation'), label_refresh_encrypted_conversation: __('Refresh encrypted conversation'),
...@@ -1391,6 +1392,7 @@ ...@@ -1391,6 +1392,7 @@
focus: function () { focus: function () {
this.$el.find('.chat-textarea').focus(); this.$el.find('.chat-textarea').focus();
converse.emit('onChatBoxFocused', this);
return this; return this;
}, },
...@@ -1404,14 +1406,13 @@ ...@@ -1404,14 +1406,13 @@
show: function (callback) { show: function (callback) {
if (this.$el.is(':visible') && this.$el.css('opacity') == "1") { if (this.$el.is(':visible') && this.$el.css('opacity') == "1") {
converse.emit('onChatBoxFocused', this); return this;
return this.focus();
} }
if (converse.animate) { if (converse.animate) {
this.$el.css({'opacity': 0, 'display': 'inline'}).animate({opacity: '1'}, 200, null, callback); this.$el.show(callback);
} else { } else {
this.$el.css({'opacity': 1, 'display': 'inline'}); this.$el.show();
callback(); if (typeof callback === 'function') { callback(); }
} }
if (converse.connection) { if (converse.connection) {
// Without a connection, we haven't yet initialized // Without a connection, we haven't yet initialized
...@@ -1779,6 +1780,7 @@ ...@@ -1779,6 +1780,7 @@
hide: function (callback) { hide: function (callback) {
this.$el.hide('fast', function () { this.$el.hide('fast', function () {
converse.emit('onChatBoxClosed', this);
converse.controlboxtoggle.show(function () { converse.controlboxtoggle.show(function () {
if (typeof callback === "function") { if (typeof callback === "function") {
callback(); callback();
...@@ -1872,6 +1874,28 @@ ...@@ -1872,6 +1874,28 @@
}, },
is_chatroom: true, is_chatroom: true,
initialize: function () {
this.connect(null);
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('destroy', function (model, response, options) {
this.hide();
converse.connection.muc.leave(
this.model.get('jid'),
this.model.get('nick'),
$.proxy(this.onLeave, this),
undefined);
},
this);
this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true});
},
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatroom(this.model.toJSON()));
return this;
},
sendChatRoomMessage: function (body) { sendChatRoomMessage: function (body) {
var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false], var match = body.replace(/^\s*/, "").match(/^\/(.*?)(?: (.*))?$/) || [false],
$chat_content; $chat_content;
...@@ -1915,12 +1939,6 @@ ...@@ -1915,12 +1939,6 @@
} }
}, },
render: function () {
this.$el.attr('id', this.model.get('box_id'))
.html(converse.templates.chatroom(this.model.toJSON()));
return this;
},
renderChatArea: function () { renderChatArea: function () {
if (!this.$el.find('.chat-area').length) { if (!this.$el.find('.chat-area').length) {
this.$el.find('.chat-body').empty().append( this.$el.find('.chat-body').empty().append(
...@@ -1951,22 +1969,6 @@ ...@@ -1951,22 +1969,6 @@
} }
}, },
initialize: function () {
this.connect(null);
this.model.messages.on('add', this.onMessageAdded, this);
this.model.on('destroy', function (model, response, options) {
this.hide();
converse.connection.muc.leave(
this.model.get('jid'),
this.model.get('nick'),
$.proxy(this.onLeave, this),
undefined);
},
this);
this.$el.appendTo(converse.chatboxesview.$el);
this.render().show().model.messages.fetch({add: true});
},
onLeave: function () { onLeave: function () {
this.model.set('connected', false); this.model.set('connected', false);
}, },
...@@ -2935,11 +2937,11 @@ ...@@ -2935,11 +2937,11 @@
'label_contacts': __('My contacts') 'label_contacts': __('My contacts')
}); });
if (converse.allow_contact_requests) { if (converse.allow_contact_requests) {
roster_markup = roster_markup =
converse.templates.requesting_contacts({ converse.templates.requesting_contacts({
'label_contact_requests': __('Contact requests') 'label_contact_requests': __('Contact requests')
}) + }) +
roster_markup + roster_markup +
converse.templates.pending_contacts({ converse.templates.pending_contacts({
'label_pending_contacts': __('Pending contacts') 'label_pending_contacts': __('Pending contacts')
}); });
...@@ -3391,11 +3393,15 @@ ...@@ -3391,11 +3393,15 @@
}, },
render: function () { render: function () {
$('#conversejs').append(this.$el.html( var toggle = this.$el.html(
converse.templates.controlbox_toggle({ converse.templates.controlbox_toggle({
'label_toggle': __('Toggle chat') 'label_toggle': __('Toggle chat')
}) })
)); );
if (converse.show_controlbox_by_default) {
toggle.hide(); // It's either or
}
$('#conversejs').append(toggle);
return this; return this;
}, },
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<meta name="description" content="Converse.js: Open Source Browser-Based Instant Messaging" /> <meta name="description" content="Converse.js: Open Source Browser-Based Instant Messaging" />
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css"> <link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
<link rel="stylesheet" type="text/css" media="screen" href="converse.css"> <link rel="stylesheet" type="text/css" media="screen" href="converse.css">
<!--<script data-main="main" src="components/requirejs/require.js"></script>--> <script data-main="main" src="components/requirejs/require.js"></script>
<script src="builds/converse.min.js"></script> <!-- <script src="builds/converse.min.js"></script> -->
<title>Converse.js</title> <title>Converse.js</title>
</head> </head>
......
...@@ -10,17 +10,23 @@ ...@@ -10,17 +10,23 @@
return describe("Chatboxes", $.proxy(function(mock, utils) { return describe("Chatboxes", $.proxy(function(mock, utils) {
describe("A Chatbox", $.proxy(function () { describe("A Chatbox", $.proxy(function () {
beforeEach(function () { beforeEach(function () {
utils.closeAllChatBoxes(); runs(function () {
utils.removeControlBox(); utils.closeAllChatBoxes();
converse.roster.localStorage._clear(); utils.removeControlBox();
utils.initConverse(); });
utils.createCurrentContacts(); waits(250);
utils.openControlBox(); runs(function () {
utils.openContactsPanel(); converse.roster.localStorage._clear();
}); utils.initConverse();
utils.createCurrentContacts();
afterEach(function () { utils.openControlBox();
utils.closeAllChatBoxes(); });
waits(250);
runs(function () {
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 () {
...@@ -44,63 +50,77 @@ ...@@ -44,63 +50,77 @@
it("can be saved to, and retrieved from, localStorage", $.proxy(function () { it("can be saved to, and retrieved from, localStorage", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
utils.closeControlBox(); runs(function () {
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object)); utils.closeControlBox();
});
// First, we open 6 more chatboxes (controlbox is already open) waits(250);
utils.openChatBoxes(6); runs(function () {
// We instantiate a new ChatBoxes collection, which by default expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
// will be empty. utils.openChatBoxes(6);
var newchatboxes = new this.ChatBoxes(); // We instantiate a new ChatBoxes collection, which by default
expect(newchatboxes.length).toEqual(0); // will be empty.
// The chatboxes will then be fetched from localStorage inside the var newchatboxes = new this.ChatBoxes();
// onConnected method expect(newchatboxes.length).toEqual(0);
newchatboxes.onConnected(); // The chatboxes will then be fetched from localStorage inside the
expect(newchatboxes.length).toEqual(6); // onConnected method
// Check that the chatboxes items retrieved from localStorage newchatboxes.onConnected();
// have the same attributes values as the original ones. expect(newchatboxes.length).toEqual(6);
attrs = ['id', 'box_id', 'visible']; // Check that the chatboxes items retrieved from localStorage
for (i=0; i<attrs.length; i++) { // have the same attributes values as the original ones.
new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]); attrs = ['id', 'box_id', 'visible'];
old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]); for (i=0; i<attrs.length; i++) {
expect(_.isEqual(new_attrs, old_attrs)).toEqual(true); new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
} old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
this.rosterview.render(); expect(_.isEqual(new_attrs, old_attrs)).toEqual(true);
}
this.rosterview.render();
}.bind(converse));
}, converse)); }, converse));
it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () { it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var chatbox, view, $el, var view = this.chatboxesview.views.controlbox; // The controlbox is currently open
num_open_chats = this.chatboxes.length; spyOn(view, 'closeChat').andCallThrough();
for (i=0; i<num_open_chats; i++) { view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
chatbox = this.chatboxes.models[0];
view = this.chatboxesview.views[chatbox.get('id')]; runs(function () {
spyOn(view, 'closeChat').andCallThrough();
view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
view.$el.find('.close-chatbox-button').click(); view.$el.find('.close-chatbox-button').click();
});
waits(250);
runs(function () {
expect(view.closeChat).toHaveBeenCalled(); expect(view.closeChat).toHaveBeenCalled();
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object)); expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
} });
// TODO: Open a normal chatbox and close it again...
}, converse)); }, converse));
it("will be removed from localStorage when closed", $.proxy(function () { it("will be removed from localStorage when closed", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
this.chatboxes.localStorage._clear(); this.chatboxes.localStorage._clear();
utils.closeControlBox(); runs(function () {
expect(converse.chatboxes.length).toEqual(0); utils.closeControlBox();
utils.openChatBoxes(6); });
expect(converse.chatboxes.length).toEqual(6); waits(250);
expect(converse.emit).toHaveBeenCalledWith('onChatBoxOpened', jasmine.any(Object)); runs(function () {
utils.closeAllChatBoxes(); expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
expect(converse.chatboxes.length).toEqual(0); expect(converse.chatboxes.length).toEqual(0);
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object)); utils.openChatBoxes(6);
var newchatboxes = new this.ChatBoxes(); expect(converse.chatboxes.length).toEqual(6);
expect(newchatboxes.length).toEqual(0); expect(converse.emit).toHaveBeenCalledWith('onChatBoxOpened', jasmine.any(Object));
// onConnected will fetch chatboxes in localStorage, but utils.closeAllChatBoxes();
// because there aren't any open chatboxes, there won't be any });
// in localStorage either. waits(250);
newchatboxes.onConnected(); runs(function () {
expect(newchatboxes.length).toEqual(0); expect(converse.chatboxes.length).toEqual(0);
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
var newchatboxes = new this.ChatBoxes();
expect(newchatboxes.length).toEqual(0);
// onConnected will fetch chatboxes in localStorage, but
// because there aren't any open chatboxes, there won't be any
// in localStorage either.
newchatboxes.onConnected();
expect(newchatboxes.length).toEqual(0);
}.bind(converse));
}, converse)); }, converse));
describe("A chat toolbar", $.proxy(function () { describe("A chat toolbar", $.proxy(function () {
...@@ -341,19 +361,23 @@ ...@@ -341,19 +361,23 @@
it("can be sent from a chatbox, and will appear inside it", $.proxy(function () { it("can be sent from a chatbox, and will appear inside it", $.proxy(function () {
spyOn(converse, 'emit'); spyOn(converse, 'emit');
var contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost'; var contact_jid = mock.cur_names[0].replace(' ','.').toLowerCase() + '@localhost';
utils.openChatBoxFor(contact_jid); runs(function () {
expect(converse.emit).toHaveBeenCalledWith('onChatBoxOpened', jasmine.any(Object)); utils.openChatBoxFor(contact_jid);
var view = this.chatboxesview.views[contact_jid]; });
var message = 'This message is sent from this chatbox'; waits(250);
spyOn(view, 'sendMessage').andCallThrough(); runs(function () {
view.$el.find('.chat-textarea').text(message); expect(converse.emit).toHaveBeenCalledWith('onChatBoxFocused', jasmine.any(Object));
view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13})); var view = this.chatboxesview.views[contact_jid];
expect(view.sendMessage).toHaveBeenCalled(); var message = 'This message is sent from this chatbox';
expect(view.model.messages.length, 2); spyOn(view, 'sendMessage').andCallThrough();
expect(converse.emit.callCount).toEqual(2); view.$el.find('.chat-textarea').text(message);
expect(converse.emit.mostRecentCall.args, ['onMessageSend', message]); view.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
var txt = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text(); expect(view.sendMessage).toHaveBeenCalled();
expect(txt).toEqual(message); expect(view.model.messages.length, 2);
expect(converse.emit.mostRecentCall.args, ['onMessageSend', message]);
var txt = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-message-content').text();
expect(txt).toEqual(message);
}.bind(converse));
}, converse)); }, converse));
it("are sanitized to prevent Javascript injection attacks", $.proxy(function () { it("are sanitized to prevent Javascript injection attacks", $.proxy(function () {
......
...@@ -10,12 +10,35 @@ ...@@ -10,12 +10,35 @@
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(function () { beforeEach(function () {
utils.closeAllChatBoxes(); runs(function () {
utils.createNewChatRoom('lounge', 'dummy'); utils.closeAllChatBoxes();
}); });
waits(250);
afterEach(function () { runs(function () {
utils.closeAllChatBoxes(); utils.openControlBox();
});
waits(250);
runs(function () {
utils.openRoomsPanel();
});
waits(300);
runs(function () {
// Open a new chatroom
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();
});
waits(250);
runs(function () {
utils.closeControlBox();
});
waits(250);
runs(function () {});
}); });
it("shows users currently present in the room", $.proxy(function () { it("shows users currently present in the room", $.proxy(function () {
...@@ -115,10 +138,15 @@ ...@@ -115,10 +138,15 @@
spyOn(converse, 'emit'); spyOn(converse, 'emit');
spyOn(converse.connection.muc, 'leave'); spyOn(converse.connection.muc, 'leave');
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
view.$el.find('.close-chatbox-button').click(); runs(function () {
expect(view.closeChat).toHaveBeenCalled(); view.$el.find('.close-chatbox-button').click();
expect(converse.connection.muc.leave).toHaveBeenCalled(); });
expect(converse.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object)); waits(250);
runs(function () {
expect(view.closeChat).toHaveBeenCalled();
expect(this.connection.muc.leave).toHaveBeenCalled();
expect(this.emit).toHaveBeenCalledWith('onChatBoxClosed', jasmine.any(Object));
}.bind(converse));
}, converse)); }, converse));
}, converse)); }, converse));
......
...@@ -8,27 +8,32 @@ ...@@ -8,27 +8,32 @@
); );
} (this, function (mock, utils) { } (this, function (mock, utils) {
describe("The Control Box", $.proxy(function (mock, utils) { describe("The Control Box", $.proxy(function (mock, utils) {
window.localStorage.clear();
it("is not shown by default", $.proxy(function () { it("can be opened by clicking a DOM element with class 'toggle-online-users'", $.proxy(function () {
expect(this.rosterview.$el.is(':visible')).toEqual(false); runs(function () {
utils.closeControlBox();
});
waits(250);
runs(function () {
// This spec will only pass if the controlbox is not currently
// open yet.
expect($("div#controlbox").is(':visible')).toBe(false);
spyOn(this.controlboxtoggle, 'onClick').andCallThrough();
spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
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();
}.bind(converse));
waits(250);
runs(function () {
expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
expect(this.emit).toHaveBeenCalledWith('onControlBoxOpened', jasmine.any(Object));
expect($("div#controlbox").is(':visible')).toBe(true);
}.bind(converse));
}, converse)); }, converse));
var open_controlbox = $.proxy(function () {
// This spec will only pass if the controlbox is not currently
// open yet.
expect($("div#controlbox").is(':visible')).toBe(false);
spyOn(this.controlboxtoggle, 'onClick').andCallThrough();
spyOn(this.controlboxtoggle, 'showControlBox').andCallThrough();
// Redelegate so that the spies are now registered as the event handlers (specifically for 'onClick')
this.controlboxtoggle.delegateEvents();
$('.toggle-online-users').click();
expect(this.controlboxtoggle.onClick).toHaveBeenCalled();
expect(this.controlboxtoggle.showControlBox).toHaveBeenCalled();
expect($("div#controlbox").is(':visible')).toBe(true);
}, converse);
it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox);
describe("The Status Widget", $.proxy(function () { describe("The Status Widget", $.proxy(function () {
it("shows the user's chat status, which is online by default", $.proxy(function () { it("shows the user's chat status, which is online by default", $.proxy(function () {
var view = this.xmppstatusview; var view = this.xmppstatusview;
...@@ -88,13 +93,20 @@ ...@@ -88,13 +93,20 @@
}); });
}, converse)); }, converse));
}, converse)); }, converse));
}, converse, utils, mock)); }, converse, mock, utils));
describe("The Contacts Roster", $.proxy(function (utils, mock) { describe("The Contacts Roster", $.proxy(function (mock, utils) {
describe("Pending Contacts", $.proxy(function () { describe("Pending Contacts", $.proxy(function () {
beforeEach(function () { beforeEach(function () {
utils.openControlBox(); runs(function () {
utils.openContactsPanel(); utils.openControlBox();
});
waits(250);
runs(function () {
utils.openContactsPanel();
});
waits(250);
runs(function () {});
}); });
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
...@@ -132,7 +144,7 @@ ...@@ -132,7 +144,7 @@
runs($.proxy(function () { runs($.proxy(function () {
view.$el.find('.remove-xmpp-contact').click(); view.$el.find('.remove-xmpp-contact').click();
}, converse)); }, converse));
waits(500); waits(250);
runs($.proxy(function () { runs($.proxy(function () {
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
expect(this.connection.roster.remove).toHaveBeenCalled(); expect(this.connection.roster.remove).toHaveBeenCalled();
...@@ -177,8 +189,15 @@ ...@@ -177,8 +189,15 @@
describe("Existing Contacts", $.proxy(function () { describe("Existing Contacts", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
utils.openControlBox(); runs(function () {
utils.openContactsPanel(); utils.openControlBox();
});
waits(250);
runs(function () {
utils.openContactsPanel();
});
waits(250);
runs(function () {});
}, converse)); }, converse));
it("do not have a heading if there aren't any", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () {
...@@ -437,9 +456,9 @@ ...@@ -437,9 +456,9 @@
} }
}, converse)); }, converse));
}, converse)); }, converse));
}, converse, utils, mock)); }, converse, mock, utils));
describe("The 'Add Contact' widget", $.proxy(function (utils, mock) { describe("The 'Add Contact' widget", $.proxy(function (mock, utils) {
it("opens up an add form when you click on it", $.proxy(function () { it("opens up an add form when you click on it", $.proxy(function () {
var panel = this.chatboxesview.views.controlbox.contactspanel; var panel = this.chatboxesview.views.controlbox.contactspanel;
spyOn(panel, 'toggleContactForm').andCallThrough(); spyOn(panel, 'toggleContactForm').andCallThrough();
...@@ -450,12 +469,19 @@ ...@@ -450,12 +469,19 @@
panel.$el.find('a.toggle-xmpp-contact-form').click(); panel.$el.find('a.toggle-xmpp-contact-form').click();
}, converse)); }, converse));
}, converse, utils, mock)); }, converse, mock, utils));
describe("The Controlbox Tabs", $.proxy(function () { describe("The Controlbox Tabs", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
utils.closeAllChatBoxes(); runs(function () {
utils.openControlBox(); utils.closeAllChatBoxes();
});
waits(250);
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
}, converse)); }, converse));
it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () { it("contains two tabs, 'Contacts' and 'ChatRooms'", $.proxy(function () {
...@@ -468,10 +494,17 @@ ...@@ -468,10 +494,17 @@
expect($panels.children().last().is(':visible')).toBe(false); expect($panels.children().last().is(':visible')).toBe(false);
}, converse)); }, converse));
describe("The Chatrooms Panel", $.proxy(function () { describe("chatrooms panel", $.proxy(function () {
beforeEach($.proxy(function () { beforeEach($.proxy(function () {
utils.closeAllChatBoxes(); runs(function () {
utils.openControlBox(); utils.closeAllChatBoxes();
});
waits(250);
runs(function () {
utils.openControlBox();
});
waits(250);
runs(function () {});
}, converse)); }, converse));
it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () { it("is opened by clicking the 'Chatrooms' tab", $.proxy(function () {
......
...@@ -42,20 +42,26 @@ ...@@ -42,20 +42,26 @@
}; };
utils.openControlBox = function () { utils.openControlBox = function () {
var toggle = $(".toggle-online-users");
if (!$("#controlbox").is(':visible')) { if (!$("#controlbox").is(':visible')) {
$('.toggle-online-users').click(); if (!toggle.is(':visible')) {
toggle.show(toggle.click);
} else {
toggle.click();
}
} }
return this; return this;
}; };
utils.closeControlBox = function () { utils.closeControlBox = function () {
if ($("#controlbox").is(':visible')) { if ($("#controlbox").is(':visible')) {
$('.toggle-online-users').click(); $("#controlbox").find(".close-chatbox-button").click();
} }
return this; return this;
}; };
utils.removeControlBox = function () { utils.removeControlBox = function () {
converse.controlboxtoggle.show();
$('#controlbox').remove(); $('#controlbox').remove();
}; };
...@@ -89,23 +95,6 @@ ...@@ -89,23 +95,6 @@
view.model.messages.reset().localStorage._clear(); view.model.messages.reset().localStorage._clear();
}; };
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.
......
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