Commit 9f5031c2 authored by JC Brand's avatar JC Brand

Make `converse.initialize` an `async` function

- Combine all test init functions into `initConverse`
- Use `async` functions in more tests
- Replace `var` with `let` and `const` in more tests
- New utils method `toStanza` which converts a string to a Node
parent fb5c299d
......@@ -62984,7 +62984,7 @@ function cleanup() {
initClientConfig();
}
_converse.initialize = function (settings, callback) {
_converse.initialize = async function (settings, callback) {
settings = !_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(settings) ? settings : {};
const init_promise = _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].getResolveablePromise();
......@@ -63821,17 +63821,22 @@ _converse.initialize = function (settings, callback) {
this.connection = settings.connection;
}
if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_converse.connection) && _converse.connection.service === 'jasmine tests') {
if (_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.get(_converse.connection, 'service') === 'jasmine tests') {
finishInitialization();
return _converse;
} else if (_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_i18n__WEBPACK_IMPORTED_MODULE_6__["default"])) {
finishInitialization();
} else {
_i18n__WEBPACK_IMPORTED_MODULE_6__["default"].fetchTranslations(_converse.locale, _converse.locales, _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].interpolate(_converse.locales_url, {
} else if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_i18n__WEBPACK_IMPORTED_MODULE_6__["default"])) {
const url = _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].interpolate(_converse.locales_url, {
'locale': _converse.locale
})).catch(e => _converse.log(e.message, strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL)).finally(finishInitialization).catch(e => _converse.log(e.message, strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL));
});
try {
await _i18n__WEBPACK_IMPORTED_MODULE_6__["default"].fetchTranslations(_converse.locale, _converse.locales, url);
} catch (e) {
_converse.log(e.message, strophe_js__WEBPACK_IMPORTED_MODULE_0__["Strophe"].LogLevel.FATAL);
}
}
finishInitialization();
return init_promise;
};
/**
......@@ -69717,6 +69722,10 @@ __webpack_require__.r(__webpack_exports__);
const u = {};
u.toStanza = function (string) {
return strophe_js__WEBPACK_IMPORTED_MODULE_2__["Strophe"].xmlHtmlNode(string).firstElementChild;
};
u.getLongestSubstring = function (string, candidates) {
function reducer(accumulator, current_value) {
if (string.startsWith(current_value)) {
......@@ -16,7 +16,7 @@
describe("The nickname autocomplete feature", function () {
it("shows all autocompletion options when the user presses @",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -60,7 +60,7 @@
}));
it("autocompletes when the user presses tab",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......
......@@ -19,7 +19,7 @@
describe("A chat room", function () {
it("can be bookmarked", mock.initConverseWithPromises(
it("can be bookmarked", mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -141,7 +141,7 @@
}));
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverseWithPromises(
it("will be automatically opened if 'autojoin' is set on the bookmark", mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -173,7 +173,7 @@
describe("when bookmarked", function () {
it("displays that it's bookmarked through its bookmark icon", mock.initConverseWithPromises(
it("displays that it's bookmarked through its bookmark icon", mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -194,7 +194,7 @@
done();
}));
it("can be unbookmarked", mock.initConverseWithPromises(
it("can be unbookmarked", mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -270,7 +270,7 @@
describe("and when autojoin is set", function () {
it("will be be opened and joined automatically upon login", mock.initConverseWithPromises(
it("will be be opened and joined automatically upon login", mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -303,7 +303,7 @@
describe("Bookmarks", function () {
it("can be pushed from the XMPP server", mock.initConverseWithPromises(
it("can be pushed from the XMPP server", mock.initConverse(
['send'], ['rosterGroupsFetched', 'connected'], {},
async function (done, _converse) {
......@@ -361,7 +361,7 @@
}));
it("can be retrieved from the XMPP server", mock.initConverseWithPromises(
it("can be retrieved from the XMPP server", mock.initConverse(
['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -452,7 +452,7 @@
describe("The rooms panel", function () {
it("shows a list of bookmarks", mock.initConverseWithPromises(
it("shows a list of bookmarks", mock.initConverse(
['send'], ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -540,7 +540,7 @@
}));
it("remembers the toggle state of the bookmarks list", mock.initConverseWithPromises(
it("remembers the toggle state of the bookmarks list", mock.initConverse(
['send'], ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -606,7 +606,7 @@
describe("When hide_open_bookmarks is true and a bookmarked room is opened", function () {
it("can be closed", mock.initConverseWithPromises(
it("can be closed", mock.initConverse(
null, ['rosterGroupsFetched'],
{ hide_open_bookmarks: true },
async function (done, _converse) {
......
This diff is collapsed.
......@@ -12,7 +12,7 @@
describe("The Controlbox", function () {
it("can be opened by clicking a DOM element with class 'toggle-controlbox'",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -35,7 +35,7 @@
describe("The \"Contacts\" section", function () {
it("can be used to add contact and it checks for case-sensivity",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -63,7 +63,7 @@
}));
it("shows the number of unread mentions received",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -113,7 +113,7 @@
describe("The Status Widget", function () {
it("shows the user's chat status, which is online by default",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -125,7 +125,7 @@
}));
it("can be used to set the current user's chat status",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -149,7 +149,7 @@
}));
it("can be used to set a custom status message",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -178,7 +178,7 @@
describe("The 'Add Contact' widget", function () {
it("opens up an add modal when you click on it",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -215,7 +215,7 @@
it("integrates with xhr_user_search_url to search for contacts",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'],
{ 'xhr_user_search': true,
'xhr_user_search_url': 'http://example.org/'
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
describe("Whenever converse.js queries a server for its features", function () {
it("stores the features it receives",
mock.initConverseWithPromises(
mock.initConverse(
null, ['discoInitialized'], {},
function (done, _converse) {
......@@ -183,7 +183,7 @@
describe("Whenever converse.js discovers a new server feature", function () {
it("emits the serviceDiscovered event",
mock.initConverseWithPromises(
mock.initConverse(
null, ['discoInitialized'], {},
function (done, _converse) {
......
......@@ -4,7 +4,7 @@
return describe("The _converse Event Emitter", function() {
it("allows you to subscribe to emitted events", mock.initConverse(function (_converse) {
it("allows you to subscribe to emitted events", mock.initConverse((done, _converse) => {
this.callback = function () {};
spyOn(this, 'callback');
_converse.on('connected', this.callback);
......@@ -14,9 +14,10 @@
expect(this.callback.calls.count(), 2);
_converse.emit('connected');
expect(this.callback.calls.count(), 3);
done();
}));
it("allows you to listen once for an emitted event", mock.initConverse(function (_converse) {
it("allows you to listen once for an emitted event", mock.initConverse((done, _converse) => {
this.callback = function () {};
spyOn(this, 'callback');
_converse.once('connected', this.callback);
......@@ -26,9 +27,10 @@
expect(this.callback.calls.count(), 1);
_converse.emit('connected');
expect(this.callback.calls.count(), 1);
done();
}));
it("allows you to stop listening or subscribing to an event", mock.initConverse(function (_converse) {
it("allows you to stop listening or subscribing to an event", mock.initConverse((done, _converse) => {
this.callback = function () {};
this.anotherCallback = function () {};
this.neverCalled = function () {};
......@@ -56,6 +58,7 @@
expect(this.callback.calls.count(), 1);
expect(this.anotherCallback.calls.count(), 3);
expect(this.neverCalled).not.toHaveBeenCalled();
done();
}));
});
}));
......@@ -13,7 +13,7 @@
describe("A headlines box", function () {
it("will not open nor display non-headline messages", mock.initConverse(function (_converse) {
it("will not open nor display non-headline messages", mock.initConverse((done, _converse) => {
/* XMPP spam message:
*
* <message xmlns="jabber:client"
......@@ -37,9 +37,10 @@
expect(utils.isHeadlineMessage.called).toBeTruthy();
expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
utils.isHeadlineMessage.restore();
done();
}));
it("will open and display headline messages", mock.initConverseWithPromises(
it("will open and display headline messages", mock.initConverse(
null, ['rosterGroupsFetched'], {}, function (done, _converse) {
/* <message from='notify.example.com'
......@@ -84,7 +85,7 @@
}));
it("will not show a headline messages from a full JID if allow_non_roster_messaging is false",
mock.initConverse(function (_converse) {
mock.initConverse((done, _converse) => {
_converse.allow_non_roster_messaging = false;
sinon.spy(utils, 'isHeadlineMessage');
......@@ -101,6 +102,7 @@
expect(utils.isHeadlineMessage.called).toBeTruthy();
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
utils.isHeadlineMessage.restore(); // unwraps
done();
}));
});
}));
This diff is collapsed.
......@@ -5,7 +5,7 @@
describe("The Login Form", function () {
it("contains a checkbox to indicate whether the computer is trusted or not",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: false },
......@@ -43,7 +43,7 @@
}));
it("checkbox can be set to false by default",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
trusted: false,
......
This diff is collapsed.
This diff is collapsed.
......@@ -9,7 +9,7 @@
describe("The Minimized Chats Widget", function () {
it("shows chats that have been minimized",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -48,7 +48,7 @@
}));
it("can be toggled to hide or show minimized chats",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -79,7 +79,7 @@
}));
it("shows the number messages received to minimized chats",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) {
......@@ -158,7 +158,7 @@
}));
it("shows the number messages received to minimized groupchats",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......
This diff is collapsed.
......@@ -14,9 +14,9 @@
describe("an HTML5 Notification", function () {
it("is shown when a new private message is received",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
// TODO: not yet testing show_desktop_notifications setting
test_utils.createContacts(_converse, 'current');
......@@ -42,9 +42,9 @@
}));
it("is shown when you are mentioned in a groupchat",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
await test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
......@@ -83,9 +83,9 @@
}));
it("is shown for headline messages",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
spyOn(_converse, 'showMessageNotification').and.callThrough();
spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true);
......@@ -112,11 +112,11 @@
done();
}));
it("is not shown for full JID headline messages if allow_non_roster_messaging is false", mock.initConverse(function (_converse) {
it("is not shown for full JID headline messages if allow_non_roster_messaging is false", mock.initConverse((done, _converse) => {
_converse.allow_non_roster_messaging = false;
spyOn(_converse, 'showMessageNotification').and.callThrough();
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
var stanza = $msg({
const stanza = $msg({
'type': 'headline',
'from': 'someone@notify.example.com',
'to': 'dummy@localhost',
......@@ -132,30 +132,33 @@
'someone@notify.example.com')
).toBeFalsy();
expect(_converse.showMessageNotification).not.toHaveBeenCalled();
done();
}));
it("is shown when a user changes their chat state (if show_chatstate_notifications is true)", mock.initConverse(function (_converse) {
it("is shown when a user changes their chat state (if show_chatstate_notifications is true)", mock.initConverse((done, _converse) => {
// TODO: not yet testing show_desktop_notifications setting
_converse.show_chatstate_notifications = true;
test_utils.createContacts(_converse, 'current');
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'showChatStateNotification');
var jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
const jid = mock.cur_names[2].replace(/ /g,'.').toLowerCase() + '@localhost';
_converse.roster.get(jid).presence.set('show', 'busy'); // This will emit 'contactStatusChanged'
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showChatStateNotification).toHaveBeenCalled();
done()
}));
});
});
describe("When a new contact request is received", function () {
it("an HTML5 Notification is received", mock.initConverse(function (_converse) {
it("an HTML5 Notification is received", mock.initConverse((done, _converse) => {
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'showContactRequestNotification');
_converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showContactRequestNotification).toHaveBeenCalled();
done();
}));
});
});
......@@ -164,9 +167,9 @@
describe("A notification sound", function () {
it("is played when the current user is mentioned in a groupchat",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
......
......@@ -76,7 +76,7 @@
describe("The OMEMO module", function() {
it("adds methods for encrypting and decrypting messages via AES GCM",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -93,7 +93,7 @@
it("enables encrypted messages to be sent and received",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -233,7 +233,7 @@
}));
it("enables encrypted groupchat messages to be sent and received",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -377,7 +377,7 @@
}));
it("gracefully handles auth errors when trying to send encrypted groupchat messages",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -506,7 +506,7 @@
}));
it("can receive a PreKeySignalMessage",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -607,7 +607,7 @@
it("updates device lists based on PEP messages",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true},
async function (done, _converse) {
......@@ -771,7 +771,7 @@
it("updates device bundles based on PEP messages",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......@@ -921,7 +921,7 @@
}));
it("publishes a bundle with which an encrypted session can be created",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -1000,7 +1000,7 @@
it("adds a toolbar button for starting an encrypted chat session",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -1165,7 +1165,7 @@
}));
it("adds a toolbar button for starting an encrypted groupchat session",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'},
async function (done, _converse) {
......@@ -1347,7 +1347,7 @@
it("shows OMEMO device fingerprints in the user details modal",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -1447,7 +1447,7 @@
describe("A chatbox with an active OMEMO session", function() {
it("will not show the spoiler toolbar button",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
// TODO
......
......@@ -7,7 +7,7 @@
describe("Ping and pong handlers", function () {
it("are registered when _converse.js is connected",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -20,7 +20,7 @@
}));
it("are registered when _converse.js reconnected",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -35,9 +35,9 @@
describe("An IQ stanza", function () {
it("is sent out when _converse.js pings a server", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ;
it("is sent out when _converse.js pings a server", mock.initConverse((done, _converse) => {
let sent_stanza, IQ_id;
const sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
......@@ -47,6 +47,7 @@
`<iq id="${IQ_id}" to="localhost" type="get" xmlns="jabber:client">`+
`<ping xmlns="urn:xmpp:ping"/>`+
`</iq>`);
done();
}));
});
});
......
This diff is collapsed.
......@@ -7,7 +7,7 @@
describe("Profiling", function() {
xit("adds hundreds of contacts to the roster",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -51,7 +51,7 @@
}));
xit("adds hundreds of contacts to the roster, with roster groups",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......
......@@ -49,7 +49,7 @@
* stanza of type "result".
*/
it("Subscribe to contact, contact accepts and subscribes back",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'],
{ roster_groups: false },
async function (done, _converse) {
......@@ -366,7 +366,7 @@
}));
it("Alternate Flow: Contact Declines Subscription Request",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......@@ -453,7 +453,7 @@
}));
it("Unsubscribe to a contact when subscription is mutual",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'],
{ roster_groups: false },
async function (done, _converse) {
......@@ -512,7 +512,7 @@
done();
}));
it("Receiving a subscription request", mock.initConverseWithPromises(
it("Receiving a subscription request", mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......
......@@ -10,7 +10,7 @@
describe("XEP-0357 Push Notifications", function () {
it("can be enabled",
mock.initConverseWithPromises(null,
mock.initConverse(null,
['rosterGroupsFetched'], {
'push_app_servers': [{
'jid': 'push-5@client.example',
......@@ -49,7 +49,7 @@
}));
it("can be enabled for a MUC domain",
mock.initConverseWithPromises(null,
mock.initConverse(null,
['rosterGroupsFetched'], {
'enable_muc_push': true,
'push_app_servers': [{
......@@ -89,7 +89,7 @@
}));
it("can be disabled",
mock.initConverseWithPromises(null,
mock.initConverse(null,
['rosterGroupsFetched'], {
'push_app_servers': [{
'jid': 'push-5@client.example',
......@@ -126,7 +126,7 @@
it("can require a secret token to be included",
mock.initConverseWithPromises(null,
mock.initConverse(null,
['rosterGroupsFetched'], {
'push_app_servers': [{
'jid': 'push-5@client.example',
......
......@@ -9,7 +9,7 @@
describe("The Registration Panel", function () {
it("is not available unless allow_registration=true",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: false },
......@@ -23,7 +23,7 @@
}));