(function (root, factory) { define([ "converse" ], function (converse) { return factory(converse); } ); } (this, function (converse) { return describe("Converse.js", $.proxy(function() { // Names from http://www.fakenamegenerator.com/ var req_names = [ 'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer' ]; var pend_names = [ 'Suleyman van Beusichem', 'Nicole Diederich', 'Nanja van Yperen' ]; var cur_names = [ 'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez', 'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel', 'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers' ]; var num_contacts = req_names.length + pend_names.length + cur_names.length; mock_connection = { 'muc': { 'listRooms': function () {}, 'join': function () {} }, 'jid': 'dummy@localhost', 'addHandler': function (handler, ns, name, type, id, from, options) { return function () {}; }, 'send': function () {}, 'roster': { 'add': function () {}, 'authorize': function () {}, 'unauthorize': function () {}, 'get': function () {}, 'subscribe': function () {}, 'registerCallback': function () {} }, 'vcard': { 'get': function (callback, jid) { var name = jid.split('@')[0].replace('.', ' ').split(' '); var firstname = name[0].charAt(0).toUpperCase()+name[0].slice(1); var lastname = name[1].charAt(0).toUpperCase()+name[1].slice(1); var fullname = firstname+' '+lastname; var vcard = $iq().c('vCard').c('FN').t(fullname); callback(vcard.tree()); } } }; // Clear localStorage window.localStorage.clear(); this.initialize({ prebind: false, xhr_user_search: false, auto_subscribe: false, animate: false }); this.onConnected(mock_connection); // Variable declarations for specs var open_controlbox; describe("The Control Box", $.proxy(function () { it("is not shown by default", $.proxy(function () { expect(this.rosterview.$el.is(':visible')).toEqual(false); }, converse)); open_controlbox = $.proxy(function () { // This spec will only pass if the controlbox is not currently // open yet. expect($("div#controlbox").is(':visible')).toBe(false); spyOn(this, 'toggleControlBox').andCallThrough(); $('.toggle-online-users').click(); expect(this.toggleControlBox).toHaveBeenCalled(); expect($("div#controlbox").is(':visible')).toBe(true); }, converse); it("can be opened by clicking a DOM element with class 'toggle-online-users'", open_controlbox); describe("The Status Widget", $.proxy(function () { it("can be used to set the current user's chat status", $.proxy(function () { var view = this.xmppstatusview; spyOn(view, 'toggleOptions').andCallThrough(); spyOn(view, 'setStatus').andCallThrough(); view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called runs(function () { view.$el.find('a.choose-xmpp-status').click(); expect(view.toggleOptions).toHaveBeenCalled(); expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(false); }); waits(250); runs(function () { spyOn(view, 'updateStatusUI').andCallThrough(); view.initialize(); // Rebind events for spy view.$el.find('.dropdown dd ul li a').first().click(); expect(view.setStatus).toHaveBeenCalled(); }); waits(250); runs($.proxy(function () { expect(view.updateStatusUI).toHaveBeenCalled(); expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true); expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe('I am online'); }, converse)); }, converse)); it("can be used to set a custom status message", $.proxy(function () { var view = this.xmppstatusview; spyOn(view, 'setStatusMessage').andCallThrough(); spyOn(view, 'renderStatusChangeForm').andCallThrough(); view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called view.$el.find('a.change-xmpp-status-message').click(); expect(view.renderStatusChangeForm).toHaveBeenCalled(); // The async testing here is used only to provide time for // visual feedback var msg = 'I am happy'; runs (function () { view.$el.find('form input.custom-xmpp-status').val(msg); }); waits(250); runs (function () { view.$el.find('form#set-custom-xmpp-status').submit(); expect(view.setStatusMessage).toHaveBeenCalled(); expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true); expect(view.$el.find('a.choose-xmpp-status span.value').text()).toBe(msg); }); }, converse)); }, converse)); }, converse)); describe("The Contacts Roster", $.proxy(function () { describe("Pending Contacts", $.proxy(function () { it("do not have a heading if there aren't any", $.proxy(function () { expect(this.rosterview.$el.find('dt#pending-xmpp-contacts').css('display')).toEqual('none'); }, converse)); it("can be added to the roster and they will be sorted alphabetically", $.proxy(function () { var i, t, is_last; spyOn(this.rosterview, 'render').andCallThrough(); for (i=0; i