diff --git a/spec/bookmarks.js b/spec/bookmarks.js index 9fb7e58d5..70fbc24c4 100644 --- a/spec/bookmarks.js +++ b/spec/bookmarks.js @@ -17,7 +17,9 @@ describe("A chat room", function () { - it("can be bookmarked", mock.initConverse(function (_converse) { + it("can be bookmarked", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, function (done, _converse) { + var sent_stanza, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -124,9 +126,12 @@ _converse.connection._dataRecv(test_utils.createRequest(stanza)); // We ignore this IQ stanza... (unless it's an error stanza), so // nothing to test for here. + done(); })); - it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(function (_converse) { + it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, function (done, _converse) { + var jid = 'lounge@localhost'; _converse.bookmarks.create({ 'jid': jid, @@ -144,11 +149,14 @@ 'nick': ' Othello' }); expect(_.isUndefined(_converse.chatboxviews.get(jid))).toBeFalsy(); + done(); })); describe("when bookmarked", function () { - it("displays that it's bookmarked through its bookmark icon", mock.initConverse(function (_converse) { + it("displays that it's bookmarked through its bookmark icon", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, function (done, _converse) { + test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); var view = _converse.chatboxviews.get('lounge@localhost'); var $bookmark_icon = view.$('.icon-pushpin'); @@ -157,9 +165,12 @@ expect($bookmark_icon.hasClass('button-on')).toBeTruthy(); view.model.set('bookmarked', false); expect($bookmark_icon.hasClass('button-on')).toBeFalsy(); + done(); })); - it("can be unbookmarked", mock.initConverse(function (_converse) { + it("can be unbookmarked", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, function (done, _converse) { + var sent_stanza, IQ_id; var sendIQ = _converse.connection.sendIQ; test_utils.openChatRoom(_converse, 'theplay', 'conference.shakespeare.lit', 'JC'); @@ -216,6 +227,7 @@ ""+ "" ); + done(); })); }); @@ -293,8 +305,9 @@ */ })); - it("can be retrieved from the XMPP server", - mock.initConverseWithConnectionSpies(['send'], function (_converse) { + it("can be retrieved from the XMPP server", mock.initConverseWithPromises( + ['send'], ['rosterGroupsFetched'], {}, function (done, _converse) { + /* Client requests all items * ------------------------- * @@ -366,11 +379,14 @@ 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); + done(); })); describe("The rooms panel", function () { - it("shows a list of bookmarks", mock.initConverseWithConnectionSpies(['send'], function (_converse) { + it("shows a list of bookmarks", mock.initConverseWithPromises( + ['send'], ['rosterGroupsFetched'], {}, function (done, _converse) { + var IQ_id; expect(_.filter(_converse.connection.send.calls.all(), function (call) { var stanza = call.args[0]; @@ -415,10 +431,12 @@ }).c('nick').t('JC').up().up(); _converse.connection._dataRecv(test_utils.createRequest(stanza)); expect($('#chatrooms dl.bookmarks dd').length).toBe(3); + done(); })); - it("remembers the toggle state of the bookmarks list", - mock.initConverseWithConnectionSpies(['send'], function (_converse) { + it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises( + ['send'], ['rosterGroupsFetched'], {}, function (done, _converse) { + var IQ_id; expect(_.filter(_converse.connection.send.calls.all(), function (call) { var stanza = call.args[0]; @@ -462,15 +480,19 @@ $('#chatrooms .bookmarks-toggle').click(); expect($('#chatrooms dl.bookmarks dd:visible').length).toBe(1); expect(_converse.bookmarksview.list_model.get('toggle-state')).toBe(_converse.OPENED); + done(); })); }); }); describe("When hide_open_bookmarks is true and a bookmarked room is opened", function () { - it("can be closed", mock.initConverse({ hide_open_bookmarks: true }, function (_converse) { - test_utils.openControlBox().openRoomsPanel(_converse); + it("can be closed", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], + { hide_open_bookmarks: true }, + function (done, _converse) { + test_utils.openControlBox().openRoomsPanel(_converse); // XXX Create bookmarks view here, otherwise we need to mock stanza // traffic for it to get created. _converse.bookmarksview = new _converse.BookmarksView( @@ -502,6 +524,7 @@ view.close(); room_els = _converse.bookmarksview.el.querySelectorAll(".open-room"); expect(room_els.length).toBe(1); + done(); })); }); })); diff --git a/spec/chatbox.js b/spec/chatbox.js index 4921ca692..987ef5ffc 100644 --- a/spec/chatbox.js +++ b/spec/chatbox.js @@ -1,15 +1,15 @@ (function (root, factory) { define([ + "jquery.noconflict", "jasmine", "utils", "converse-core", "mock", "test-utils" ], factory); -} (this, function (jasmine, utils, converse, mock, test_utils) { +} (this, function ($, jasmine, utils, converse, mock, test_utils) { "use strict"; var _ = converse.env._; - var $ = converse.env.jQuery; var $msg = converse.env.$msg; var Strophe = converse.env.Strophe; var moment = converse.env.moment; @@ -17,7 +17,11 @@ return describe("Chatboxes", function() { describe("A Chatbox", function () { - it("supports the /me command", mock.initConverse(function (_converse) { + it("supports the /me command", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -41,9 +45,14 @@ test_utils.sendMessage(view, message); expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy(); expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well'); + done(); })); - it("is created when you click on a roster item", mock.initConverse(function (_converse) { + it("is created when you click on a roster item", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -68,9 +77,14 @@ expect($("#conversejs .chatbox").length).toBe(i+2); expect($("#conversejs .chatbox")[1].id).toBe(chatboxview.model.get('box_id')); } + done(); })); - it("can be trimmed to conserve space", mock.initConverseWithAsync(function (done, _converse) { + it("can be trimmed to conserve space", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -121,9 +135,14 @@ expect(_converse.chatboxviews.trimChats).toHaveBeenCalled(); done(); }); + done(); })); - it("can be opened in minimized mode initially", mock.initConverse(function(_converse) { + it("can be opened in minimized mode initially", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -137,39 +156,44 @@ var minimized_chat = _converse.minimized_chats.get(sender_jid); expect(minimized_chat).toBeTruthy(); expect(minimized_chat.$el.is(':visible')).toBeTruthy(); + done(); })); - it("is focused if its already open and you click on its corresponding roster item", mock.initConverseWithAsync(function (done, _converse) { + + it("is focused if its already open and you click on its corresponding roster item", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); + _converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced. test_utils.openControlBox(); test_utils.openContactsPanel(_converse); var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost'; - var $el, jid, chatboxview, chatbox; + var $el, jid, chatbox; // openControlBox was called earlier, so the controlbox is // visible, but no other chat boxes have been created. expect(_converse.chatboxes.length).toEqual(1); + + spyOn(_converse.ChatBoxView.prototype, 'focus'); chatbox = test_utils.openChatBoxFor(_converse, contact_jid); - chatboxview = _converse.chatboxviews.get(contact_jid); - spyOn(chatboxview, 'focus'); - // Test that they can be trimmed - _converse.rosterview.update(); // XXX: Hack to make sure $roster element is attaced. - test_utils.waitUntil(function () { - return _converse.rosterview.$el.find('dt').length; - }, 300) - .then(function () { - $el = _converse.rosterview.$el.find('a.open-chat:contains("'+chatbox.get('fullname')+'")'); - jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost'; - $el.click(); - setTimeout(function () { - expect(_converse.chatboxes.length).toEqual(2); - expect(chatboxview.focus).toHaveBeenCalled(); - done(); - }, 500); - }); + + $el = _converse.rosterview.$el.find('a.open-chat:contains("'+chatbox.get('fullname')+'")'); + jid = $el.text().replace(/ /g,'.').toLowerCase() + '@localhost'; + $el.click(); + expect(_converse.chatboxes.length).toEqual(2); + var chatboxview = _converse.chatboxviews.get(contact_jid); + expect(chatboxview.focus).toHaveBeenCalled(); + done(); })); - it("can be saved to, and retrieved from, browserStorage", mock.initConverse(function (_converse) { + + it("can be saved to, and retrieved from, browserStorage", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -198,9 +222,14 @@ expect(_.isEqual(new_attrs, old_attrs)).toEqual(true); } _converse.rosterview.render(); + done(); })); - it("can be closed by clicking a DOM element with class 'close-chatbox-button'", mock.initConverseWithAsync(function (done, _converse) { + it("can be closed by clicking a DOM element with class 'close-chatbox-button'", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -233,7 +262,11 @@ }); })); - it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", mock.initConverseWithAsync(function (done, _converse) { + it("can be minimized by clicking a DOM element with class 'toggle-chatbox-button'", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var chatview; test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); @@ -277,7 +310,11 @@ }); })); - it("will be removed from browserStorage when closed", mock.initConverseWithAsync(function (done, _converse) { + it("will be removed from browserStorage when closed", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -318,7 +355,11 @@ describe("A chat toolbar", function () { - it("can be found on each chat box", mock.initConverse(function (_converse) { + it("can be found on each chat box", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -332,9 +373,14 @@ var $toolbar = view.$el.find('ul.chat-toolbar'); expect($toolbar.length).toBe(1); expect($toolbar.children('li').length).toBe(3); + done(); })); - it("contains a button for inserting emoticons", mock.initConverseWithAsync(function (done, _converse) { + it("contains a button for inserting emoticons", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -392,7 +438,11 @@ }); })); - it("contains a button for starting an encrypted chat session", mock.initConverseWithAsync(function (done, _converse) { + it("contains a button for starting an encrypted chat session", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -421,7 +471,11 @@ }); })); - it("can contain a button for starting a call", mock.initConverse(function (_converse) { + it("can contain a button for starting a call", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -448,9 +502,14 @@ expect(callButton.length).toBe(1); callButton.click(); expect(_converse.emit).toHaveBeenCalledWith('callButtonClicked', jasmine.any(Object)); + done(); })); - it("can contain a button for clearing messages", mock.initConverse(function (_converse) { + it("can contain a button for clearing messages", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -479,13 +538,18 @@ view.delegateEvents(); // We need to rebind all events otherwise our spy won't be called clearButton.click(); expect(view.clearMessages).toHaveBeenCalled(); + done(); })); }); describe("A Chat Message", function () { describe("when received from someone else", function () { - it("can be received which will open a chatbox and be displayed inside it", mock.initConverseWithAsync(function (done, _converse) { + it("can be received which will open a chatbox and be displayed inside it", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -534,7 +598,11 @@ })); describe("who is not on the roster", function () { - it("will open a chatbox and be displayed inside it if allow_non_roster_messaging is true", mock.initConverse(function (_converse) { + it("will open a chatbox and be displayed inside it if allow_non_roster_messaging is true", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.allow_non_roster_messaging = false; spyOn(_converse, 'emit'); @@ -581,12 +649,17 @@ expect(msg_txt).toEqual(message); var sender_txt = $chat_content.find('span.chat-msg-them').text(); expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy(); + done(); })); }); describe("and for which then an error message is received from the server", function () { - it("will have the error message displayed after itself", mock.initConverse(function (_converse) { + it("will have the error message displayed after itself", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -682,10 +755,16 @@ .t('Server-to-server connection failed: Connecting failed: connection timeout'); _converse.connection._dataRecv(test_utils.createRequest(stanza)); expect($chat_content.find('.chat-error').length).toEqual(1); + done(); })); + }); - it("will cause the chat area to be scrolled down only if it was at the bottom already", mock.initConverseWithAsync(function (done, _converse) { + it("will cause the chat area to be scrolled down only if it was at the bottom already", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -750,7 +829,11 @@ })); it("is ignored if it's intended for a different resource and filter_by_resource is set to true", - mock.initConverseWithAsync(function (done, _converse) { + + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -800,7 +883,11 @@ })); }); - it("is ignored if it's a malformed headline message", mock.initConverse(function (_converse) { + it("is ignored if it's a malformed headline message", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -829,9 +916,15 @@ _converse.log.restore(); _converse.chatboxes.getChatBox.restore(); utils.isHeadlineMessage.restore(); + done(); })); - it("can be a carbon message, as defined in XEP-0280", mock.initConverse(function (_converse) { + + it("can be a carbon message, as defined in XEP-0280", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -874,9 +967,14 @@ expect(msg_txt).toEqual(msgtext); var sender_txt = $chat_content.find('span.chat-msg-them').text(); expect(sender_txt.match(/^[0-9][0-9]:[0-9][0-9] /)).toBeTruthy(); + done(); })); - it("can be a carbon message that this user sent from a different client, as defined in XEP-0280", mock.initConverse(function (_converse) { + it("can be a carbon message that this user sent from a different client, as defined in XEP-0280", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -917,9 +1015,14 @@ var $chat_content = chatboxview.$el.find('.chat-content'); var msg_txt = $chat_content.find('.chat-message').find('.chat-msg-content').text(); expect(msg_txt).toEqual(msgtext); + done(); })); - it("will be discarded if it's a malicious message meant to look like a carbon copy", mock.initConverse(function (_converse) { + it("will be discarded if it's a malicious message meant to look like a carbon copy", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -960,10 +1063,15 @@ // Check that the chatbox for the malicous user is not created chatbox = _converse.chatboxes.get(sender_jid); expect(chatbox).not.toBeDefined(); + done(); })); it("received for a minimized chat box will increment a counter on its header", - mock.initConverseWithAsync(function (done, _converse) { + + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1020,7 +1128,11 @@ })); it("will indicate when it has a time difference of more than a day between it and its predecessor", - mock.initConverseWithAsync(function (done, _converse) { + + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1105,7 +1217,11 @@ }); })); - it("can be sent from a chatbox, and will appear inside it", mock.initConverse(function (_converse) { + it("can be sent from a chatbox, and will appear inside it", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1122,9 +1238,14 @@ expect(view.model.messages.length, 2); expect(_converse.emit.calls.mostRecent().args, ['messageSend', message]); expect(view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content').text()).toEqual(message); + done(); })); - it("is sanitized to prevent Javascript injection attacks", mock.initConverse(function (_converse) { + it("is sanitized to prevent Javascript injection attacks", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1139,9 +1260,14 @@ var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content'); expect(msg.text()).toEqual(message); expect(msg.html()).toEqual('<p>This message contains <em>some</em> <b>markup</b></p>'); + done(); })); - it("should display emoticons correctly", mock.initConverse(function (_converse) { + it("should display emoticons correctly", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1167,9 +1293,14 @@ var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content'); expect(msg.html()).toEqual(emoticons[i]); } + done(); })); - it("can contain hyperlinks, which will be clickable", mock.initConverse(function (_converse) { + it("can contain hyperlinks, which will be clickable", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1184,9 +1315,14 @@ var msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content'); expect(msg.text()).toEqual(message); expect(msg.html()).toEqual('This message contains a hyperlink: www.opkode.com'); + done(); })); - it("will have properly escaped URLs", mock.initConverse(function (_converse) { + it("will have properly escaped URLs", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1226,9 +1362,15 @@ msg = view.$el.find('.chat-content').find('.chat-message').last().find('.chat-msg-content'); expect(msg.text()).toEqual(message); expect(msg.html()).toEqual('https://en.wikipedia.org/wiki/Ender%27s_Game'); + done(); })); - it("will render images from their URLs", mock.initConverseWithAsync(function (done, _converse) { + + it("will render images from their URLs", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + if (/PhantomJS/.test(window.navigator.userAgent)) { // Doesn't work when running tests in PhantomJS, since // the page is loaded via file:/// @@ -1268,7 +1410,11 @@ }); })); - it("will render the message time as configured", mock.initConverse(function (_converse) { + it("will render the message time as configured", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); _converse.time_format = 'hh:mm'; @@ -1286,12 +1432,17 @@ var msg_time_rendered = msg_time_author.split(" ",1); var msg_time = moment(msg_object.get('time')).format(_converse.time_format); expect(msg_time_rendered[0]).toBe(msg_time); + done(); })); }); describe("A Chat Status Notification", function () { - it("does not open automatically if a chat state notification is received", mock.initConverse(function (_converse) { + it("does not open automatically if a chat state notification is received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1307,11 +1458,16 @@ }).c('composing', {'xmlns': Strophe.NS.CHATSTATES}).tree(); _converse.chatboxes.onMessage(msg); expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object)); + done(); })); describe("An active notification", function () { - it("is sent when the user opens a chat box", mock.initConverseWithAsync(function (done, _converse) { + it("is sent when the user opens a chat box", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1334,7 +1490,11 @@ }); })); - it("is sent when the user maximizes a minimized a chat box", mock.initConverseWithAsync(function (done, _converse) { + it("is sent when the user maximizes a minimized a chat box", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1367,7 +1527,11 @@ describe("A composing notification", function () { - it("is sent as soon as the user starts typing a message which is not a command", mock.initConverseWithAsync(function (done, _converse) { + it("is sent as soon as the user starts typing a message which is not a command", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1404,7 +1568,11 @@ }); })); - it("will be shown if received", mock.initConverse(function (_converse) { + it("will be shown if received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1427,9 +1595,14 @@ // Check that the notification appears inside the chatbox in the DOM var $events = chatboxview.$el.find('.chat-event'); expect($events.text()).toEqual(mock.cur_names[1] + ' is typing'); + done(); })); - it("can be a composing carbon message that this user sent from a different client", mock.initConverse(function (_converse) { + it("can be a composing carbon message that this user sent from a different client", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); // Send a message from a different resource @@ -1464,12 +1637,17 @@ var $chat_content = chatboxview.$el.find('.chat-content'); var status_text = $chat_content.find('.chat-info.chat-event').text(); expect(status_text).toBe('Typing from another device'); + done(); })); }); describe("A paused notification", function () { - it("is sent if the user has stopped typing since 30 seconds", mock.initConverseWithAsync(function (done, _converse) { + it("is sent if the user has stopped typing since 30 seconds", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var view, contact_jid; test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); @@ -1524,7 +1702,11 @@ }); })); - it("will be shown if received", mock.initConverseWithAsync(function (done, _converse) { + it("will be shown if received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1552,7 +1734,11 @@ }); })); - it("can be a paused carbon message that this user sent from a different client", mock.initConverse(function (_converse) { + it("can be a paused carbon message that this user sent from a different client", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); // Send a message from a different resource @@ -1587,12 +1773,17 @@ var $chat_content = chatboxview.$el.find('.chat-content'); var status_text = $chat_content.find('.chat-info.chat-event').text(); expect(status_text).toBe('Stopped typing on the other device'); + done(); })); }); describe("An inactive notifciation", function () { - it("is sent if the user has stopped typing since 2 minutes", mock.initConverseWithAsync(function (done, _converse) { + it("is sent if the user has stopped typing since 2 minutes", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var view, contact_jid; test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); @@ -1642,7 +1833,11 @@ }); })); - it("is sent when the user a minimizes a chat box", mock.initConverse(function (_converse) { + it("is sent when the user a minimizes a chat box", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1657,9 +1852,14 @@ var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree()); expect($stanza.attr('to')).toBe(contact_jid); expect($stanza.children().get(0).tagName).toBe('inactive'); + done(); })); - it("is sent if the user closes a chat box", mock.initConverseWithAsync(function (done, _converse) { + it("is sent if the user closes a chat box", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1684,7 +1884,11 @@ }); })); - it("will clear any other chat status notifications if its received", mock.initConverse(function (_converse) { + it("will clear any other chat status notifications if its received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1706,13 +1910,17 @@ _converse.chatboxes.onMessage(msg); expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object)); expect(view.$el.find('.chat-event').length).toBe(0); + done(); })); - }); describe("A gone notifciation", function () { - it("will be shown if received", mock.initConverse(function (_converse) { + it("will be shown if received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1731,6 +1939,7 @@ var chatboxview = _converse.chatboxviews.get(sender_jid); var $events = chatboxview.$el.find('.chat-event'); expect($events.text()).toEqual(mock.cur_names[1] + ' has gone away'); + done(); })); }); }); @@ -1738,7 +1947,11 @@ describe("Special Messages", function () { - it("'/clear' can be used to clear messages in a conversation", mock.initConverse(function (_converse) { + it("'/clear' can be used to clear messages in a conversation", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1769,12 +1982,17 @@ expect(view.model.messages.browserStorage.records.length, 0); // And also from browserStorage expect(_converse.emit.calls.count(), 1); expect(_converse.emit.calls.mostRecent().args, ['messageSend', message]); + done(); })); }); describe("A Message Counter", function () { - it("is incremented when the message is received and the window is not focused", mock.initConverse(function (_converse) { + it("is incremented when the message is received and the window is not focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1801,9 +2019,14 @@ expect(_converse.msg_counter).toBe(1); expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object)); _converse.windowSate = previous_state; + done(); })); - it("is cleared when the window is focused", mock.initConverse(function (_converse) { + it("is cleared when the window is focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1812,9 +2035,14 @@ _converse.saveWindowState(null, 'focus'); _converse.saveWindowState(null, 'blur'); expect(_converse.clearMsgCounter).toHaveBeenCalled(); + done(); })); - it("is not incremented when the message is received and the window is focused", mock.initConverse(function (_converse) { + it("is not incremented when the message is received and the window is focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openControlBox(); test_utils.openContactsPanel(_converse); @@ -1834,9 +2062,14 @@ _converse.chatboxes.onMessage(msg); expect(_converse.incrementMsgCounter).not.toHaveBeenCalled(); expect(_converse.msg_counter).toBe(0); + done(); })); - it("is incremented from zero when chatbox was closed after viewing previously received messages and the window is not focused now", mock.initConverse(function (_converse) { + it("is incremented from zero when chatbox was closed after viewing previously received messages and the window is not focused now", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); // initial state @@ -1876,12 +2109,17 @@ view = _converse.chatboxviews.get(sender_jid); expect(view.$el.is(':visible')).toBeTruthy(); expect(_converse.msg_counter).toBe(1); + done(); })); }); describe("A ChatBox's Unread Message Count", function () { - it("is incremented when the message is received and ChatBoxView is scrolled up", mock.initConverse(function (_converse) { + it("is incremented when the message is received and ChatBoxView is scrolled up", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); @@ -1894,9 +2132,14 @@ _converse.chatboxes.onMessage(msg); expect(chatbox.get('num_unread')).toBe(1); + done(); })); - it("is not incremented when the message is received and ChatBoxView is scrolled down", mock.initConverse(function (_converse) { + it("is not incremented when the message is received and ChatBoxView is scrolled down", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); @@ -1908,9 +2151,14 @@ _converse.chatboxes.onMessage(msg); expect(chatbox.get('num_unread')).toBe(0); + done(); })); - it("is incremeted when message is received, chatbox is scrolled down and the window is not focused", mock.initConverse(function (_converse) { + it("is incremeted when message is received, chatbox is scrolled down and the window is not focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -1925,9 +2173,14 @@ _converse.chatboxes.onMessage(msgFactory()); expect(chatbox.get('num_unread')).toBe(1); + done(); })); - it("is incremeted when message is received, chatbox is scrolled up and the window is not focused", mock.initConverse(function (_converse) { + it("is incremeted when message is received, chatbox is scrolled up and the window is not focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -1943,9 +2196,14 @@ _converse.chatboxes.onMessage(msgFactory()); expect(chatbox.get('num_unread')).toBe(1); + done(); })); - it("is cleared when ChatBoxView was scrolled down and the window become focused", mock.initConverse(function (_converse) { + it("is cleared when ChatBoxView was scrolled down and the window become focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -1962,9 +2220,14 @@ _converse.saveWindowState(null, 'focus'); expect(chatbox.get('num_unread')).toBe(0); + done(); })); - it("is not cleared when ChatBoxView was scrolled up and the windows become focused", mock.initConverse(function (_converse) { + it("is not cleared when ChatBoxView was scrolled up and the windows become focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); var sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -1982,12 +2245,17 @@ _converse.saveWindowState(null, 'focus'); expect(chatbox.get('num_unread')).toBe(1); + done(); })); }); describe("A RosterView's Unread Message Count", function () { - it("is updated when message is received and chatbox is scrolled up", mock.initConverseWithAsync(function (done, _converse) { + it("is updated when message is received and chatbox is scrolled up", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); test_utils.waitUntil(function () { @@ -2012,12 +2280,15 @@ $msgIndicator = $(_converse.rosterview.$el.find(msgIndicatorSelector)); expect($msgIndicator.text()).toBe('2'); - done(); }); })); - it("is updated when message is received and chatbox is minimized", mock.initConverseWithAsync(function (done, _converse) { + it("is updated when message is received and chatbox is minimized", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); test_utils.waitUntil(function () { @@ -2043,12 +2314,15 @@ $msgIndicator = $(_converse.rosterview.$el.find(msgIndicatorSelector)); expect($msgIndicator.text()).toBe('2'); - done(); }); })); - it("is cleared when chatbox is maximzied after receiving messages in minimized mode", mock.initConverseWithAsync(function (done, _converse) { + it("is cleared when chatbox is maximzied after receiving messages in minimized mode", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); test_utils.waitUntil(function () { @@ -2075,12 +2349,15 @@ chatboxview.maximize(); expect(selectMsgsIndicator().length).toBe(0); - done(); }); })); - it("is cleared when unread messages are viewed which were received in scrolled-up chatbox", mock.initConverseWithAsync(function (done, _converse) { + it("is cleared when unread messages are viewed which were received in scrolled-up chatbox", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); test_utils.waitUntil(function () { @@ -2105,12 +2382,15 @@ chatboxview.viewUnreadMessages(); _converse.rosterview.render(); expect(selectMsgsIndicator().length).toBe(0); - done(); }); })); - it("is not cleared after user clicks on roster view when chatbox is already opened and scrolled up", mock.initConverseWithAsync(function (done, _converse) { + it("is not cleared after user clicks on roster view when chatbox is already opened and scrolled up", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); test_utils.waitUntil(function () { @@ -2134,17 +2414,18 @@ test_utils.openChatBoxFor(_converse, sender_jid); expect(selectMsgsIndicator().text()).toBe('1'); - done(); }); })); - - }); describe("A Minimized ChatBoxView's Unread Message Count", function () { - it("is displayed when scrolled up chatbox is minimized after receiving unread messages", mock.initConverse(function (_converse) { + it("is displayed when scrolled up chatbox is minimized after receiving unread messages", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); @@ -2168,9 +2449,14 @@ var $unreadMsgCount = selectUnreadMsgCount(); expect($unreadMsgCount.is(':visible')).toBeTruthy(); expect($unreadMsgCount.html()).toBe('1'); + done(); })); - it("is incremented when message is received and windows is not focused", mock.initConverse(function (_converse) { + it("is incremented when message is received and windows is not focused", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openContactsPanel(_converse); @@ -2192,6 +2478,7 @@ var $unreadMsgCount = selectUnreadMsgCount(); expect($unreadMsgCount.is(':visible')).toBeTruthy(); expect($unreadMsgCount.html()).toBe('1'); + done(); })); }); }); diff --git a/spec/chatroom.js b/spec/chatroom.js index 384135dda..cd49af6ca 100644 --- a/spec/chatroom.js +++ b/spec/chatroom.js @@ -1,8 +1,7 @@ (function (root, factory) { - define(["jasmine", "mock", "converse-core", "test-utils", "utils" ], factory); -} (this, function (jasmine, mock, converse, test_utils, utils) { + define(["jquery.noconflict", "jasmine", "mock", "converse-core", "test-utils", "utils" ], factory); +} (this, function ($, jasmine, mock, converse, test_utils, utils) { var _ = converse.env._; - var $ = converse.env.jQuery; var $pres = converse.env.$pres; var $iq = converse.env.$iq; var $msg = converse.env.$msg; @@ -11,7 +10,11 @@ return describe("ChatRooms", function () { describe("The \"rooms\" API", function () { - it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments", mock.initConverse(function (_converse) { + it("has a method 'close' which closes rooms by JID or all rooms when called with no arguments", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); test_utils.openAndEnterChatRoom(_converse, 'leisure', 'localhost', 'dummy'); @@ -43,6 +46,7 @@ _converse.api.rooms.close(); expect(_converse.chatboxviews.get('lounge@localhost')).toBeUndefined(); expect(_converse.chatboxviews.get('leisure@localhost')).toBeUndefined(); + done(); })); it("has a method 'get' which returns a wrapped chat room (if it exists)", mock.initConverseWithAsync(function (done, _converse) { @@ -242,7 +246,11 @@ }); describe("An instant chat room", function () { - it("will be created when muc_instant_rooms is set to true", mock.initConverse(function (_converse) { + it("will be created when muc_instant_rooms is set to true", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -269,7 +277,6 @@ .c('item-not-found', {'xmlns': "urn:ietf:params:xml:ns:xmpp-stanzas"}); _converse.connection._dataRecv(test_utils.createRequest(features_stanza)); - var view = _converse.chatboxviews.get('lounge@localhost'); spyOn(view, 'join').and.callThrough(); @@ -346,12 +353,17 @@ ""+ ""+ ""); + done(); })); }); describe("A Chat Room", function () { - it("shows join/leave messages when users enter or exit a room", mock.initConverse(function (_converse) { + it("shows join/leave messages when users enter or exit a room", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openChatRoom(_converse, "coven", 'chat.shakespeare.lit', 'some1'); var view = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); var $chat_content = view.$el.find('.chat-content'); @@ -432,9 +444,14 @@ _converse.connection._dataRecv(test_utils.createRequest(presence)); expect($chat_content.find('div.chat-info').length).toBe(3); expect($chat_content.find('div.chat-info:last').html()).toBe("newguy has left the room"); + done(); })); - it("shows its description in the chat heading", mock.initConverse(function (_converse) { + it("shows its description in the chat heading", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -473,9 +490,14 @@ _converse.connection._dataRecv(test_utils.createRequest(features_stanza)); expect(view.generateHeadingHTML).toHaveBeenCalled(); expect(view.$('.chatroom-description').text()).toBe('This is the description'); + done(); })); - it("will specially mark messages in which you are mentioned", mock.initConverse(function (_converse) { + it("will specially mark messages in which you are mentioned", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); var view = _converse.chatboxviews.get('lounge@localhost'); @@ -490,9 +512,14 @@ }).c('body').t(message).tree(); view.handleMUCMessage(msg); expect(view.$el.find('.chat-message').hasClass('mentioned')).toBeTruthy(); + done(); })); - it("supports the /me command", mock.initConverse(function (_converse) { + it("supports the /me command", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); var view = _converse.chatboxviews.get('lounge@localhost'); @@ -519,16 +546,26 @@ view.handleMUCMessage(msg); expect(_.includes(view.$el.find('.chat-msg-author:last').text(), '**Max Mustermann')).toBeTruthy(); expect(view.$el.find('.chat-msg-content:last').text()).toBe(' is as well'); + done(); })); - it("can have spaces and special characters in its name", mock.initConverse(function (_converse) { + it("can have spaces and special characters in its name", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _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); + done(); })); - it("can be configured if you're its owner", mock.initConverse(function (_converse) { + it("can be configured if you're its owner", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var view; var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; @@ -593,8 +630,8 @@ ""); /* Server responds with the configuration form. - * See: // http://xmpp.org/extensions/xep-0045.html#example-165 - */ + * See: // http://xmpp.org/extensions/xep-0045.html#example-165 + */ var config_stanza = $iq({from: 'coven@chat.shakespeare.lit', 'id': IQ_id, 'to': 'dummy@localhost/desktop', @@ -740,9 +777,14 @@ expect($sent_stanza.find('field[var="muc#roomconfig_moderatedroom"] value').text()).toBe('1'); expect($sent_stanza.find('field[var="muc#roomconfig_allowpm"] value').text()).toBe('moderators'); expect($sent_stanza.find('field[var="muc#roomconfig_presencebroadcast"] value').text()).toBe('moderator'); + done(); })); - it("shows users currently present in the room", mock.initConverse(function (_converse) { + it("shows users currently present in the room", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); var name; var view = _converse.chatboxviews.get('lounge@localhost'), @@ -787,9 +829,14 @@ _converse.connection._dataRecv(test_utils.createRequest(presence)); expect($occupants.find('li').length).toBe(i+1); } + done(); })); - it("escapes occupant nicknames when rendering them, to avoid JS-injection attacks", mock.initConverse(function (_converse) { + it("escapes occupant nicknames when rendering them, to avoid JS-injection attacks", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); /* @@ -814,9 +861,14 @@ var occupant = view.$el.find('.occupant-list').find('li'); expect(occupant.length).toBe(2); expect($(occupant).last().text()).toBe("<img src="x" onerror="alert(123)"/>"); + done(); })); - it("indicates moderators by means of a special css class and tooltip", mock.initConverse(function (_converse) { + it("indicates moderators by means of a special css class and tooltip", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); var view = _converse.chatboxviews.get('lounge@localhost'); var contact_jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -838,9 +890,14 @@ expect($(occupant).last().text()).toBe("moderatorman"); expect($(occupant).last().attr('class').indexOf('moderator')).not.toBe(-1); expect($(occupant).last().attr('title')).toBe(contact_jid + ' This user is a moderator. Click to mention moderatorman in your message.'); + done(); })); - it("will use the user's reserved nickname, if it exists", mock.initConverse(function (_converse) { + it("will use the user's reserved nickname, if it exists", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -920,9 +977,14 @@ _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'); + done(); })); - it("allows the user to invite their roster contacts to enter the chat room", mock.initConverseWithAsync(function (done, _converse) { + it("allows the user to invite their roster contacts to enter the chat room", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); test_utils.createContacts(_converse, 'current'); // We need roster contacts, so that we have someone to invite // Since we don't actually fetch roster contacts, we need to @@ -989,7 +1051,11 @@ }); })); - it("can be joined automatically, based upon a received invite", mock.initConverse(function (_converse) { + it("can be joined automatically, based upon a received invite", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.createContacts(_converse, 'current'); // We need roster contacts, who can invite us spyOn(window, 'confirm').and.callFake(function () { return true; @@ -1018,9 +1084,14 @@ expect(_converse.chatboxes.models.length).toBe(2); expect(_converse.chatboxes.models[0].id).toBe('controlbox'); expect(_converse.chatboxes.models[1].id).toBe(room_jid); + done(); })); - it("shows received groupchat messages", mock.initConverse(function (_converse) { + it("shows received groupchat messages", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy'); spyOn(_converse, 'emit'); var view = _converse.chatboxviews.get('lounge@localhost'); @@ -1038,9 +1109,14 @@ expect($chat_content.find('.chat-message').length).toBe(1); expect($chat_content.find('.chat-msg-content').text()).toBe(text); expect(_converse.emit).toHaveBeenCalledWith('message', jasmine.any(Object)); + done(); })); - it("shows sent groupchat messages", mock.initConverse(function (_converse) { + it("shows sent groupchat messages", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); spyOn(_converse, 'emit'); var view = _converse.chatboxviews.get('lounge@localhost'); @@ -1065,9 +1141,14 @@ 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.calls.count(), 1); + done(); })); - it("will cause the chat area to be scrolled down only if it was at the bottom already", mock.initConverseWithAsync(function (done, _converse) { + it("will cause the chat area to be scrolled down only if it was at the bottom already", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var message = 'This message is received while the chat area is scrolled up'; test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); var view = _converse.chatboxviews.get('lounge@localhost'); @@ -1104,7 +1185,11 @@ }, 500); })); - it("shows received chatroom subject messages", mock.initConverse(function (_converse) { + it("shows received chatroom subject messages", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _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'; @@ -1118,9 +1203,14 @@ var view = _converse.chatboxviews.get('jdev@conference.jabber.org'); var $chat_content = view.$el.find('.chat-content'); expect($chat_content.find('.chat-info:last').text()).toBe('Topic set by ralphm to: '+text); + done(); })); - it("escapes the subject before rendering it, to avoid JS-injection attacks", mock.initConverse(function (_converse) { + it("escapes the subject before rendering it, to avoid JS-injection attacks", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openAndEnterChatRoom(_converse, 'jdev', 'conference.jabber.org', 'jc'); spyOn(window, 'alert'); var subject = ''; @@ -1128,9 +1218,14 @@ view.setChatRoomSubject('ralphm', subject); var $chat_content = view.$el.find('.chat-content'); expect($chat_content.find('.chat-info:last').text()).toBe('Topic set by ralphm to: '+subject); + done(); })); - it("informs users if their nicknames has been changed.", mock.initConverse(function (_converse) { + it("informs users if their nicknames has been changed.", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _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 @@ -1240,9 +1335,14 @@ $occupants = view.$('.occupant-list'); expect($occupants.children().length).toBe(1); expect($occupants.children().first(0).text()).toBe("newnick"); + done(); })); - it("queries for the room information before attempting to join the user", mock.initConverse(function (_converse) { + it("queries for the room information before attempting to join the user", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -1306,9 +1406,14 @@ expect(view.model.get('open')).toBe(true); expect(view.model.get('unmoderated')).toBe(true); expect(view.model.get('nonanonymous')).toBe(true); + done(); })); - it("updates the shown features when the room configuration has changed", mock.initConverse(function (_converse) { + it("updates the shown features when the room configuration has changed", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; test_utils.openAndEnterChatRoom(_converse, 'room', 'conference.example.org', 'dummy'); @@ -1356,9 +1461,14 @@ view.model.set({'membersonly': true}); expect(view.model.get('open')).toBe(false); expect(view.model.get('membersonly')).toBe(true); + done(); })); - it("indicates when a room is no longer anonymous", mock.initConverse(function (_converse) { + it("indicates when a room is no longer anonymous", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -1400,9 +1510,14 @@ expect($chat_body.html().trim().indexOf( '
This room is now no longer anonymous
' )).not.toBe(-1); + done(); })); - it("informs users if they have been kicked out of the chat room", mock.initConverse(function (_converse) { + it("informs users if they have been kicked out of the chat room", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + /* "+ ""+ ""); + done(); })); - it("to ban a user", mock.initConverse(function (_converse) { + it("to ban a user", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var sent_IQ, IQ_id; var sendIQ = _converse.connection.sendIQ; spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { @@ -1652,6 +1800,7 @@ ""+ ""+ ""); + done(); })); }); @@ -1668,7 +1817,11 @@ roomspanel.$el.find('form').submit(); }; - it("will show an error message if the room requires a password", mock.initConverse(function (_converse) { + it("will show an error message if the room requires a password", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + submitRoomForm(_converse); var presence = $pres().attrs({ from:'lounge@localhost/thirdwitch', @@ -1687,9 +1840,14 @@ expect(view.renderPasswordForm).toHaveBeenCalled(); expect($chat_body.find('form.chatroom-form').length).toBe(1); expect($chat_body.find('legend').text()).toBe('This chatroom requires a password'); + done(); })); - it("will show an error message if the room is members-only and the user not included", mock.initConverse(function (_converse) { + it("will show an error message if the room is members-only and the user not included", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + submitRoomForm(_converse); var presence = $pres().attrs({ from:'lounge@localhost/thirdwitch', @@ -1703,9 +1861,14 @@ spyOn(view, 'showErrorMessage').and.callThrough(); view.onChatRoomPresence(presence); expect(view.$el.find('.chatroom-body p:last').text()).toBe('You are not on the member list of this room.'); + done(); })); - it("will show an error message if the user has been banned", mock.initConverse(function (_converse) { + it("will show an error message if the user has been banned", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + submitRoomForm(_converse); var presence = $pres().attrs({ from:'lounge@localhost/thirdwitch', @@ -1719,9 +1882,14 @@ spyOn(view, 'showErrorMessage').and.callThrough(); view.onChatRoomPresence(presence); expect(view.$el.find('.chatroom-body p:last').text()).toBe('You have been banned from this room.'); + done(); })); - it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false", mock.initConverse(function (_converse) { + it("will render a nickname form if a nickname conflict happens and muc_nickname_from_jid=false", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + submitRoomForm(_converse); var presence = $pres().attrs({ from:'lounge@localhost/thirdwitch', @@ -1735,9 +1903,14 @@ spyOn(view, 'showErrorMessage').and.callThrough(); view.onChatRoomPresence(presence); expect(view.$el.find('.chatroom-body form.chatroom-form label:first').text()).toBe('Please choose your nickname'); + done(); })); - it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true", mock.initConverse(function (_converse) { + it("will automatically choose a new nickname if a nickname conflict happens and muc_nickname_from_jid=true", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + /* "+ "" ); + done(); })); }); describe("The affiliations delta", function () { - it("can be computed in various ways", mock.initConverse(function (_converse) { + it("can be computed in various ways", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openChatRoom(_converse, 'coven', 'chat.shakespeare.lit', 'dummy'); var roomview = _converse.chatboxviews.get('coven@chat.shakespeare.lit'); @@ -2058,12 +2261,17 @@ old_list = [{'jid': 'wiccarocks@shakespeare.lit', 'affiliation': 'owner'}]; delta = roomview.computeAffiliationsDelta(exclude_existing, remove_absentees, new_list, old_list); expect(delta.length).toBe(0); + done(); })); }); describe("The \"Rooms\" Panel", function () { - it("is opened by clicking the 'Chatrooms' tab", mock.initConverse(function (_converse) { + it("is opened by clicking the 'Chatrooms' tab", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var cbview = _converse.chatboxviews.get('controlbox'); var $tabs = cbview.$el.find('#controlbox-tabs'); @@ -2076,9 +2284,14 @@ expect($contacts.is(':visible')).toBe(false); expect($chatrooms.is(':visible')).toBe(true); expect(cbview.switchTab).toHaveBeenCalled(); + done(); })); - it("contains a form through which a new chatroom can be created", mock.initConverse(function (_converse) { + it("contains a form through which a new chatroom can be created", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var roomspanel = _converse.chatboxviews.get('controlbox').roomspanel; var $input = roomspanel.$el.find('input.new-chatroom-name'); @@ -2101,9 +2314,14 @@ roomspanel.$el.find('form').submit(); expect(roomspanel.openChatRoom).toHaveBeenCalled(); expect($('.chatroom:visible').length).toBe(1); // There should now be an open chatroom + done(); })); - it("can list rooms publically available on the server", mock.initConverse(function (_converse) { + it("can list rooms publically available on the server", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var panel = _converse.chatboxviews.get('controlbox').roomspanel; $(panel.tabs).find('li').last().find('a').click(); // Click the chatrooms tab @@ -2126,9 +2344,14 @@ expect(panel.$('#available-chatrooms').children('dt').length).toBe(1); expect(panel.$('#available-chatrooms').children('dt').first().text()).toBe("Rooms on muc.localhost"); expect(panel.$('#available-chatrooms').children('dd').length).toBe(4); + done(); })); - it("shows the number of unread mentions received", mock.initConverse(function (_converse) { + it("shows the number of unread mentions received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var room_jid = 'kitchen@conference.shakespeare.lit'; test_utils.openAndEnterChatRoom( _converse, 'kitchen', 'conference.shakespeare.lit', 'fires'); @@ -2168,6 +2391,7 @@ view.model.set({'minimized': false}); expect(_.includes(roomspanel.tab_el.firstChild.classList, 'unread-msgs')).toBeFalsy(); expect(_.isNull(roomspanel.tab_el.querySelector('.msgs-indicator'))).toBeTruthy(); + done(); })); }); }); diff --git a/spec/controlbox.js b/spec/controlbox.js index 4aa5188aa..46aa10082 100644 --- a/spec/controlbox.js +++ b/spec/controlbox.js @@ -1,8 +1,7 @@ (function (root, factory) { - define(["jasmine", "mock", "converse-core", "test-utils"], factory); -} (this, function (jasmine, mock, converse, test_utils) { + define(["jquery.noconflict", "jasmine", "mock", "converse-core", "test-utils"], factory); +} (this, function ($, jasmine, mock, converse, test_utils) { var _ = converse.env._; - var $ = converse.env.jQuery; var $pres = converse.env.$pres; var $msg = converse.env.$msg; var $iq = converse.env.$iq; @@ -25,7 +24,11 @@ describe("The Control Box", function () { - it("can be opened by clicking a DOM element with class 'toggle-controlbox'", mock.initConverse(function (_converse) { + it("can be opened by clicking a DOM element with class 'toggle-controlbox'", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + // This spec will only pass if the controlbox is not currently // open yet. expect($("div#controlbox").is(':visible')).toBe(false); @@ -39,18 +42,28 @@ expect(_converse.controlboxtoggle.showControlBox).toHaveBeenCalled(); expect(_converse.emit).toHaveBeenCalledWith('controlBoxOpened', jasmine.any(Object)); expect($("div#controlbox").is(':visible')).toBe(true); + done(); })); describe("The Status Widget", function () { - it("shows the user's chat status, which is online by default", mock.initConverse(function (_converse) { + it("shows the user's chat status, which is online by default", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var view = _converse.xmppstatusview; expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true); expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am online'); + done(); })); - it("can be used to set the current user's chat status", mock.initConverse(function (_converse) { + it("can be used to set the current user's chat status", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var view = _converse.xmppstatusview; spyOn(view, 'toggleOptions').and.callThrough(); @@ -68,9 +81,14 @@ expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(false); expect(view.$el.find('a.choose-xmpp-status').hasClass('dnd')).toBe(true); expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe('I am busy'); + done(); })); - it("can be used to set a custom status message", mock.initConverse(function (_converse) { + it("can be used to set a custom status message", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var view = _converse.xmppstatusview; _converse.xmppstatus.save({'status': 'online'}); @@ -87,6 +105,7 @@ expect(_converse.emit).toHaveBeenCalledWith('statusMessageChanged', msg); expect(view.$el.find('a.choose-xmpp-status').hasClass('online')).toBe(true); expect(view.$el.find('a.choose-xmpp-status').attr('data-value')).toBe(msg); + done(); })); }); }); @@ -95,7 +114,11 @@ describe("The live filter", function () { - it("will only appear when roster contacts flow over the visible area", mock.initConverseWithAsync(function (done, _converse) { + it("will only appear when roster contacts flow over the visible area", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var $filter = _converse.rosterview.$('.roster-filter'); var names = mock.cur_names; test_utils.openControlBox(); @@ -120,13 +143,17 @@ } else { return !$filter.is(':visible'); } - }).then(function () { - done(); - }); + }).then(function () { + done(); + }); }); })); - it("can be used to filter the contacts shown", mock.initConverseWithAsync(function (done, _converse) { + it("can be used to filter the contacts shown", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var $filter; var $roster; _converse.roster_groups = true; @@ -180,7 +207,11 @@ }); })); - it("can be used to filter the groups shown", mock.initConverseWithAsync(function (done, _converse) { + it("can be used to filter the groups shown", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var $filter; var $roster; var $type; @@ -226,7 +257,11 @@ }); })); - it("has a button with which its contents can be cleared", mock.initConverseWithAsync(function (done, _converse) { + it("has a button with which its contents can be cleared", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.roster_groups = true; test_utils.openControlBox(); test_utils.createGroupedContacts(_converse); @@ -250,7 +285,11 @@ }); })); - it("can be used to filter contacts by their chat state", mock.initConverseWithAsync(function (done, _converse) { + it("can be used to filter contacts by their chat state", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var $filter; var $roster; _converse.roster_groups = true; @@ -287,7 +326,11 @@ describe("A Roster Group", function () { - it("can be used to organize existing contacts", mock.initConverseWithAsync(function (done, _converse) { + it("can be used to organize existing contacts", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.roster_groups = true; spyOn(_converse, 'emit'); spyOn(_converse.rosterview, 'update').and.callThrough(); @@ -321,7 +364,11 @@ }); })); - it("can share contacts with other roster groups", mock.initConverseWithAsync(function (done, _converse) { + it("can share contacts with other roster groups", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.roster_groups = true; var groups = ['colleagues', 'friends']; spyOn(_converse, 'emit'); @@ -351,7 +398,11 @@ }); })); - it("remembers whether it is closed or opened", mock.initConverse(function (_converse) { + it("remembers whether it is closed or opened", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.roster_groups = true; var i=0, j=0; var groups = { @@ -378,6 +429,7 @@ expect(view.model.get('state')).toBe('closed'); $toggle.click(); expect(view.model.get('state')).toBe('opened'); + done(); })); }); @@ -388,7 +440,11 @@ test_utils.createContacts(_converse, 'pending').openControlBox().openContactsPanel(_converse); } - it("can be collapsed under their own header", mock.initConverseWithAsync(function (done, _converse) { + it("can be collapsed under their own header", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _addContacts(_converse); test_utils.waitUntil(function () { return _converse.rosterview.$el.find('dd').length; @@ -399,7 +455,11 @@ }); })); - it("can be added to the roster", mock.initConverse(function (_converse) { + it("can be added to the roster", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + spyOn(_converse, 'emit'); spyOn(_converse.rosterview, 'update').and.callThrough(); test_utils.openControlBox(); @@ -410,9 +470,14 @@ fullname: mock.pend_names[0] }); expect(_converse.rosterview.update).toHaveBeenCalled(); + done(); })); - it("are shown in the roster when show_only_online_users", mock.initConverseWithAsync(function (done, _converse) { + it("are shown in the roster when show_only_online_users", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.show_only_online_users = true; spyOn(_converse.rosterview, 'update').and.callThrough(); _addContacts(_converse); @@ -428,7 +493,11 @@ }); })); - it("are shown in the roster when hide_offline_users", mock.initConverseWithAsync(function (done, _converse) { + it("are shown in the roster when hide_offline_users", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.hide_offline_users = true; spyOn(_converse.rosterview, 'update').and.callThrough(); _addContacts(_converse); @@ -444,7 +513,11 @@ }); })); - it("can be removed by the user", mock.initConverseWithAsync(function (done, _converse) { + it("can be removed by the user", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _addContacts(_converse); var name = mock.pend_names[0]; var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -474,7 +547,11 @@ }); })); - it("do not have a header if there aren't any", mock.initConverseWithAsync(function (done, _converse) { + it("do not have a header if there aren't any", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); var name = mock.pend_names[0]; _converse.roster.create({ @@ -500,7 +577,11 @@ }); })); - it("will lose their own header once the last one has been removed", mock.initConverse(function (_converse) { + it("is shown when a new private message is received", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _addContacts(_converse); var name; spyOn(window, 'confirm').and.returnValue(true); @@ -510,9 +591,14 @@ .parent().siblings('.remove-xmpp-contact').click(); } expect(_converse.rosterview.$el.find('dt#pending-xmpp-contacts').is(':visible')).toBeFalsy(); + done(); })); - it("can be added to the roster and they will be sorted alphabetically", mock.initConverse(function (_converse) { + it("can be added to the roster and they will be sorted alphabetically", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + var i, t; spyOn(_converse, 'emit'); spyOn(_converse.rosterview, 'update').and.callThrough(); @@ -530,6 +616,7 @@ return result + _.trim(value.textContent); }, ''); expect(t).toEqual(mock.pend_names.slice(0,i+1).sort().join('')); + done(); })); }); @@ -538,7 +625,11 @@ test_utils.createContacts(_converse, 'current').openControlBox().openContactsPanel(_converse); }; - it("can be collapsed under their own header", mock.initConverseWithAsync(function (done, _converse) { + it("can be collapsed under their own header", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _addContacts(_converse); test_utils.waitUntil(function () { return _converse.rosterview.$el.find('dd:visible').length; @@ -549,7 +640,11 @@ }); })); - it("will be hidden when appearing under a collapsed group", mock.initConverseWithAsync(function (done, _converse) { + it("will be hidden when appearing under a collapsed group", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + _converse.roster_groups = false; _addContacts(_converse); test_utils.waitUntil(function () { @@ -572,7 +667,11 @@ }); })); - it("can be added to the roster and they will be sorted alphabetically", mock.initConverseWithAsync(function (done, _converse) { + it("can be added to the roster and they will be sorted alphabetically", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + spyOn(_converse.rosterview, 'update').and.callThrough(); for (var i=0; i stanzas", mock.initConverse(function (_converse) { + it("will add processing hints to sent out encrypted stanzas", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); test_utils.openContactsPanel(_converse); test_utils.createContacts(_converse, 'current'); @@ -25,11 +28,16 @@ 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 + done(); })); describe("An OTR Chat Message", function () { - it("will not be carbon copied when it's sent out", mock.initConverse(function (_converse) { + it("will not be carbon copied when it's sent out", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); test_utils.openContactsPanel(_converse); test_utils.createContacts(_converse, 'current'); @@ -46,6 +54,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 + done(); })); }); }); diff --git a/spec/ping.js b/spec/ping.js index fad523715..467320c65 100644 --- a/spec/ping.js +++ b/spec/ping.js @@ -6,20 +6,30 @@ describe("XMPP Ping", function () { describe("Ping and pong handlers", function () { - it("are registered when _converse.js is connected", mock.initConverse(function (_converse) { + it("are registered when _converse.js is connected", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + spyOn(_converse, 'registerPingHandler').and.callThrough(); spyOn(_converse, 'registerPongHandler').and.callThrough(); _converse.emit('connected'); expect(_converse.registerPingHandler).toHaveBeenCalled(); expect(_converse.registerPongHandler).toHaveBeenCalled(); + done(); })); - it("are registered when _converse.js reconnected", mock.initConverse(function (_converse) { + it("are registered when _converse.js reconnected", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + spyOn(_converse, 'registerPingHandler').and.callThrough(); spyOn(_converse, 'registerPongHandler').and.callThrough(); _converse.emit('reconnected'); expect(_converse.registerPingHandler).toHaveBeenCalled(); expect(_converse.registerPongHandler).toHaveBeenCalled(); + done(); })); }); diff --git a/spec/presence.js b/spec/presence.js index d9c11935b..289afd95e 100644 --- a/spec/presence.js +++ b/spec/presence.js @@ -49,7 +49,11 @@ describe("A received presence stanza", function () { - it("has its priority taken into account", mock.initConverse(function (_converse) { + it("has its priority taken into account", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(); test_utils.createContacts(_converse, 'current'); // Create some contacts so that we can test positioning var contact_jid = mock.cur_names[8].replace(/ /g,'.').toLowerCase() + '@localhost'; @@ -218,6 +222,7 @@ _converse.connection._dataRecv(test_utils.createRequest(stanza[0])); expect(_converse.roster.get(contact_jid).get('chat_status')).toBe('offline'); expect(_.keys(contact.get('resources')).length).toBe(0); + done(); })); }); })); diff --git a/spec/protocol.js b/spec/protocol.js index 86e505bac..dc3868063 100644 --- a/spec/protocol.js +++ b/spec/protocol.js @@ -10,6 +10,7 @@ var Strophe = converse.env.Strophe; var $iq = converse.env.$iq; var $pres = converse.env.$pres; + var _ = converse.env._; // See: // https://xmpp.org/rfcs/rfc3921.html @@ -47,11 +48,15 @@ * that session. A client MUST acknowledge each roster push with an IQ * stanza of type "result". */ - it("Subscribe to contact, contact accepts and subscribes back", mock.initConverseWithAsync(function (done, _converse) { + it("Subscribe to contact, contact accepts and subscribes back", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], + { roster_groups: false }, + function (done, _converse) { + /* The process by which a user subscribes to a contact, including * the interaction between roster items and subscription states. */ - _converse.roster_groups = false; var contact, stanza, sent_stanza, IQ_id; test_utils.openControlBox(_converse); var panel = _converse.chatboxviews.get('controlbox').contactspanel; @@ -134,8 +139,10 @@ * */ var create = _converse.roster.create; + var sent_stanzas = []; spyOn(_converse.connection, 'send').and.callFake(function (stanza) { sent_stanza = stanza; + sent_stanzas.push(stanza.toLocaleString()); }); spyOn(_converse.roster, 'create').and.callFake(function () { contact = create.apply(_converse.roster, arguments); @@ -165,6 +172,11 @@ * * */ + + test_utils.waitUntil(function () { + return sent_stanzas.length == 1; + }).then(function () { + expect(contact.subscribe).toHaveBeenCalled(); expect(sent_stanza.toLocaleString()).toBe( // Strophe adds the xmlns attr (although not in spec) ""+ @@ -347,9 +359,14 @@ expect($contacts.hasClass('both')).toBeTruthy(); done(); }); + }); })); - it("Alternate Flow: Contact Declines Subscription Request", mock.initConverse(function (_converse) { + it("Alternate Flow: Contact Declines Subscription Request", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + /* The process by which a user subscribes to a contact, including * the interaction between roster items and subscription states. */ @@ -429,11 +446,16 @@ ""+ "" ); + done(); })); - it("Unsubscribe to a contact when subscription is mutual", mock.initConverseWithAsync(function (done, _converse) { + it("Unsubscribe to a contact when subscription is mutual", + mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], + { roster_groups: false }, + function (done, _converse) { + var sent_IQ, IQ_id, jid = 'annegreet.gomez@localhost'; - _converse.roster_groups = false; test_utils.openControlBox(_converse); test_utils.createContacts(_converse, 'current'); spyOn(window, 'confirm').and.returnValue(true); @@ -490,7 +512,10 @@ }); })); - it("Receiving a subscription request", mock.initConverse(function (_converse) { + it("Receiving a subscription request", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], {}, + function (done, _converse) { + test_utils.openControlBox(_converse); test_utils.createContacts(_converse, 'current'); // Create some contacts so that we can test positioning spyOn(_converse, "emit"); @@ -516,6 +541,7 @@ expect($header.is(":visible")).toBeTruthy(); var $contacts = $header.parent().nextUntil('dt', 'dd'); expect($contacts.length).toBe(1); + done(); }); })); }); diff --git a/spec/register.js b/spec/register.js index 1840647b2..bc735428e 100644 --- a/spec/register.js +++ b/spec/register.js @@ -1,7 +1,6 @@ (function (root, factory) { - define(["jasmine", "mock", "converse-core", "test-utils"], factory); -} (this, function (jasmine, mock, converse, test_utils) { - var $ = converse.env.jQuery; + define(["jquery.noconflict", "jasmine", "mock", "converse-core", "test-utils"], factory); +} (this, function ($, jasmine, mock, converse, test_utils) { var Strophe = converse.env.Strophe; var $iq = converse.env.$iq; diff --git a/spec/roomslist.js b/spec/roomslist.js index 0c3b6bb47..5ca032e17 100644 --- a/spec/roomslist.js +++ b/spec/roomslist.js @@ -7,12 +7,13 @@ describe("The converse-roomslist plugin", function () { - it("is shown under a list of open rooms in the \"Rooms\" panel", mock.initConverse( + it("is shown under a list of open rooms in the \"Rooms\" panel", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], { whitelisted_plugins: ['converse-roomslist'], allow_bookmarks: false // Makes testing easier, otherwise we // have to mock stanza traffic. }, - function (_converse) { + function (done, _converse) { test_utils.openControlBox().openRoomsPanel(_converse); var controlbox = _converse.chatboxviews.get('controlbox'); @@ -46,18 +47,20 @@ list = controlbox.el.querySelector('div.rooms-list-container'); expect(_.includes(list.classList, 'hidden')).toBeTruthy(); + done(); } )); }); describe("An room shown in the rooms list", function () { - it("can be closed", mock.initConverse( + it("can be closed", mock.initConverseWithPromises( + null, ['rosterGroupsFetched'], { whitelisted_plugins: ['converse-roomslist'], allow_bookmarks: false // Makes testing easier, otherwise we // have to mock stanza traffic. }, - function (_converse) { + function (done, _converse) { spyOn(window, 'confirm').and.callFake(function () { return true; @@ -76,6 +79,7 @@ room_els = _converse.rooms_list_view.el.querySelectorAll(".open-room"); expect(room_els.length).toBe(0); expect(_converse.chatboxes.length).toBe(1); + done(); })); it("shows unread messages directed at the user", mock.initConverseWithAsync( diff --git a/spec/transcripts.js b/spec/transcripts.js index 83697b22c..e9ad7b2cd 100644 --- a/spec/transcripts.js +++ b/spec/transcripts.js @@ -1,5 +1,6 @@ (function (root, factory) { define([ + "jquery.noconflict", "converse-core", "mock", "test_utils", @@ -7,10 +8,9 @@ "transcripts" ], factory ); -} (this, function (converse, mock, test_utils, utils, transcripts) { +} (this, function ($, converse, mock, test_utils, utils, transcripts) { var Strophe = converse.env.Strophe; var _ = converse.env._; - var $ = converse.env.jQuery; var IGNORED_TAGS = [ 'stream:features', 'auth', diff --git a/spec/xmppstatus.js b/spec/xmppstatus.js index 76181380f..2587dfebc 100644 --- a/spec/xmppstatus.js +++ b/spec/xmppstatus.js @@ -1,7 +1,6 @@ (function (root, factory) { - define(["jasmine", "mock", "converse-core", "test-utils"], factory); -} (this, function (jasmine, mock, converse, test_utils) { - var $ = converse.env.jQuery; + define(["jquery.noconflict", "jasmine", "mock", "converse-core", "test-utils"], factory); +} (this, function ($, jasmine, mock, converse, test_utils) { return describe("The XMPPStatus model", function() { diff --git a/tests/mock.js b/tests/mock.js index eef3b68e2..847dd02d1 100644 --- a/tests/mock.js +++ b/tests/mock.js @@ -2,6 +2,7 @@ define("mock", ['jquery.noconflict', 'converse'], factory); }(this, function ($, converse_api) { var _ = converse_api.env._; + var Promise = converse_api.env.Promise; var Strophe = converse_api.env.Strophe; var $iq = converse_api.env.$iq; var mock = {}; @@ -76,7 +77,7 @@ }; }(); - function initConverse (settings, spies) { + function initConverse (settings, spies, promises) { window.localStorage.clear(); window.sessionStorage.clear(); @@ -105,6 +106,14 @@ return converse; } + mock.initConverseWithPromises = function (spies, promise_names, settings, func) { + return function (done) { + var _converse = initConverse(settings, spies); + var promises = _.map(promise_names, _converse.api.waitUntil); + Promise.all(promises).then(_.partial(func, done, _converse)); + } + }; + mock.initConverseWithConnectionSpies = function (spies, settings, func) { if (_.isFunction(settings)) { var _func = settings;