Browse Source

All tests suites now updated and isolated.

JC Brand 8 years ago
parent
commit
a2f4acdcee
22 changed files with 1292 additions and 1205 deletions
  1. 38 31
      spec/bookmarks.js
  2. 344 190
      spec/chatbox.js
  3. 136 144
      spec/chatroom.js
  4. 297 308
      spec/controlbox.js
  5. 1 0
      spec/converse.js
  6. 12 7
      spec/disco.js
  7. 11 20
      spec/eventemitter.js
  8. 11 9
      spec/headline.js
  9. 47 39
      spec/mam.js
  10. 72 70
      spec/minchats.js
  11. 28 30
      spec/notification.js
  12. 25 21
      spec/otr.js
  13. 18 15
      spec/ping.js
  14. 9 19
      spec/profiling.js
  15. 1 0
      spec/protocol.js
  16. 198 260
      spec/register.js
  17. 16 21
      spec/xmppstatus.js
  18. 2 0
      src/converse-mam.js
  19. 8 0
      tests.html
  20. 1 5
      tests/main.js
  21. 4 5
      tests/mock.js
  22. 13 11
      tests/utils.js

+ 38 - 31
spec/bookmarks.js

@@ -1,4 +1,3 @@
-/*global converse */
 (function (root, factory) {
     define([
         "jquery",
@@ -14,7 +13,12 @@
 
     describe("A chat room", function () {
 
-        it("can be bookmarked", function () {
+        afterEach(function () {
+            converse_api.user.logout();
+            test_utils.clearBrowserStorage();
+        });
+
+        it("can be bookmarked", mock.initConverse(function (converse) {
             var sent_stanza, IQ_id;
             var sendIQ = converse.connection.sendIQ;
             spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -23,7 +27,7 @@
             });
             spyOn(converse.connection, 'getUniqueId').andCallThrough();
 
-            test_utils.openChatRoom('theplay', 'conference.shakespeare.lit', 'JC');
+            test_utils.openChatRoom(converse, 'theplay', 'conference.shakespeare.lit', 'JC');
             var jid = 'theplay@conference.shakespeare.lit';
             var view = converse.chatboxviews.get(jid);
             spyOn(view, 'renderBookmarkForm').andCallThrough();
@@ -121,9 +125,9 @@
             converse.connection._dataRecv(test_utils.createRequest(stanza));
             // We ignore this IQ stanza... (unless it's an error stanza), so
             // nothing to test for here.
-        });
+        }));
 
-        it("will be automatically opened if 'autojoin' is set on the bookmark", function () {
+        it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(function (converse) {
             var jid = 'lounge@localhost';
             converse.bookmarks.create({
                 'jid': jid,
@@ -141,17 +145,18 @@
                 'nick': ' Othello'
             });
             expect(_.isUndefined(converse.chatboxviews.get(jid))).toBeFalsy();
-        });
+        }));
 
         describe("when bookmarked", function () {
-            beforeEach(function () {
-                test_utils.closeAllChatBoxes();
-                converse.bookmarks.reset();
+
+            afterEach(function () {
+                converse_api.user.logout();
+                test_utils.clearBrowserStorage();
             });
 
-            it("displays that it's bookmarked through its bookmark icon", function () {
+            it("displays that it's bookmarked through its bookmark icon", mock.initConverse(function (converse) {
                 runs(function () {
-                    test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 });
                 waits(100);
                 runs(function () {
@@ -163,9 +168,9 @@
                     view.model.set('bookmarked', false);
                     expect($bookmark_icon.hasClass('button-on')).toBeFalsy();
                 });
-            });
+            }));
 
-            it("can be unbookmarked", function () {
+            it("can be unbookmarked", mock.initConverse(function (converse) {
                 var view, sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -175,7 +180,7 @@
                 spyOn(converse.connection, 'getUniqueId').andCallThrough();
 
                 runs(function () {
-                    test_utils.openChatRoom('theplay', 'conference.shakespeare.lit', 'JC');
+                    test_utils.openChatRoom(converse, 'theplay', 'conference.shakespeare.lit', 'JC');
                 });
                 waits(100);
                 runs(function () {
@@ -229,15 +234,16 @@
                         "</iq>"
                     );
                 });
-            });
+            }));
         });
 
         describe("and when autojoin is set", function () {
-            beforeEach(function () {
-                converse.bookmarks.reset();
+            afterEach(function () {
+                converse_api.user.logout();
+                test_utils.clearBrowserStorage();
             });
 
-            it("will be be opened and joined automatically upon login", function () {
+            it("will be be opened and joined automatically upon login", mock.initConverse(function (converse) {
                 spyOn(converse_api.rooms, 'open');
                 var jid = 'theplay@conference.shakespeare.lit';
                 var model = converse.bookmarks.create({
@@ -256,17 +262,18 @@
                     'nick': ''
                 });
                 expect(converse_api.rooms.open).toHaveBeenCalled();
-            });
+            }));
         });
     });
 
     describe("Bookmarks", function () {
 
-        beforeEach(function () {
-            window.sessionStorage.clear();
+        afterEach(function () {
+            converse_api.user.logout();
+            test_utils.clearBrowserStorage();
         });
 
-        it("can be pushed from the XMPP server", function () {
+        it("can be pushed from the XMPP server", mock.initConverse(function (converse) {
             // TODO
             /* The stored data is automatically pushed to all of the user's
              * connected resources.
@@ -311,9 +318,9 @@
              * </event>
              * </message>
              */
-        });
+        }));
 
-        it("can be retrieved from the XMPP server", function () {
+        it("can be retrieved from the XMPP server", mock.initConverse(function (converse) {
             var sent_stanza, IQ_id,
                 sendIQ = converse.connection.sendIQ;
             spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -380,21 +387,21 @@
             expect(converse.bookmarks.models.length).toBe(2);
             expect(converse.bookmarks.findWhere({'jid': 'theplay@conference.shakespeare.lit'}).get('autojoin')).toBe(true);
             expect(converse.bookmarks.findWhere({'jid': 'another@conference.shakespeare.lit'}).get('autojoin')).toBe(false);
-        });
+        }));
 
         describe("The rooms panel", function () {
-            beforeEach(function () {
-                test_utils.openRoomsPanel();
-                converse.bookmarks.reset();
-                converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
+            afterEach(function () {
+                converse_api.user.logout();
+                test_utils.clearBrowserStorage();
             });
 
-            it("shows a list of bookmarks", function () {
+            it("shows a list of bookmarks", mock.initConverse(function (converse) {
                 var IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
                     IQ_id = sendIQ.bind(this)(iq, callback, errback);
                 });
+                converse.chatboxviews.get('controlbox').$('#chatrooms dl.bookmarks').html('');
                 converse.emit('chatBoxesFetched');
                 var stanza = $iq({'to': converse.connection.jid, 'type':'result', 'id':IQ_id})
                     .c('pubsub', {'xmlns': Strophe.NS.PUBSUB})
@@ -418,7 +425,7 @@
                                     }).c('nick').t('JC').up().up();
                 converse.connection._dataRecv(test_utils.createRequest(stanza));
                 expect($('#chatrooms dl.bookmarks dd').length).toBe(3);
-            });
+            }));
         });
     });
 }));

File diff suppressed because it is too large
+ 344 - 190
spec/chatbox.js


+ 136 - 144
spec/chatroom.js

@@ -1,42 +1,27 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "underscore",
-        "mock",
-        "test_utils",
-        "utils"
-        ], function ($, _, mock, test_utils, utils) {
-            return factory($, _, mock, test_utils, utils);
-        }
-    );
-} (this, function ($, _, mock, test_utils, utils) {
+    define(["mock", "test_utils", "utils" ], factory);
+} (this, function (mock, test_utils, utils) {
+    var _ = converse_api.env._;
+    var $ = converse_api.env.jQuery;
     var $pres = converse_api.env.$pres;
     var $iq = converse_api.env.$iq;
     var $msg = converse_api.env.$msg;
     var Strophe = converse_api.env.Strophe;
 
-    return describe("ChatRooms", function (mock, test_utils) {
-        beforeEach(function () {
-            runs(function () {
-                test_utils.closeAllChatBoxes();
-                test_utils.clearBrowserStorage();
-            });
-        });
-
+    return describe("ChatRooms", function () {
         describe("The \"rooms\" API", function () {
-            beforeEach(function () {
-                test_utils.closeAllChatBoxes();
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
                 test_utils.clearBrowserStorage();
-                converse.rosterview.model.reset();
-                test_utils.createContacts('current');
             });
 
-            it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments", function () {
+            it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments", mock.initConverse(function (converse) {
+                test_utils.createContacts(converse, 'current');
                 runs(function () {
-                    test_utils.openChatRoom('lounge', 'localhost', 'dummy');
-                    test_utils.openChatRoom('leisure', 'localhost', 'dummy');
-                    test_utils.openChatRoom('news', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'leisure', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'news', 'localhost', 'dummy');
                     expect(converse.chatboxviews.get('lounge@localhost').$el.is(':visible')).toBeTruthy();
                     expect(converse.chatboxviews.get('leisure@localhost').$el.is(':visible')).toBeTruthy();
                     expect(converse.chatboxviews.get('news@localhost').$el.is(':visible')).toBeTruthy();
@@ -52,8 +37,8 @@
                     expect(converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
                     expect(converse.chatboxviews.get('news@localhost')).toBeUndefined();
 
-                    test_utils.openChatRoom('lounge', 'localhost', 'dummy');
-                    test_utils.openChatRoom('leisure', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'leisure', 'localhost', 'dummy');
                     expect(converse.chatboxviews.get('lounge@localhost').$el.is(':visible')).toBeTruthy();
                     expect(converse.chatboxviews.get('leisure@localhost').$el.is(':visible')).toBeTruthy();
                 });
@@ -63,12 +48,13 @@
                     expect(converse.chatboxviews.get('lounge@localhost')).toBeUndefined();
                     expect(converse.chatboxviews.get('leisure@localhost')).toBeUndefined();
                 });
-            });
+            }));
 
-            it("has a method 'get' which returns a wrapped chat room (if it exists)", function () {
+            it("has a method 'get' which returns a wrapped chat room (if it exists)", mock.initConverse(function (converse) {
+                test_utils.createContacts(converse, 'current');
                 waits('300'); // ChatBox.show() is debounced for 250ms
                 runs(function () {
-                    test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                     var jid = 'lounge@localhost';
                     var room = converse_api.rooms.get(jid);
                     expect(room instanceof Object).toBeTruthy();
@@ -80,7 +66,7 @@
                 waits('300'); // ChatBox.show() is debounced for 250ms
                 runs(function () {
                     // Test with mixed case
-                    test_utils.openChatRoom('Leisure', 'localhost', 'dummy');
+                    test_utils.openChatRoom(converse, 'Leisure', 'localhost', 'dummy');
                     var jid = 'Leisure@localhost';
                     var room = converse_api.rooms.get(jid);
                     expect(room instanceof Object).toBeTruthy();
@@ -107,9 +93,10 @@
                     room = converse_api.rooms.get(jid);
                     expect(typeof room === 'undefined').toBeTruthy();
                 });
-            });
+            }));
 
-           it("has a method 'open' which opens and returns a wrapped chat box", function () {
+           it("has a method 'open' which opens and returns a wrapped chat box", mock.initConverse(function (converse) {
+                test_utils.createContacts(converse, 'current');
                 var chatroomview;
                 var jid = 'lounge@localhost';
                 var room = converse_api.rooms.open(jid);
@@ -151,27 +138,25 @@
                     expect(chatroomview.$el.is(':visible')).toBeTruthy();
                     chatroomview.close();
                 });
-            });
+            }));
         });
 
-
         describe("A Chat Room", function () {
-            beforeEach(function () {
-                runs(function () {
-                    test_utils.closeAllChatBoxes();
-                    test_utils.clearBrowserStorage();
-                });
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
+                test_utils.clearBrowserStorage();
             });
 
-            it("can have spaces and special characters in its name", function () {
-                test_utils.openChatRoom('lounge & leisure', 'localhost', 'dummy');
+            it("can have spaces and special characters in its name", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge & leisure', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get(
                         Strophe.escapeNode('lounge & leisure')+'@localhost');
                 expect(view instanceof converse.ChatRoomView).toBe(true);
-            });
+            }));
 
-            it("shows users currently present in the room", function () {
-                test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+            it("shows users currently present in the room", mock.initConverse(function (converse) {
+                test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var name;
                 var view = converse.chatboxviews.get('lounge@localhost'),
                     $occupants = view.$('.occupant-list');
@@ -215,10 +200,10 @@
                     converse.connection._dataRecv(test_utils.createRequest(presence));
                     expect($occupants.find('li').length).toBe(i+1);
                 }
-            });
+            }));
 
-            it("indicates moderators by means of a special css class and tooltip", function () {
-                test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+            it("indicates moderators by means of a special css class and tooltip", mock.initConverse(function (converse) {
+                test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
 
                 var presence = $pres({
@@ -239,9 +224,9 @@
                 expect($(occupant).last().text()).toBe("moderatorman");
                 expect($(occupant).last().attr('class').indexOf('moderator')).not.toBe(-1);
                 expect($(occupant).last().attr('title')).toBe('This user is a moderator. Click to mention this user in your message.');
-            });
+            }));
 
-            it("will use the user's reserved nickname, if it exists", function () {
+            it("will use the user's reserved nickname, if it exists", mock.initConverse(function (converse) {
                 var sent_IQ, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -249,7 +234,7 @@
                     IQ_id = sendIQ.bind(this)(iq, callback, errback);
                 });
 
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 spyOn(view, 'join').andCallThrough();
 
@@ -310,19 +295,19 @@
                 converse.connection._dataRecv(test_utils.createRequest(presence));
                 var info_text = view.$el.find('.chat-content .chat-info').text();
                 expect(info_text).toBe('Your nickname has been automatically set to: thirdwitch');
-            });
+            }));
 
-            it("allows the user to invite their roster contacts to enter the chat room", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("allows the user to invite their roster contacts to enter the chat room", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 spyOn(converse, 'emit');
                 spyOn(window, 'prompt').andCallFake(function () {
                     return null;
                 });
                 var $input;
-                var view = this.chatboxviews.get('lounge@localhost');
+                var view = converse.chatboxviews.get('lounge@localhost');
                 view.$el.find('.chat-area').remove();
                 view.renderChatArea(); // Will init the widget
-                test_utils.createContacts('current'); // We need roster contacts, so that we have someone to invite
+                test_utils.createContacts(converse, 'current'); // We need roster contacts, so that we have someone to invite
                 $input = view.$el.find('input.invited-contact.tt-input');
                 var $hint = view.$el.find('input.invited-contact.tt-hint');
                 runs (function () {
@@ -340,15 +325,15 @@
                     $sugg.trigger('click');
                     expect(window.prompt).toHaveBeenCalled();
                 });
-            }.bind(converse));
+            }));
 
-            it("can be joined automatically, based upon a received invite", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("can be joined automatically, based upon a received invite", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 spyOn(window, 'confirm').andCallFake(function () {
                     return true;
                 });
-                test_utils.createContacts('current'); // We need roster contacts, who can invite us
-                var view = this.chatboxviews.get('lounge@localhost');
+                test_utils.createContacts(converse, 'current'); // We need roster contacts, who can invite us
+                var view = converse.chatboxviews.get('lounge@localhost');
                 view.close();
                 var name = mock.cur_names[0];
                 var from_jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
@@ -370,12 +355,12 @@
                 expect(converse.chatboxes.models.length).toBe(2);
                 expect(converse.chatboxes.models[0].id).toBe('controlbox');
                 expect(converse.chatboxes.models[1].id).toBe(room_jid);
-            }.bind(converse));
+            }));
 
-            it("shows received groupchat messages", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("shows received groupchat messages", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 spyOn(converse, 'emit');
-                var view = this.chatboxviews.get('lounge@localhost');
+                var view = converse.chatboxviews.get('lounge@localhost');
                 if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
                 var nick = mock.chatroom_names[0];
                 var text = 'This is a received message';
@@ -390,10 +375,10 @@
                 expect($chat_content.find('.chat-message').length).toBe(1);
                 expect($chat_content.find('.chat-msg-content').text()).toBe(text);
                 expect(converse.emit).toHaveBeenCalledWith('message', message.nodeTree);
-            }.bind(converse));
+            }));
 
-            it("shows sent groupchat messages", function () {
-                test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+            it("shows sent groupchat messages", mock.initConverse(function (converse) {
+                test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 spyOn(converse, 'emit');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
@@ -417,11 +402,11 @@
                 expect($chat_content.find('.chat-msg-content').last().text()).toBe(text);
                 // We don't emit an event if it's our own message
                 expect(converse.emit.callCount, 1);
-            });
+            }));
 
-            it("will cause the chat area to be scrolled down only if it was at the bottom already", function () {
+            it("will cause the chat area to be scrolled down only if it was at the bottom already", mock.initConverse(function (converse) {
                 var message = 'This message is received while the chat area is scrolled up';
-                test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+                test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 spyOn(view, 'scrollDown').andCallThrough();
                 runs(function () {
@@ -461,10 +446,10 @@
                     expect(msg_txt).toEqual(message);
                     expect(view.$content.scrollTop()).toBe(0);
                 });
-            });
+            }));
 
-            it("shows received chatroom subject messages", function () {
-                test_utils.openAndEnterChatRoom('jdev', 'conference.jabber.org', 'jc');
+            it("shows received chatroom subject messages", mock.initConverse(function (converse) {
+                test_utils.openAndEnterChatRoom(converse, 'jdev', 'conference.jabber.org', 'jc');
 
                 var text = 'Jabber/XMPP Development | RFCs and Extensions: http://xmpp.org/ | Protocol and XSF discussions: xsf@muc.xmpp.org';
                 var stanza = Strophe.xmlHtmlNode(
@@ -478,9 +463,9 @@
                 var $chat_content = view.$el.find('.chat-content');
                 expect($chat_content.find('.chat-info').length).toBe(1);
                 expect($chat_content.find('.chat-info').text()).toBe('Topic set by ralphm to: '+text);
-            });
+            }));
 
-            it("informs users if their nicknames has been changed.", function () {
+            it("informs users if their nicknames has been changed.", mock.initConverse(function (converse) {
                 /* The service then sends two presence stanzas to the full JID
                  * of each occupant (including the occupant who is changing his
                  * or her room nickname), one of type "unavailable" for the old
@@ -517,7 +502,7 @@
                  *  </presence>
                  */
                 var __ = utils.__.bind(converse);
-                test_utils.openAndEnterChatRoom('lounge', 'localhost', 'oldnick');
+                test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'oldnick');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 var $chat_content = view.$el.find('.chat-content');
 
@@ -588,9 +573,9 @@
                 $occupants = view.$('.occupant-list');
                 expect($occupants.children().length).toBe(1);
                 expect($occupants.children().first(0).text()).toBe("newnick");
-            });
+            }));
 
-            it("informs users if they have been kicked out of the chat room", function () {
+            it("informs users if they have been kicked out of the chat room", mock.initConverse(function (converse) {
                 /*  <presence
                  *      from='harfleur@chat.shakespeare.lit/pistol'
                  *      to='pistol@shakespeare.lit/harfleur'
@@ -604,7 +589,7 @@
                  *  </x>
                  *  </presence>
                  */
-                test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+                test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var presence = $pres().attrs({
                         from:'lounge@localhost/dummy',
                         to:'dummy@localhost/pda',
@@ -621,20 +606,20 @@
                     .up()
                     .c('status').attrs({code:'307'}).nodeTree;
 
-                var view = this.chatboxviews.get('lounge@localhost');
+                var view = converse.chatboxviews.get('lounge@localhost');
                 view.onChatRoomPresence(presence);
                 expect(view.$('.chat-area').is(':visible')).toBeFalsy();
                 expect(view.$('.occupants').is(':visible')).toBeFalsy();
                 var $chat_body = view.$('.chatroom-body');
                 expect($chat_body.html().trim().indexOf('<p>You have been kicked from this room</p><p>The reason given is: "Avaunt, you cullion!"</p>')).not.toBe(-1);
-            }.bind(converse));
+            }));
 
-            it("can be saved to, and retrieved from, browserStorage", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("can be saved to, and retrieved from, browserStorage", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 // We instantiate a new ChatBoxes collection, which by default
                 // will be empty.
                 test_utils.openControlBox();
-                var newchatboxes = new this.ChatBoxes();
+                var newchatboxes = new converse.ChatBoxes();
                 expect(newchatboxes.length).toEqual(0);
                 // The chatboxes will then be fetched from browserStorage inside the
                 // onConnected method
@@ -646,20 +631,20 @@
                 var new_attrs, old_attrs;
                 for (var i=0; i<attrs.length; i++) {
                     new_attrs = _.pluck(_.pluck(newchatboxes.models, 'attributes'), attrs[i]);
-                    old_attrs = _.pluck(_.pluck(this.chatboxes.models, 'attributes'), attrs[i]);
+                    old_attrs = _.pluck(_.pluck(converse.chatboxes.models, 'attributes'), attrs[i]);
                     // FIXME: should have have to sort here? Order must
                     // probably be the same...
                     // This should be fixed once the controlbox always opens
                     // only on the right.
                     expect(_.isEqual(new_attrs.sort(), old_attrs.sort())).toEqual(true);
                 }
-                this.rosterview.render();
-            }.bind(converse));
+                converse.rosterview.render();
+            }));
 
-            it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
-                var view = this.chatboxviews.get('lounge@localhost'),
-                    trimmed_chatboxes = this.minimized_chats;
+            it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
+                var view = converse.chatboxviews.get('lounge@localhost'),
+                    trimmed_chatboxes = converse.minimized_chats;
                 spyOn(view, 'minimize').andCallThrough();
                 spyOn(view, 'maximize').andCallThrough();
                 spyOn(converse, 'emit');
@@ -686,11 +671,10 @@
                     expect(view.model.get('minimized')).toBeFalsy();
                     expect(converse.emit.callCount, 3);
                 });
-            }.bind(converse));
-
+            }));
 
-            it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("can be closed again by clicking a DOM element with class 'close-chatbox-button'", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 spyOn(view, 'close').andCallThrough();
                 spyOn(converse, 'emit');
@@ -705,20 +689,19 @@
                     expect(view.leave).toHaveBeenCalled();
                     expect(converse.emit).toHaveBeenCalledWith('chatBoxClosed', jasmine.any(Object));
                 });
-            });
-        }.bind(converse));
+            }));
+        });
 
 
         describe("Each chat room can take special commands", function () {
-            beforeEach(function () {
-                runs(function () {
-                    test_utils.closeAllChatBoxes();
-                    test_utils.clearBrowserStorage();
-                });
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
+                test_utils.clearBrowserStorage();
             });
 
-            it("to clear messages", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("to clear messages", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 spyOn(view, 'onMessageSubmitted').andCallThrough();
                 spyOn(view, 'clearChatRoomMessages');
@@ -727,10 +710,10 @@
                 expect(view.onMessageSubmitted).toHaveBeenCalled();
                 expect(view.clearChatRoomMessages).toHaveBeenCalled();
 
-            });
+            }));
 
-            it("to ban a user", function () {
-                test_utils.openChatRoom('lounge', 'localhost', 'dummy');
+            it("to ban a user", mock.initConverse(function (converse) {
+                test_utils.openChatRoom(converse, 'lounge', 'localhost', 'dummy');
                 var view = converse.chatboxviews.get('lounge@localhost');
                 spyOn(view, 'onMessageSubmitted').andCallThrough();
                 spyOn(view, 'setAffiliation').andCallThrough();
@@ -754,13 +737,18 @@
                 expect(view.validateRoleChangeCommand.callCount).toBe(2);
                 expect(view.showStatusNotification.callCount).toBe(1);
                 expect(view.setAffiliation).toHaveBeenCalled();
-            });
-
-        }.bind(converse));
+            }));
+        });
 
         describe("When attempting to enter a chatroom", function () {
-            beforeEach(function () {
-                var roomspanel = this.chatboxviews.get('controlbox').roomspanel;
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
+                test_utils.clearBrowserStorage();
+            });
+            
+            var submitRoomForm = function (converse) {
+                var roomspanel = converse.chatboxviews.get('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');
@@ -768,14 +756,10 @@
                 $nick.val('dummy');
                 $server.val('muc.localhost');
                 roomspanel.$el.find('form').submit();
-            }.bind(converse));
+            };
 
-            afterEach(function () {
-                var view = this.chatboxviews.get('problematic@muc.localhost');
-                view.close();
-            }.bind(converse));
-
-            it("will show an error message if the room requires a password", function () {
+            it("will show an error message if the room requires a password", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -785,7 +769,7 @@
                 .c('error').attrs({by:'lounge@localhost', type:'auth'})
                     .c('not-authorized').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
 
-                var view = this.chatboxviews.get('problematic@muc.localhost');
+                var view = converse.chatboxviews.get('problematic@muc.localhost');
                 spyOn(view, 'renderPasswordForm').andCallThrough();
                 runs(function () {
                     view.onChatRoomPresence(presence);
@@ -797,9 +781,10 @@
                     expect($chat_body.find('form.chatroom-form').length).toBe(1);
                     expect($chat_body.find('legend').text()).toBe('This chatroom requires a password');
                 });
-            }.bind(converse));
+            }));
 
-            it("will show an error message if the room is members-only and the user not included", function () {
+            it("will show an error message if the room is members-only and the user not included", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -812,9 +797,10 @@
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body p:last').text()).toBe('You are not on the member list of this room');
-            });
+            }));
 
-            it("will show an error message if the user has been banned", function () {
+            it("will show an error message if the user has been banned", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -827,9 +813,10 @@
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body p:last').text()).toBe('You have been banned from this room');
-            });
+            }));
 
-            it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false", function () {
+            it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -842,9 +829,9 @@
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body form.chatroom-form label:first').text()).toBe('Please choose your nickname');
-            });
+            }));
 
-            it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true", function () {
+            it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true", mock.initConverse(function (converse) {
                 /*
                     <presence
                         from='coven@chat.shakespeare.lit/thirdwitch'
@@ -857,6 +844,7 @@
                     </error>
                     </presence>
                 */
+                submitRoomForm(converse);
                 converse.muc_nickname_from_jid = true;
 
                 var attrs = {
@@ -895,9 +883,10 @@
                         .c('conflict').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
                 view.onChatRoomPresence(presence);
                 expect(view.join).toHaveBeenCalledWith('dummy-4');
-            });
+            }));
 
-            it("will show an error message if the user is not allowed to have created the room", function () {
+            it("will show an error message if the user is not allowed to have created the room", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -906,13 +895,14 @@
                 .c('x').attrs({xmlns:'http://jabber.org/protocol/muc'}).up()
                 .c('error').attrs({by:'lounge@localhost', type:'cancel'})
                     .c('not-allowed').attrs({xmlns:'urn:ietf:params:xml:ns:xmpp-stanzas'}).nodeTree;
-                var view = this.chatboxviews.get('problematic@muc.localhost');
+                var view = converse.chatboxviews.get('problematic@muc.localhost');
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body p:last').text()).toBe('You are not allowed to create new rooms');
-            }.bind(converse));
+            }));
 
-            it("will show an error message if the user's nickname doesn't conform to room policy", function () {
+            it("will show an error message if the user's nickname doesn't conform to room policy", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -925,9 +915,10 @@
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body p:last').text()).toBe("Your nickname doesn't conform to this room's policies");
-            });
+            }));
 
-            it("will show an error message if the room doesn't yet exist", function () {
+            it("will show an error message if the room doesn't yet exist", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -940,9 +931,10 @@
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body p:last').text()).toBe("This room does not (yet) exist");
-            });
+            }));
 
-            it("will show an error message if the room has reached its maximum number of occupants", function () {
+            it("will show an error message if the room has reached its maximum number of occupants", mock.initConverse(function (converse) {
+                submitRoomForm(converse);
                 var presence = $pres().attrs({
                     from:'lounge@localhost/thirdwitch',
                         id:'n13mt3l',
@@ -955,7 +947,7 @@
                 spyOn(view, 'showErrorMessage').andCallThrough();
                 view.onChatRoomPresence(presence);
                 expect(view.$el.find('.chatroom-body p:last').text()).toBe("This room has reached its maximum number of occupants");
-            });
-        }.bind(converse));
-    }.bind(converse, mock, test_utils));
+            }));
+        });
+    });
 }));

File diff suppressed because it is too large
+ 297 - 308
spec/controlbox.js


+ 1 - 0
spec/converse.js

@@ -15,6 +15,7 @@
         
         afterEach(function () {
             converse_api.user.logout();
+            converse_api.listen.not();
             test_utils.clearBrowserStorage();
         });
 

+ 12 - 7
spec/disco.js

@@ -1,4 +1,3 @@
-/*global converse */
 (function (root, factory) {
     define([
         "jquery",
@@ -12,15 +11,21 @@
     "use strict";
     var Strophe = converse_api.env.Strophe;
 
-    describe("Service Discovery", $.proxy(function (mock, test_utils) {
+    describe("Service Discovery", function () {
 
-        describe("Whenever converse.js discovers a new server feature", $.proxy(function (mock, test_utils) {
-           it("emits the serviceDiscovered event", function () {
+        describe("Whenever converse.js discovers a new server feature", function () {
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
+                test_utils.clearBrowserStorage();
+            });
+
+           it("emits the serviceDiscovered event", mock.initConverse(function (converse) {
                 spyOn(converse, 'emit');
                 converse.features.create({'var': Strophe.NS.MAM});
                 expect(converse.emit).toHaveBeenCalled();
                 expect(converse.emit.argsForCall[0][1].get('var')).toBe(Strophe.NS.MAM);
-            });
-        }, converse, mock, test_utils));
-    }, converse, mock, test_utils));
+            }));
+        });
+    });
 }));

+ 11 - 20
spec/eventemitter.js

@@ -1,19 +1,10 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "mock",
-        "test_utils"
-        ], function ($, mock, test_utils) {
-            return factory($, mock, test_utils);
-        }
-    );
-} (this, function ($, mock, test_utils) {
-    return describe("The Converse Event Emitter", $.proxy(function(mock, test_utils) {
-        window.localStorage.clear();
-        window.sessionStorage.clear();
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
 
-        it("allows you to subscribe to emitted events", function () {
+    return describe("The Converse Event Emitter", function() {
+
+        it("allows you to subscribe to emitted events", mock.initConverse(function (converse) {
             this.callback = function () {};
             spyOn(this, 'callback');
             converse.on('connected', this.callback);
@@ -23,9 +14,9 @@
             expect(this.callback.callCount, 2);
             converse.emit('connected');
             expect(this.callback.callCount, 3);
-        });
+        }));
 
-        it("allows you to listen once for an emitted event", function () {
+        it("allows you to listen once for an emitted event", mock.initConverse(function (converse) {
             this.callback = function () {};
             spyOn(this, 'callback');
             converse.once('connected', this.callback);
@@ -35,9 +26,9 @@
             expect(this.callback.callCount, 1);
             converse.emit('connected');
             expect(this.callback.callCount, 1);
-        });
+        }));
 
-        it("allows you to stop listening or subscribing to an event", function () {
+        it("allows you to stop listening or subscribing to an event", mock.initConverse(function (converse) {
             this.callback = function () {};
             this.anotherCallback = function () {};
             this.neverCalled = function () {};
@@ -65,6 +56,6 @@
             expect(this.callback.callCount, 1);
             expect(this.anotherCallback.callCount, 3);
             expect(this.neverCalled).not.toHaveBeenCalled();
-        });
-    }, converse, mock, test_utils));
+        }));
+    });
 }));

+ 11 - 9
spec/headline.js

@@ -1,4 +1,3 @@
-/*global converse */
 (function (root, factory) {
     define([
         "jquery",
@@ -13,12 +12,12 @@
 
     describe("A headlines box", function () {
 
-        beforeEach(function () {
-            test_utils.openControlBox();
-            test_utils.openContactsPanel();
+        afterEach(function () {
+            converse_api.user.logout();
+            test_utils.clearBrowserStorage();
         });
 
-        it("will not open nor display non-headline messages", function () {
+        it("will not open nor display non-headline messages", mock.initConverse(function (converse) {
             /* XMPP spam message:
              *
              *  <message xmlns="jabber:client"
@@ -29,6 +28,8 @@
              *      <body>SORRY FOR THIS ADVERT</body
              *  </message
              */
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
             sinon.spy(utils, 'isHeadlineMessage');
             runs(function () {
                 var stanza = $msg({
@@ -47,11 +48,10 @@
                 expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
                 utils.isHeadlineMessage.restore();
             });
-
-        });
+        }));
 
 
-        it("will open and display headline messages", function () {
+        it("will open and display headline messages", mock.initConverse(function (converse) {
             /*
              *  <message from='notify.example.com'
              *          to='romeo@im.example.com'
@@ -66,6 +66,8 @@
              *  </x>
              *  </message>
              */
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
             sinon.spy(utils, 'isHeadlineMessage');
             runs(function () {
                 var stanza = $msg({
@@ -91,6 +93,6 @@
                 expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
                 utils.isHeadlineMessage.restore(); // unwraps
             });
-        });
+        }));
     });
 }));

+ 47 - 39
spec/mam.js

@@ -1,28 +1,27 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "underscore",
-        "mock",
-        "test_utils"
-        ], function ($, _, mock, test_utils) {
-            return factory($, _, mock, test_utils);
-        }
-    );
-} (this, function ($, _, mock, test_utils) {
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
     "use strict";
+    var _ = converse_api.env._;
+    var $ = converse_api.env.jQuery;
     var Strophe = converse_api.env.Strophe;
     var $iq = converse_api.env.$iq;
     var $msg = converse_api.env.$msg;
     var moment = converse_api.env.moment;
     // See: https://xmpp.org/rfcs/rfc3921.html
 
-    describe("Message Archive Management", $.proxy(function (mock, test_utils) {
+    describe("Message Archive Management", function () {
         // Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
 
-        describe("The archive.query API", $.proxy(function (mock, test_utils) {
+        describe("The archive.query API", function () {
 
-           it("can be used to query for all archived messages", function () {
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
+                test_utils.clearBrowserStorage();
+            });
+
+           it("can be used to query for all archived messages", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -36,9 +35,9 @@
                 var queryid = $(sent_stanza.toString()).find('query').attr('queryid');
                 expect(sent_stanza.toString()).toBe(
                     "<iq type='set' xmlns='jabber:client' id='"+IQ_id+"'><query xmlns='urn:xmpp:mam:0' queryid='"+queryid+"'/></iq>");
-            });
+            }));
 
-           it("can be used to query for all messages to/from a particular JID", function () {
+           it("can be used to query for all messages to/from a particular JID", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -64,9 +63,9 @@
                         "</query>"+
                     "</iq>"
                 );
-            });
+            }));
 
-           it("can be used to query for all messages in a certain timespan", function () {
+           it("can be used to query for all messages in a certain timespan", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -101,15 +100,18 @@
                         "</query>"+
                     "</iq>"
                 );
-           });
+           }));
 
-           it("throws a TypeError if an invalid date is provided", function () {
+           it("throws a TypeError if an invalid date is provided", mock.initConverse(function (converse) {
+                if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
+                    converse.features.create({'var': Strophe.NS.MAM});
+                }
                 expect(_.partial(converse_api.archive.query, {'start': 'not a real date'})).toThrow(
                     new TypeError('archive.query: invalid date provided for: start')
                 );
-           });
+           }));
 
-           it("can be used to query for all messages after a certain time", function () {
+           it("can be used to query for all messages after a certain time", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -136,9 +138,9 @@
                         "</query>"+
                     "</iq>"
                 );
-           });
+           }));
 
-           it("can be used to query for a limited set of results", function () {
+           it("can be used to query for a limited set of results", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -168,9 +170,9 @@
                         "</query>"+
                     "</iq>"
                 );
-           });
+           }));
 
-           it("can be used to page through results", function () {
+           it("can be used to page through results", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -205,9 +207,9 @@
                         "</query>"+
                     "</iq>"
                 );
-           });
+           }));
 
-           it("accepts \"before\" with an empty string as value to reverse the order", function () {
+           it("accepts \"before\" with an empty string as value to reverse the order", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -234,9 +236,9 @@
                         "</query>"+
                     "</iq>"
                 );
-           });
+           }));
 
-           it("accepts a Strophe.RSM object for the query options", function () {
+           it("accepts a Strophe.RSM object for the query options", mock.initConverse(function (converse) {
                 // Normally the user wouldn't manually make a Strophe.RSM object
                 // and pass it in. However, in the callback method an RSM object is
                 // returned which can be reused for easy paging. This test is
@@ -276,9 +278,9 @@
                         "</query>"+
                     "</iq>"
                 );
-           });
+           }));
 
-           it("accepts a callback function, which it passes the messages and a Strophe.RSM object", function () {
+           it("accepts a callback function, which it passes the messages and a Strophe.RSM object", mock.initConverse(function (converse) {
                 if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
                     converse.features.create({'var': Strophe.NS.MAM});
                 }
@@ -365,13 +367,19 @@
                 expect(args[1].count).toBe('16');
                 expect(args[1].first).toBe('23452-4534-1');
                 expect(args[1].last).toBe('390-2342-22');
-           });
+           }));
 
-        }, converse, mock, test_utils));
+        });
 
-        describe("The default preference", $.proxy(function (mock, test_utils) {
+        describe("The default preference", function () {
 
-            it("is set once server support for MAM has been confirmed", function () {
+            afterEach(function () {
+                converse_api.user.logout();
+                converse_api.listen.not();
+                test_utils.clearBrowserStorage();
+            });
+
+            it("is set once server support for MAM has been confirmed", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -443,7 +451,7 @@
 
                 // Restore
                 converse.message_archiving = 'never';
-            });
-        }, converse, mock, test_utils));
-    }, converse, mock, test_utils));
+            }));
+        });
+    });
 }));

+ 72 - 70
spec/minchats.js

@@ -1,129 +1,131 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "underscore",
-        "mock",
-        "test_utils"
-        ], function ($, _, mock, test_utils) {
-            return factory($, _, mock, test_utils);
-        }
-    );
-} (this, function ($, _, mock, test_utils) {
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
+    var _ = converse_api.env._;
     var $msg = converse_api.env.$msg;
 
-    return describe("The Minimized Chats Widget", $.proxy(function(mock, test_utils) {
-        beforeEach(function () {
-            runs(function () {
-                test_utils.closeAllChatBoxes();
-                test_utils.removeControlBox();
-                converse.roster.browserStorage._clear();
-                test_utils.initConverse();
-                test_utils.createContacts('current');
-                test_utils.openControlBox();
-                test_utils.openContactsPanel();
-                converse.minimized_chats.toggleview.model.browserStorage._clear();
-                converse.minimized_chats.initToggle();
-            });
+    describe("The Minimized Chats Widget", function () {
+        afterEach(function () {
+            converse_api.user.logout();
+            converse_api.listen.not();
+            test_utils.clearBrowserStorage();
         });
 
-        it("shows chats that have been minimized",  $.proxy(function () {
+
+        it("shows chats that have been minimized",  mock.initConverse(function (converse) {
+            test_utils.createContacts(converse, 'current');
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
+            converse.minimized_chats.toggleview.model.browserStorage._clear();
+            converse.minimized_chats.initToggle();
+
             var contact_jid, chatview;
             contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
-            test_utils.openChatBoxFor(contact_jid);
+            test_utils.openChatBoxFor(converse, contact_jid);
             chatview = converse.chatboxviews.get(contact_jid);
             expect(chatview.model.get('minimized')).toBeFalsy();
-            expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
+            expect(converse.minimized_chats.$el.is(':visible')).toBeFalsy();
             chatview.$el.find('.toggle-chatbox-button').click();
             expect(chatview.model.get('minimized')).toBeTruthy();
-            expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
-            expect(this.minimized_chats.keys().length).toBe(1);
-            expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
+            expect(converse.minimized_chats.$el.is(':visible')).toBeTruthy();
+            expect(converse.minimized_chats.keys().length).toBe(1);
+            expect(converse.minimized_chats.keys()[0]).toBe(contact_jid);
 
             contact_jid = mock.cur_names[1].replace(/ /g,'.').toLowerCase() + '@localhost';
-            test_utils.openChatBoxFor(contact_jid);
+            test_utils.openChatBoxFor(converse, contact_jid);
             chatview = converse.chatboxviews.get(contact_jid);
             expect(chatview.model.get('minimized')).toBeFalsy();
             chatview.$el.find('.toggle-chatbox-button').click();
             expect(chatview.model.get('minimized')).toBeTruthy();
-            expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
-            expect(this.minimized_chats.keys().length).toBe(2);
-            expect(_.contains(this.minimized_chats.keys(), contact_jid)).toBeTruthy();
-        }, converse));
+            expect(converse.minimized_chats.$el.is(':visible')).toBeTruthy();
+            expect(converse.minimized_chats.keys().length).toBe(2);
+            expect(_.contains(converse.minimized_chats.keys(), contact_jid)).toBeTruthy();
+        }));
+
+        it("can be toggled to hide or show minimized chats", mock.initConverse(function (converse) {
+            test_utils.createContacts(converse, 'current');
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
+            converse.minimized_chats.toggleview.model.browserStorage._clear();
+            converse.minimized_chats.initToggle();
 
-        it("can be toggled to hide or show minimized chats",  $.proxy(function () {
             var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
-            test_utils.openChatBoxFor(contact_jid);
+            test_utils.openChatBoxFor(converse, contact_jid);
             var chatview = converse.chatboxviews.get(contact_jid);
-            expect(this.minimized_chats.$el.is(':visible')).toBeFalsy();
+            expect(converse.minimized_chats.$el.is(':visible')).toBeFalsy();
             chatview.model.set({'minimized': true});
-            expect(this.minimized_chats.$el.is(':visible')).toBeTruthy();
-            expect(this.minimized_chats.keys().length).toBe(1);
-            expect(this.minimized_chats.keys()[0]).toBe(contact_jid);
-            expect(this.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
-            expect(this.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
-            this.minimized_chats.$('#toggle-minimized-chats').click();
-            expect(this.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
-            expect(this.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
-        }, converse));
+            expect(converse.minimized_chats.$el.is(':visible')).toBeTruthy();
+            expect(converse.minimized_chats.keys().length).toBe(1);
+            expect(converse.minimized_chats.keys()[0]).toBe(contact_jid);
+            expect(converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeTruthy();
+            expect(converse.minimized_chats.toggleview.model.get('collapsed')).toBeFalsy();
+            converse.minimized_chats.$('#toggle-minimized-chats').click();
+            expect(converse.minimized_chats.$('.minimized-chats-flyout').is(':visible')).toBeFalsy();
+            expect(converse.minimized_chats.toggleview.model.get('collapsed')).toBeTruthy();
+        }));
+
+        it("shows the number messages received to minimized chats", mock.initConverse(function (converse) {
+            test_utils.createContacts(converse, 'current');
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
+            converse.minimized_chats.toggleview.model.browserStorage._clear();
+            converse.minimized_chats.initToggle();
 
-        it("shows the number messages received to minimized chats",  $.proxy(function () {
             var i, contact_jid, chatview, msg;
-            this.minimized_chats.toggleview.model.set({'collapsed': true});
-            expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
+            converse.minimized_chats.toggleview.model.set({'collapsed': true});
+            expect(converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeFalsy();
             for (i=0; i<3; i++) {
                 contact_jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
-                test_utils.openChatBoxFor(contact_jid);
+                test_utils.openChatBoxFor(converse, contact_jid);
                 chatview = converse.chatboxviews.get(contact_jid);
                 chatview.model.set({'minimized': true});
                 msg = $msg({
                     from: contact_jid,
-                    to: this.connection.jid,
+                    to: converse.connection.jid,
                     type: 'chat',
                     id: (new Date()).getTime()
                 }).c('body').t('This message is sent to a minimized chatbox').up()
                 .c('active', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree();
-                this.chatboxes.onMessage(msg);
-                expect(this.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy();
-                expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i+1).toString());
+                converse.chatboxes.onMessage(msg);
+                expect(converse.minimized_chats.toggleview.$('.unread-message-count').is(':visible')).toBeTruthy();
+                expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i+1).toString());
             }
             // Chat state notifications don't increment the unread messages counter
             // <composing> state
-            this.chatboxes.onMessage($msg({
+            converse.chatboxes.onMessage($msg({
                 from: contact_jid,
-                to: this.connection.jid,
+                to: converse.connection.jid,
                 type: 'chat',
                 id: (new Date()).getTime()
             }).c('composing', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
-            expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
+            expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
 
             // <paused> state
-            this.chatboxes.onMessage($msg({
+            converse.chatboxes.onMessage($msg({
                 from: contact_jid,
-                to: this.connection.jid,
+                to: converse.connection.jid,
                 type: 'chat',
                 id: (new Date()).getTime()
             }).c('paused', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
-            expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
+            expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
 
             // <gone> state
-            this.chatboxes.onMessage($msg({
+            converse.chatboxes.onMessage($msg({
                 from: contact_jid,
-                to: this.connection.jid,
+                to: converse.connection.jid,
                 type: 'chat',
                 id: (new Date()).getTime()
             }).c('gone', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
-            expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
+            expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
 
             // <inactive> state
-            this.chatboxes.onMessage($msg({
+            converse.chatboxes.onMessage($msg({
                 from: contact_jid,
-                to: this.connection.jid,
+                to: converse.connection.jid,
                 type: 'chat',
                 id: (new Date()).getTime()
             }).c('inactive', {'xmlns': 'http://jabber.org/protocol/chatstates'}).tree());
-            expect(this.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
-        }, converse));
-
-    }, converse, mock, test_utils));
+            expect(converse.minimized_chats.toggleview.$('.unread-message-count').text()).toBe((i).toString());
+        }));
+    });
 }));

+ 28 - 30
spec/notification.js

@@ -1,33 +1,23 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "underscore",
-        "mock",
-        "test_utils"
-        ], function ($, _, mock, test_utils) {
-            return factory($, _, mock, test_utils);
-        }
-    );
-} (this, function ($, _, mock, test_utils) {
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
     "use strict";
     var $msg = converse_api.env.$msg;
 
     describe("Notifications", function () {
         // Implement the protocol defined in https://xmpp.org/extensions/xep-0313.html#config
-        beforeEach(function () {
-            runs(function () {
-                test_utils.closeAllChatBoxes();
-                test_utils.createContacts('current');
-            });
-        });
 
         describe("When show_desktop_notifications is set to true", function () {
             describe("And the desktop is not focused", function () {
                 describe("an HTML5 Notification", function () {
+                    afterEach(function () {
+                        converse_api.user.logout();
+                        test_utils.clearBrowserStorage();
+                    });
 
-                    it("is shown when a new private message is received", function () {
+                    it("is shown when a new private message is received", mock.initConverse(function (converse) {
                         // TODO: not yet testing show_desktop_notifications setting
+                        test_utils.createContacts(converse, 'current');
                         spyOn(converse, 'showMessageNotification');
                         spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
                         
@@ -43,10 +33,11 @@
                         converse.chatboxes.onMessage(msg); // This will emit 'message'
                         expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
                         expect(converse.showMessageNotification).toHaveBeenCalled();
-                    });
+                    }));
 
-                    it("is shown when you are mentioned in a chat room", function () {
-                        test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+                    it("is shown when you are mentioned in a chat room", mock.initConverse(function (converse) {
+                        test_utils.createContacts(converse, 'current');
+                        test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                         var view = converse.chatboxviews.get('lounge@localhost');
                         if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
                         var no_notification = false;
@@ -75,39 +66,46 @@
                         if (no_notification) {
                             delete window.Notification;
                         }
-                    });
+                    }));
 
-                    it("is shown when a user changes their chat state", function () {
+                    it("is shown when a user changes their chat state", mock.initConverse(function (converse) {
                         // TODO: not yet testing show_desktop_notifications setting
+                        test_utils.createContacts(converse, 'current');
                         spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
                         spyOn(converse, 'showChatStateNotification');
                         var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
                         converse.roster.get(jid).set('chat_status', 'busy'); // This will emit 'contactStatusChanged'
                         expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
                         expect(converse.showChatStateNotification).toHaveBeenCalled();
-                    });
+                    }));
                 });
             });
 
             describe("When a new contact request is received", function () {
-                it("an HTML5 Notification is received", function () {
+                it("an HTML5 Notification is received", mock.initConverse(function (converse) {
                     spyOn(converse, 'areDesktopNotificationsEnabled').andReturn(true);
                     spyOn(converse, 'showContactRequestNotification');
                     converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
                     expect(converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
                     expect(converse.showContactRequestNotification).toHaveBeenCalled();
-                });
+                }));
             });
         });
 
         describe("When play_sounds is set to true", function () {
             describe("A notification sound", function () {
 
-                it("is played when the current user is mentioned in a chat room", function () {
-                    test_utils.openAndEnterChatRoom('lounge', 'localhost', 'dummy');
+                afterEach(function () {
+                    converse_api.user.logout();
+                    test_utils.clearBrowserStorage();
+                });
+
+                it("is played when the current user is mentioned in a chat room", mock.initConverse(function (converse) {
+                    test_utils.createContacts(converse, 'current');
+                    test_utils.openAndEnterChatRoom(converse, 'lounge', 'localhost', 'dummy');
                     converse.play_sounds = true;
                     spyOn(converse, 'playSoundNotification');
-                    var view = this.chatboxviews.get('lounge@localhost');
+                    var view = converse.chatboxviews.get('lounge@localhost');
                     if (!view.$el.find('.chat-area').length) { view.renderChatArea(); }
                     var text = 'This message will play a sound because it mentions dummy';
                     var message = $msg({
@@ -140,7 +138,7 @@
                     view.onChatRoomMessage(message.nodeTree);
                     expect(converse.playSoundNotification, 1);
                     converse.play_sounds = false;
-                }.bind(converse));
+                }));
             });
         });
     });

+ 25 - 21
spec/otr.js

@@ -1,27 +1,23 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "mock",
-        "test_utils"
-        ], function ($, mock, test_utils) {
-            return factory($, mock, test_utils);
-        }
-    );
-} (this, function ($, mock, test_utils) {
+    define(["mock","test_utils" ], factory);
+} (this, function (mock, test_utils) {
+    var $ = converse_api.env.jQuery;
     var Strophe = converse_api.env.Strophe;
     var b64_sha1 = converse_api.env.b64_sha1;
 
     return describe("The OTR module", function() {
-        beforeEach(function () {
-            test_utils.openControlBox();
-            test_utils.openContactsPanel();
-            test_utils.createContacts('current');
+        afterEach(function () {
+            converse_api.user.logout();
+            test_utils.clearBrowserStorage();
         });
 
-        it("can store a session passphrase in session storage", function () {
+        it("can store a session passphrase in session storage", mock.initConverse(function (converse) {
             // With no prebind, the user's XMPP password is used and nothing is
             // stored in session storage.
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
+            test_utils.createContacts(converse, 'current');
+
             var auth = converse.authentication;
             var pass = converse.connection.pass;
             converse.authentication = "manual";
@@ -38,13 +34,17 @@
             // Clean up
             converse.authentication = auth;
             converse.connection.pass = pass;
-        });
+        }));
+
+        it("will add processing hints to sent out encrypted <message> stanzas", mock.initConverse(function (converse) {
+            test_utils.openControlBox();
+            test_utils.openContactsPanel(converse);
+            test_utils.createContacts(converse, 'current');
 
-        it("will add processing hints to sent out encrypted <message> stanzas", function () {
             var UNVERIFIED = 1, UNENCRYPTED = 0;
             var contact_name = mock.cur_names[0];
             var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
-            test_utils.openChatBoxFor(contact_jid);
+            test_utils.openChatBoxFor(converse, contact_jid);
             var chatview = converse.chatboxviews.get(contact_jid);
             chatview.model.set('otr_status', UNVERIFIED);
             var stanza = chatview.createMessageStanza(new converse.Message({ message: 'hello world'}));
@@ -54,11 +54,15 @@
             expect($hints.get(1).tagName).toBe('no-permanent-store');
             expect($hints.get(2).tagName).toBe('no-copy');
             chatview.model.set('otr_status', UNENCRYPTED); // Reset again to UNENCRYPTED
-        });
+        }));
 
         describe("An OTR Chat Message", function () {
 
-            it("will not be carbon copied when it's sent out", function () {
+            it("will not be carbon copied when it's sent out", mock.initConverse(function (converse) {
+                test_utils.openControlBox();
+                test_utils.openContactsPanel(converse);
+                test_utils.createContacts(converse, 'current');
+
                 var msgtext = "?OTR,1,3,?OTR:AAIDAAAAAAEAAAABAAAAwCQ8HKsag0y0DGKsneo0kzKu1ua5L93M4UKTkCf1I2kbm2RgS5kIxDTxrTj3wVRB+H5Si86E1fKtuBgsDf/bKkGTM0h/49vh5lOD9HkE8cnSrFEn5GN,";
                 var sender_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
                 converse_api.chats.open(sender_jid);
@@ -71,7 +75,7 @@
                 expect($sent.find('private').length).toBe(1);
                 expect($sent.find('private').attr('xmlns')).toBe('urn:xmpp:carbons:2');
                 chatbox.set('otr_status', 0); // Reset again to UNENCRYPTED
-            });
+            }));
         });
     });
 }));

+ 18 - 15
spec/ping.js

@@ -1,36 +1,39 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "converse-ping"
-        ], function ($) {
-            return factory($);
-        }
-    );
-} (this, function ($) {
+    define(["mock", "test_utils", "converse-ping"], factory);
+} (this, function (mock, test_utils) {
     "use strict";
 
     describe("XMPP Ping", function () {
         describe("Ping and pong handlers", function () {
-            it("are registered when converse.js is connected", function () {
+            afterEach(function () {
+                converse_api.user.logout();
+                test_utils.clearBrowserStorage();
+            });
+
+            it("are registered when converse.js is connected", mock.initConverse(function (converse) {
                 spyOn(converse, 'registerPingHandler').andCallThrough();
                 spyOn(converse, 'registerPongHandler').andCallThrough();
                 converse.emit('connected');
                 expect(converse.registerPingHandler).toHaveBeenCalled();
                 expect(converse.registerPongHandler).toHaveBeenCalled();
-            });
+            }));
 
-            it("are registered when converse.js reconnected", function () {
+            it("are registered when converse.js reconnected", mock.initConverse(function (converse) {
                 spyOn(converse, 'registerPingHandler').andCallThrough();
                 spyOn(converse, 'registerPongHandler').andCallThrough();
                 converse.emit('reconnected');
                 expect(converse.registerPingHandler).toHaveBeenCalled();
                 expect(converse.registerPongHandler).toHaveBeenCalled();
-            });
+            }));
         });
 
         describe("An IQ stanza", function () {
-            it("is sent out when converse.js pings a server", function () {
+            afterEach(function () {
+                converse_api.user.logout();
+                test_utils.clearBrowserStorage();
+            });
+
+            it("is sent out when converse.js pings a server", mock.initConverse(function (converse) {
                 var sent_stanza, IQ_id;
                 var sendIQ = converse.connection.sendIQ;
                 spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
@@ -42,7 +45,7 @@
                     "<iq type='get' to='localhost' id='"+IQ_id+"' xmlns='jabber:client'>"+
                         "<ping xmlns='urn:xmpp:ping'/>"+
                     "</iq>");
-            });
+            }));
         });
     });
 }));

+ 9 - 19
spec/profiling.js

@@ -1,26 +1,16 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "underscore",
-        "mock",
-        "test_utils"
-        ], function ($, _, mock, test_utils) {
-            return factory($, _, mock, test_utils);
-        }
-    );
-} (this, function ($, _, mock, test_utils) {
-    var Strophe = converse_api.env.Strophe;
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
+    var _ = converse_api.env._;
     var $iq = converse_api.env.$iq;
 
     describe("Profiling", function() {
-        beforeEach(function() {
+        afterEach(function () {
+            converse_api.user.logout();
             test_utils.clearBrowserStorage();
-            converse.rosterview.model.reset();
-            converse.connection._changeConnectStatus(Strophe.Status.CONNECTED);
         });
 
-        xit("adds hundreds of contacts to the roster", $.proxy(function() {
+        xit("adds hundreds of contacts to the roster", mock.initConverse(function(converse) {
             converse.roster_groups = false;
             expect(this.roster.pluck('jid').length).toBe(0);
             var stanza = $iq({
@@ -41,9 +31,9 @@
             });
             this.roster.onReceivedFromServer(stanza.tree());
             // expect(this.roster.pluck('jid').length).toBe(400);
-        }, converse));
+        }));
 
-        xit("adds hundreds of contacts to the roster, with roster groups", $.proxy(function() {
+        xit("adds hundreds of contacts to the roster, with roster groups", mock.initConverse(function(converse) {
             // converse.show_only_online_users = true;
             converse.roster_groups = true;
             expect(this.roster.pluck('jid').length).toBe(0);
@@ -65,6 +55,6 @@
             });
             this.roster.onReceivedFromServer(stanza.tree());
             //expect(this.roster.pluck('jid').length).toBe(400);
-        }, converse));
+        }));
     });
 }));

+ 1 - 0
spec/protocol.js

@@ -23,6 +23,7 @@
 
             afterEach(function () {
                 converse_api.user.logout();
+                converse_api.listen.not();
                 test_utils.clearBrowserStorage();
             });
 

+ 198 - 260
spec/register.js

@@ -1,59 +1,34 @@
-/*global converse */
 (function (root, factory) {
-    define(["jquery", "mock", "test_utils"], factory);
-} (this, function ($, mock, test_utils) {
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
+    var $ = converse_api.env.jQuery;
     var Strophe = converse_api.env.Strophe;
     var $iq = converse_api.env.$iq;
-    var original_connection = converse.connection;
 
     describe("The Registration Panel", function () {
-        beforeEach(function () {
-            test_utils.closeControlBox();
-            converse._tearDown();
-            converse.initialized_plugins = [];
-        });
-
         afterEach(function () {
-            test_utils.closeControlBox();
-            converse.connection = original_connection;
-            converse._initialize();
+            converse_api.user.logout();
+            converse_api.listen.not();
+            test_utils.clearBrowserStorage();
         });
 
-        it("is not available unless allow_registration=true",  function () {
-            converse.initialize({
-                i18n: window.locales.en,
-                bosh_service_url: 'localhost',
-                allow_registration: true,
-                auto_subscribe: false,
-                animate: false,
-                connection: mock.mock_connection,
-                no_trimming: true,
-                debug: false
-            }, function (converse) {
-                test_utils.closeControlBox();
+        it("is not available unless allow_registration=true",  mock.initConverse(function (converse) {
+            runs(test_utils.openControlBox);
+            waits(50);
+            runs(function () {
                 var cbview = converse.chatboxviews.get('controlbox');
                 expect(cbview.$('#controlbox-tabs li').length).toBe(1);
                 expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
-                cbview = converse.chatboxviews.get('controlbox');
-                expect(cbview.$el.find('#controlbox-tabs li').length).toBe(2);
-                expect(cbview.$('#controlbox-tabs li').first().text().trim()).toBe("Sign in");
-                expect(cbview.$('#controlbox-tabs li').last().text().trim()).toBe("Register");
             });
-        });
-
-        it("can be opened by clicking on the registration tab", function () {
-            converse.initialize({
-                i18n: window.locales.en,
-                bosh_service_url: 'localhost',
-                allow_registration: true,
-                auto_subscribe: false,
-                animate: false,
-                connection: mock.mock_connection,
-                no_trimming: true,
-                debug: false
-            }, function (converse) {
-                test_utils.closeControlBox();
-                var cbview = converse.chatboxviews.get('controlbox');
+        }, { auto_login: false,
+              allow_registration: false,
+            }));
+
+        it("can be opened by clicking on the registration tab", mock.initConverse(function (converse) {
+            var cbview = converse.chatboxviews.get('controlbox');
+            runs(test_utils.openControlBox);
+            waits(50);
+            runs(function () {
                 var $tabs = cbview.$('#controlbox-tabs');
                 var $panels = cbview.$('.controlbox-panes');
                 var $login = $panels.children().first();
@@ -68,221 +43,184 @@
                 expect($registration.is(':visible')).toBe(true);
                 expect(cbview.switchTab).toHaveBeenCalled();
             });
-        });
-
-        it("allows the user to choose an XMPP provider's domain", function () {
-            converse.initialize({
-                i18n: window.locales.en,
-                bosh_service_url: 'localhost',
-                allow_registration: true,
-                auto_subscribe: false,
-                animate: false,
-                connection: mock.mock_connection,
-                no_trimming: true,
-                debug: false
-            }, function (converse) {
-                test_utils.closeControlBox();
-                var cbview = converse.chatboxviews.get('controlbox');
-                var registerview = cbview.registerpanel;
-                spyOn(registerview, 'onProviderChosen').andCallThrough();
-                registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
-                spyOn(converse.connection, 'connect');
-                var $tabs = cbview.$('#controlbox-tabs');
-                $tabs.find('li').last().find('a').click(); // Click the Register tab
-                // Check the form layout
-                var $form = cbview.$('#converse-register');
-                expect($form.find('input').length).toEqual(2);
-                expect($form.find('input').first().attr('name')).toEqual('domain');
-                expect($form.find('input').last().attr('type')).toEqual('submit');
-                // Check that the input[type=domain] input is required
-                $form.find('input[type=submit]').click();
-                expect(registerview.onProviderChosen).toHaveBeenCalled();
-                expect($form.find('input[name=domain]').hasClass('error')).toBeTruthy();
-                // Check that the form is accepted if input[type=domain] has a value
-                $form.find('input[name=domain]').val('conversejs.org');
-                $form.find('input[type=submit]').click();
-                expect(registerview.onProviderChosen).toHaveBeenCalled();
-                expect(converse.connection.connect).toHaveBeenCalled();
-            });
-        });
-
-        it("will render a registration form as received from the XMPP provider", function () {
-            converse.initialize({
-                i18n: window.locales.en,
-                bosh_service_url: 'localhost',
-                allow_registration: true,
-                auto_subscribe: false,
-                animate: false,
-                connection: mock.mock_connection,
-                no_trimming: true,
-                debug: false
-            }, function (converse) {
-                var cbview = converse.chatboxviews.get('controlbox');
-                cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
-                var registerview = converse.chatboxviews.get('controlbox').registerpanel;
-                spyOn(registerview, 'onProviderChosen').andCallThrough();
-                spyOn(registerview, 'getRegistrationFields').andCallThrough();
-                spyOn(registerview, 'onRegistrationFields').andCallThrough();
-                spyOn(registerview, 'renderRegistrationForm').andCallThrough();
-                registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
-                spyOn(converse.connection, 'connect').andCallThrough();
-
-                expect(registerview._registering).toBeFalsy();
-                expect(converse.connection.connected).toBeFalsy();
-                registerview.$('input[name=domain]').val('conversejs.org');
-                registerview.$('input[type=submit]').click();
-                expect(registerview.onProviderChosen).toHaveBeenCalled();
-                expect(registerview._registering).toBeTruthy();
-                expect(converse.connection.connect).toHaveBeenCalled();
-
-                var stanza = new Strophe.Builder("stream:features", {
-                            'xmlns:stream': "http://etherx.jabber.org/streams",
-                            'xmlns': "jabber:client"
-                        })
-                    .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
-                    .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
-                converse.connection._connect_cb(test_utils.createRequest(stanza));
-
-                expect(registerview.getRegistrationFields).toHaveBeenCalled();
-                expect(converse.connection.connected).toBeTruthy();
-
-                stanza = $iq({
-                        'type': 'result',
-                        'id': 'reg1'
-                    }).c('query', {'xmlns': 'jabber:iq:register'})
-                        .c('instructions')
-                            .t('Please choose a username, password and provide your email address').up()
-                        .c('username').up()
-                        .c('password').up()
-                        .c('email');
-                converse.connection._dataRecv(test_utils.createRequest(stanza));
-                expect(registerview.onRegistrationFields).toHaveBeenCalled();
-                expect(registerview.renderRegistrationForm).toHaveBeenCalled();
-                expect(registerview.$('input').length).toBe(5);
-                expect(registerview.$('input[type=submit]').length).toBe(1);
-                expect(registerview.$('input[type=button]').length).toBe(1);
-            });
-        });
-
-        it("will set form_type to legacy and submit it as legacy", function () {
-            converse.initialize({
-                i18n: window.locales.en,
-                bosh_service_url: 'localhost',
-                allow_registration: true,
-                auto_subscribe: false,
-                animate: false,
-                connection: mock.mock_connection,
-                no_trimming: true,
-                debug: false
-            }, function (converse) {
-                test_utils.closeControlBox();
-                var cbview = converse.chatboxviews.get('controlbox');
-                cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
-                var registerview = converse.chatboxviews.get('controlbox').registerpanel;
-                spyOn(registerview, 'onProviderChosen').andCallThrough();
-                spyOn(registerview, 'getRegistrationFields').andCallThrough();
-                spyOn(registerview, 'onRegistrationFields').andCallThrough();
-                spyOn(registerview, 'renderRegistrationForm').andCallThrough();
-                registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
-                spyOn(converse.connection, 'connect').andCallThrough();
-
-                registerview.$('input[name=domain]').val('conversejs.org');
-                registerview.$('input[type=submit]').click();
-
-                var stanza = new Strophe.Builder("stream:features", {
-                            'xmlns:stream': "http://etherx.jabber.org/streams",
-                            'xmlns': "jabber:client"
-                        })
-                    .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
-                    .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
-                converse.connection._connect_cb(test_utils.createRequest(stanza));
-                stanza = $iq({
-                        'type': 'result',
-                        'id': 'reg1'
-                    }).c('query', {'xmlns': 'jabber:iq:register'})
-                        .c('instructions')
-                            .t('Please choose a username, password and provide your email address').up()
-                        .c('username').up()
-                        .c('password').up()
-                        .c('email');
-                converse.connection._dataRecv(test_utils.createRequest(stanza));
-                expect(registerview.form_type).toBe('legacy');
-
-                registerview.$('input[name=username]').val('testusername');
-                registerview.$('input[name=password]').val('testpassword');
-                registerview.$('input[name=email]').val('test@email.local');
-
-                spyOn(converse.connection, 'send');
-
-                registerview.$('input[type=submit]').click();
-
-                expect(converse.connection.send).toHaveBeenCalled();
-                var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
-                expect($stanza.children('query').children().length).toBe(3);
-                expect($stanza.children('query').children()[0].tagName).toBe('username');
-            });
-        });
-
-        it("will set form_type to xform and submit it as xform", function () {
-            converse.initialize({
-                i18n: window.locales.en,
-                bosh_service_url: 'localhost',
-                allow_registration: true,
-                auto_subscribe: false,
-                animate: false,
-                connection: mock.mock_connection,
-                no_trimming: true,
-                debug: false
-            }, function (converse) {
-                test_utils.closeControlBox();
-                var cbview = converse.chatboxviews.get('controlbox');
-                cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
-                var registerview = converse.chatboxviews.get('controlbox').registerpanel;
-                spyOn(registerview, 'onProviderChosen').andCallThrough();
-                spyOn(registerview, 'getRegistrationFields').andCallThrough();
-                spyOn(registerview, 'onRegistrationFields').andCallThrough();
-                spyOn(registerview, 'renderRegistrationForm').andCallThrough();
-                registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
-                spyOn(converse.connection, 'connect').andCallThrough();
-
-                registerview.$('input[name=domain]').val('conversejs.org');
-                registerview.$('input[type=submit]').click();
-
-                var stanza = new Strophe.Builder("stream:features", {
-                            'xmlns:stream': "http://etherx.jabber.org/streams",
-                            'xmlns': "jabber:client"
-                        })
-                    .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
-                    .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
-                converse.connection._connect_cb(test_utils.createRequest(stanza));
-                stanza = $iq({
-                        'type': 'result',
-                        'id': 'reg1'
-                    }).c('query', {'xmlns': 'jabber:iq:register'})
-                        .c('instructions')
-                            .t('Using xform data').up()
-                        .c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
-                            .c('instructions').t('xform instructions').up()
-                            .c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
-                            .c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
-                            .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
-                converse.connection._dataRecv(test_utils.createRequest(stanza));
-                expect(registerview.form_type).toBe('xform');
-
-                registerview.$('input[name=username]').val('testusername');
-                registerview.$('input[name=password]').val('testpassword');
-                registerview.$('input[name=email]').val('test@email.local');
-
-                spyOn(converse.connection, 'send');
-
-                registerview.$('input[type=submit]').click();
-
-                expect(converse.connection.send).toHaveBeenCalled();
-                var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
-                expect($stanza.children('query').children().length).toBe(1);
-                expect($stanza.children('query').children().children().length).toBe(3);
-                expect($stanza.children('query').children().children()[0].tagName).toBe('field');
-            });
-        });
+        }, { auto_login: false,
+              allow_registration: true,
+            }));
+
+        it("allows the user to choose an XMPP provider's domain", mock.initConverse(function (converse) {
+            var cbview = converse.chatboxviews.get('controlbox');
+            var registerview = cbview.registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(converse.connection, 'connect');
+            var $tabs = cbview.$('#controlbox-tabs');
+            $tabs.find('li').last().find('a').click(); // Click the Register tab
+            // Check the form layout
+            var $form = cbview.$('#converse-register');
+            expect($form.find('input').length).toEqual(2);
+            expect($form.find('input').first().attr('name')).toEqual('domain');
+            expect($form.find('input').last().attr('type')).toEqual('submit');
+            // Check that the input[type=domain] input is required
+            $form.find('input[type=submit]').click();
+            expect(registerview.onProviderChosen).toHaveBeenCalled();
+            expect($form.find('input[name=domain]').hasClass('error')).toBeTruthy();
+            // Check that the form is accepted if input[type=domain] has a value
+            $form.find('input[name=domain]').val('conversejs.org');
+            $form.find('input[type=submit]').click();
+            expect(registerview.onProviderChosen).toHaveBeenCalled();
+            expect(converse.connection.connect).toHaveBeenCalled();
+        }, { auto_login: false,
+              allow_registration: true,
+            }));
+
+        it("will render a registration form as received from the XMPP provider", mock.initConverse(function (converse) {
+            var cbview = converse.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = converse.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(converse.connection, 'connect').andCallThrough();
+
+            expect(registerview._registering).toBeFalsy();
+            expect(converse.connection.connected).toBeFalsy();
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+            expect(registerview.onProviderChosen).toHaveBeenCalled();
+            expect(registerview._registering).toBeTruthy();
+            expect(converse.connection.connect).toHaveBeenCalled();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            converse.connection._connect_cb(test_utils.createRequest(stanza));
+
+            expect(registerview.getRegistrationFields).toHaveBeenCalled();
+            expect(converse.connection.connected).toBeTruthy();
+
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Please choose a username, password and provide your email address').up()
+                    .c('username').up()
+                    .c('password').up()
+                    .c('email');
+            converse.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.onRegistrationFields).toHaveBeenCalled();
+            expect(registerview.renderRegistrationForm).toHaveBeenCalled();
+            expect(registerview.$('input').length).toBe(5);
+            expect(registerview.$('input[type=submit]').length).toBe(1);
+            expect(registerview.$('input[type=button]').length).toBe(1);
+        }, { auto_login: false,
+              allow_registration: true,
+            }));
+
+        it("will set form_type to legacy and submit it as legacy", mock.initConverse(function (converse) {
+            var cbview = converse.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = converse.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(converse.connection, 'connect').andCallThrough();
+
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            converse.connection._connect_cb(test_utils.createRequest(stanza));
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Please choose a username, password and provide your email address').up()
+                    .c('username').up()
+                    .c('password').up()
+                    .c('email');
+            converse.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.form_type).toBe('legacy');
+
+            registerview.$('input[name=username]').val('testusername');
+            registerview.$('input[name=password]').val('testpassword');
+            registerview.$('input[name=email]').val('test@email.local');
+
+            spyOn(converse.connection, 'send');
+
+            registerview.$('input[type=submit]').click();
+
+            expect(converse.connection.send).toHaveBeenCalled();
+            var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
+            expect($stanza.children('query').children().length).toBe(3);
+            expect($stanza.children('query').children()[0].tagName).toBe('username');
+        }, { auto_login: false,
+              allow_registration: true,
+            }));
+
+        it("will set form_type to xform and submit it as xform", mock.initConverse(function (converse) {
+            var cbview = converse.chatboxviews.get('controlbox');
+            cbview.$('#controlbox-tabs').find('li').last().find('a').click(); // Click the Register tab
+            var registerview = converse.chatboxviews.get('controlbox').registerpanel;
+            spyOn(registerview, 'onProviderChosen').andCallThrough();
+            spyOn(registerview, 'getRegistrationFields').andCallThrough();
+            spyOn(registerview, 'onRegistrationFields').andCallThrough();
+            spyOn(registerview, 'renderRegistrationForm').andCallThrough();
+            registerview.delegateEvents();  // We need to rebind all events otherwise our spy won't be called
+            spyOn(converse.connection, 'connect').andCallThrough();
+
+            registerview.$('input[name=domain]').val('conversejs.org');
+            registerview.$('input[type=submit]').click();
+
+            var stanza = new Strophe.Builder("stream:features", {
+                        'xmlns:stream': "http://etherx.jabber.org/streams",
+                        'xmlns': "jabber:client"
+                    })
+                .c('register',  {xmlns: "http://jabber.org/features/iq-register"}).up()
+                .c('mechanisms', {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"});
+            converse.connection._connect_cb(test_utils.createRequest(stanza));
+            stanza = $iq({
+                    'type': 'result',
+                    'id': 'reg1'
+                }).c('query', {'xmlns': 'jabber:iq:register'})
+                    .c('instructions')
+                        .t('Using xform data').up()
+                    .c('x', { 'xmlns': 'jabber:x:data', 'type': 'form' })
+                        .c('instructions').t('xform instructions').up()
+                        .c('field', {'type': 'text-single', 'var': 'username'}).c('required').up().up()
+                        .c('field', {'type': 'text-private', 'var': 'password'}).c('required').up().up()
+                        .c('field', {'type': 'text-single', 'var': 'email'}).c('required').up().up();
+            converse.connection._dataRecv(test_utils.createRequest(stanza));
+            expect(registerview.form_type).toBe('xform');
+
+            registerview.$('input[name=username]').val('testusername');
+            registerview.$('input[name=password]').val('testpassword');
+            registerview.$('input[name=email]').val('test@email.local');
+
+            spyOn(converse.connection, 'send');
+
+            registerview.$('input[type=submit]').click();
+
+            expect(converse.connection.send).toHaveBeenCalled();
+            var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
+            expect($stanza.children('query').children().length).toBe(1);
+            expect($stanza.children('query').children().children().length).toBe(3);
+            expect($stanza.children('query').children().children()[0].tagName).toBe('field');
+        }, { auto_login: false,
+              allow_registration: true,
+            }));
     });
 }));

+ 16 - 21
spec/xmppstatus.js

@@ -1,30 +1,25 @@
-/*global converse */
 (function (root, factory) {
-    define([
-        "jquery",
-        "mock",
-        "test_utils"
-        ], function ($, mock, test_utils) {
-            return factory($, mock, test_utils);
-        }
-    );
-} (this, function ($, mock, test_utils) {
-    return describe("The XMPPStatus model", $.proxy(function(mock, test_utils) {
-        beforeEach($.proxy(function () {
-            window.localStorage.clear();
-            window.sessionStorage.clear();
-        }, converse));
-        it("won't send <show>online when setting a custom status message", $.proxy(function () {
-            this.xmppstatus.save({'status': 'online'});
-            spyOn(this.xmppstatus, 'setStatusMessage').andCallThrough();
+    define(["mock", "test_utils"], factory);
+} (this, function (mock, test_utils) {
+    var $ = converse_api.env.jQuery;
+
+    return describe("The XMPPStatus model", function() {
+        afterEach(function () {
+            converse_api.user.logout();
+            test_utils.clearBrowserStorage();
+        });
+
+        it("won't send <show>online when setting a custom status message", mock.initConverse(function (converse) {
+            converse.xmppstatus.save({'status': 'online'});
+            spyOn(converse.xmppstatus, 'setStatusMessage').andCallThrough();
             spyOn(converse.connection, 'send');
-            this.xmppstatus.setStatusMessage("I'm also happy!");
+            converse.xmppstatus.setStatusMessage("I'm also happy!");
             runs (function () {
                 expect(converse.connection.send).toHaveBeenCalled();
                 var $stanza = $(converse.connection.send.argsForCall[0][0].tree());
                 expect($stanza.children().length).toBe(1);
                 expect($stanza.children('show').length).toBe(0);
             });
-        }, converse));
-    }, converse, mock, test_utils));
+        }));
+    });
 }));

+ 2 - 0
src/converse-mam.js

@@ -164,11 +164,13 @@
                     callback = options;
                     errback = callback;
                 }
+                /*
                 if (!converse.features.findWhere({'var': Strophe.NS.MAM})) {
                     converse.log('This server does not support XEP-0313, Message Archive Management');
                     errback(null);
                     return;
                 }
+                */
                 var queryid = converse.connection.getUniqueId();
                 var attrs = {'type':'set'};
                 if (typeof options !== "undefined" && options.groupchat) {

+ 8 - 0
tests.html

@@ -10,6 +10,14 @@
     <link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
     <script src="config.js"></script>
     <script data-main="tests/main" src="node_modules/requirejs/require.js"></script>
+    <style>
+        body {
+            background-color: lightgoldenrodyellow;
+        }
+        h2 { 
+            color: darkgray;
+        }
+    </style>
 </head>
 
 <body>

+ 1 - 5
tests/main.js

@@ -50,13 +50,10 @@ require([
             //"spec/transcripts",
             "spec/utils",
             "spec/converse",
-            /*
             "spec/bookmarks",
             "spec/headline",
             "spec/disco",
-            */
             "spec/protocol",
-            /*
             "spec/mam",
             "spec/otr",
             "spec/eventemitter",
@@ -68,8 +65,7 @@ require([
             "spec/profiling",
             "spec/ping",
             "spec/register",
-            "spec/xmppstatus",
-            */
+            "spec/xmppstatus"
         ], function () {
             // Jasmine stuff
             var jasmineEnv = jasmine.getEnv();

+ 4 - 5
tests/mock.js

@@ -75,9 +75,9 @@
         };
     }();
 
-    mock.initConverse = function (func) {
+    mock.initConverse = function (func, settings) {
         return function () {
-            var converse = converse_api.initialize({
+            var converse = converse_api.initialize(_.extend({
                 i18n: window.locales.en,
                 auto_subscribe: false,
                 bosh_service_url: 'localhost',
@@ -86,9 +86,8 @@
                 no_trimming: true,
                 auto_login: true,
                 jid: 'dummy@localhost',
-                password: 'secret',
-                debug: true
-            });
+                password: 'secret'
+            }, settings || {}));
             converse.ChatBoxViews.prototype.trimChat = function () {};
             return func(converse);
         };

+ 13 - 11
tests/utils.js

@@ -79,14 +79,14 @@
         $tabs.find('li').first().find('a').click();
     };
 
-    utils.openRoomsPanel = function () {
+    utils.openRoomsPanel = function (converse) {
         utils.openControlBox();
         var cbview = converse.chatboxviews.get('controlbox');
         var $tabs = cbview.$el.find('#controlbox-tabs');
         $tabs.find('li').last().find('a').click();
     };
 
-    utils.openChatBoxes = function (amount) {
+    utils.openChatBoxes = function (converse, amount) {
         var i = 0, jid, views = [];
         for (i; i<amount; i++) {
             jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
@@ -99,25 +99,25 @@
         return converse.roster.get(jid).trigger("open");
     };
 
-    utils.openChatRoom = function (room, server, nick) {
+    utils.openChatRoom = function (converse, room, server, nick) {
         // Open a new chatroom
-        this.openControlBox();
-        this.openRoomsPanel();
+        this.openControlBox(converse);
+        this.openRoomsPanel(converse);
         var roomspanel = converse.chatboxviews.get('controlbox').roomspanel;
         roomspanel.$el.find('input.new-chatroom-name').val(room);
         roomspanel.$el.find('input.new-chatroom-nick').val(nick);
         roomspanel.$el.find('input.new-chatroom-server').val(server);
         roomspanel.$el.find('form').submit();
-        this.closeControlBox();
+        this.closeControlBox(converse);
     };
 
-    utils.openAndEnterChatRoom = function (room, server, nick) {
+    utils.openAndEnterChatRoom = function (converse, room, server, nick) {
         var IQ_id, sendIQ = converse.connection.sendIQ;
         spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
             IQ_id = sendIQ.bind(this)(iq, callback, errback);
         });
 
-        utils.openChatRoom(room, server);
+        utils.openChatRoom(converse, room, server);
         var view = converse.chatboxviews.get(room+'@'+server);
 
         // The XMPP server returns the reserved nick for this user.
@@ -160,7 +160,7 @@
         return this;
     };
 
-    utils.clearChatBoxMessages = function (jid) {
+    utils.clearChatBoxMessages = function (converse, jid) {
         var view = converse.chatboxviews.get(jid);
         view.$el.find('.chat-content').empty();
         view.model.messages.reset();
@@ -190,7 +190,9 @@
             requesting = false;
             ask = null;
         } else if (type === 'all') {
-            this.createContacts('current').createContacts('requesting').createContacts('pending');
+            this.createContacts(converse, 'current')
+                .createContacts(converse, 'requesting')
+                .createContacts(converse, 'pending');
             return this;
         } else {
             throw "Need to specify the type of contact to create";
@@ -214,7 +216,7 @@
         return this;
     };
 
-    utils.createGroupedContacts = function () {
+    utils.createGroupedContacts = function (converse) {
         /* Create grouped contacts
          */
         var i=0, j=0;

Some files were not shown because too many files changed in this diff