@@ -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;