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 @@
}));
it("can be opened by clicking on the registration tab",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
......@@ -44,7 +44,7 @@
}));
it("allows the user to choose an XMPP provider's domain",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
......@@ -80,7 +80,7 @@
}));
it("will render a registration form as received from the XMPP provider",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
......@@ -136,7 +136,7 @@
}));
it("will set form_type to legacy and submit it as legacy",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
......@@ -193,7 +193,7 @@
}));
it("will set form_type to xform and submit it as xform",
mock.initConverseWithPromises(
mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false,
allow_registration: true },
......
......@@ -14,7 +14,7 @@
describe("The /register commmand", function () {
it("allows you to register your nickname in a room",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
function (done, _converse) {
......@@ -78,7 +78,7 @@
describe("The auto_register_muc_nickname option", function () {
it("allows you to automatically register your nickname when joining a room",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
function (done, _converse) {
......
......@@ -7,7 +7,7 @@
describe("A list of open groupchats", function () {
it("is shown in controlbox", mock.initConverseWithPromises(
it("is shown in controlbox", mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ allow_bookmarks: false // Makes testing easier, otherwise we
// have to mock stanza traffic.
......@@ -47,7 +47,7 @@
));
it("uses bookmarks to determine groupchat names",
mock.initConverseWithPromises(
mock.initConverse(
['send'], ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'},
async function (done, _converse) {
......@@ -113,7 +113,7 @@
describe("A groupchat shown in the groupchats list", function () {
it("is highlighted if its currently open", mock.initConverseWithPromises(
it("is highlighted if its currently open", mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we
......@@ -142,7 +142,7 @@
done();
}));
it("has an info icon which opens a details modal when clicked", mock.initConverseWithPromises(
it("has an info icon which opens a details modal when clicked", mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we
......@@ -249,7 +249,7 @@
done();
}));
it("can be closed", mock.initConverseWithPromises(
it("can be closed", mock.initConverse(
null, ['rosterGroupsFetched'],
{ whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
......@@ -272,10 +272,11 @@
done();
}));
it("shows unread messages directed at the user", mock.initConverseWithAsync(
it("shows unread messages directed at the user", mock.initConverse(
null, null,
{ whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
}, async function (done, _converse) {
}, async (done, _converse) => {
test_utils.openControlBox();
const room_jid = 'kitchen@conference.shakespeare.lit';
......
This diff is collapsed.
......@@ -10,9 +10,9 @@
describe("A spoiler message", function () {
it("can be received with a hint",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
......@@ -47,9 +47,9 @@
}));
it("can be received without a hint",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
test_utils.createContacts(_converse, 'current');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
......@@ -80,9 +80,9 @@
}));
it("can be sent without a hint",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
......@@ -155,9 +155,9 @@
}));
it("can be sent with a hint",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
async (done, _converse) => {
test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched');
......
......@@ -50,7 +50,7 @@
return describe("Transcripts of chat logs", function () {
it("can be used to replay conversations",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
......
......@@ -6,16 +6,16 @@
], factory);
} (this, function (jasmine, mock, test_utils) {
"use strict";
var _ = converse.env._;
var $iq = converse.env.$iq;
var $msg = converse.env.$msg;
var Strophe = converse.env.Strophe;
var u = converse.env.utils;
const _ = converse.env._;
const $iq = converse.env.$iq;
const $msg = converse.env.$msg;
const Strophe = converse.env.Strophe;
const u = converse.env.utils;
return describe("The User Details Modal", function () {
it("can be used to remove a contact",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
......@@ -49,7 +49,7 @@
}));
it("shows an alert when an error happened while removing the contact",
mock.initConverseWithPromises(
mock.initConverse(
null, ['rosterGroupsFetched'], {},
async function (done, _converse) {
......
(function (root, factory) {
define(["jquery", "jasmine", "mock", "test-utils"], factory);
} (this, function ($, jasmine, mock, test_utils) {
define(["jasmine", "mock", "test-utils"], factory);
} (this, function (jasmine, mock, test_utils) {
return describe("The XMPPStatus model", function() {
return describe("The XMPPStatus model", function () {
it("won't send <show>online</show> when setting a custom status message", mock.initConverse(function (_converse) {
it("won't send <show>online</show> when setting a custom status message", mock.initConverse((done, _converse) => {
_converse.xmppstatus.save({'status': 'online'});
spyOn(_converse.connection, 'send');
_converse.api.user.status.message.set("I'm also happy!");
expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree());
expect($stanza.children().length).toBe(3);
expect($stanza.children('status').length).toBe(1);
expect($stanza.children('status').text()).toBe("I'm also happy!");
expect($stanza.children('show').length).toBe(0);
expect($stanza.children('priority').length).toBe(1);
expect($stanza.children('priority').text()).toBe('0');
const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
expect(stanza.childNodes.length).toBe(3);
expect(stanza.querySelectorAll('status').length).toBe(1);
expect(stanza.querySelector('status').textContent).toBe("I'm also happy!");
expect(stanza.querySelectorAll('show').length).toBe(0);
expect(stanza.querySelectorAll('priority').length).toBe(1);
expect(stanza.querySelector('priority').textContent).toBe('0');
done();
}));
});
}));
......@@ -463,7 +463,7 @@ function cleanup () {
}
_converse.initialize = function (settings, callback) {
_converse.initialize = async function (settings, callback) {
settings = !_.isUndefined(settings) ? settings : {};
const init_promise = u.getResolveablePromise();
_.each(PROMISES, addPromise);
......@@ -1212,21 +1212,18 @@ _converse.initialize = function (settings, callback) {
this.connection = settings.connection;
}
if (!_.isUndefined(_converse.connection) &&
_converse.connection.service === 'jasmine tests') {
if (_.get(_converse.connection, 'service') === 'jasmine tests') {
finishInitialization();
return _converse;
} else if (_.isUndefined(i18n)) {
finishInitialization();
} else {
i18n.fetchTranslations(
_converse.locale,
_converse.locales,
u.interpolate(_converse.locales_url, {'locale': _converse.locale}))
.catch(e => _converse.log(e.message, Strophe.LogLevel.FATAL))
.finally(finishInitialization)
.catch(e => _converse.log(e.message, Strophe.LogLevel.FATAL));
} else if (!_.isUndefined(i18n)) {
const url = u.interpolate(_converse.locales_url, {'locale': _converse.locale});
try {
await i18n.fetchTranslations(_converse.locale, _converse.locales, url);
} catch (e) {
_converse.log(e.message, Strophe.LogLevel.FATAL);
}
}
finishInitialization();
return init_promise;
};
......
......@@ -16,6 +16,10 @@ import sizzle from "sizzle";
const u = {};
u.toStanza = function (string) {
return Strophe.xmlHtmlNode(string).firstElementChild;
}
u.getLongestSubstring = function (string, candidates) {
function reducer (accumulator, current_value) {
if (string.startsWith(current_value)) {
......
(function (root, factory) {
define("mock", [], factory);
}(this, function () {
var _ = converse.env._;
var Promise = converse.env.Promise;
var Strophe = converse.env.Strophe;
var moment = converse.env.moment;
var $iq = converse.env.$iq;
var u = converse.env.utils;
const _ = converse.env._;
const Promise = converse.env.Promise;
const Strophe = converse.env.Strophe;
const moment = converse.env.moment;
const $iq = converse.env.$iq;
const u = converse.env.utils;
window.libsignal = {
'SignalProtocolAddress': function (name, device_id) {
......@@ -66,7 +66,7 @@
}
};
var mock = {};
const mock = {};
mock.view_mode = 'overlayed';
// Names from http://www.fakenamegenerator.com/
......@@ -158,7 +158,7 @@
};
}();
function initConverse (settings, spies, promises) {
async function initConverse (settings, spies, promises) {
window.localStorage.clear();
window.sessionStorage.clear();
const el = document.querySelector('#conversejs');
......@@ -173,7 +173,7 @@
});
}
const _converse = converse.initialize(_.extend({
const _converse = await converse.initialize(_.extend({
'i18n': 'en',
'auto_subscribe': false,
'play_sounds': false,
......@@ -196,19 +196,19 @@
} else if (!model.get('vcard_updated') || force) {
jid = model.get('jid') || model.get('muc_jid');
}
var fullname;
let fullname;
if (!jid || jid == 'dummy@localhost') {
jid = 'dummy@localhost';
fullname = 'Max Mustermann' ;
} else {
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
var last = name.length-1;
const name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
const last = name.length-1;
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
fullname = name.join(' ');
}
var vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree;
var result = {
const vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree;
const result = {
'vcard': vcard,
'fullname': _.get(vcard.querySelector('FN'), 'textContent'),
'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'),
......@@ -230,41 +230,21 @@
return _converse;
}
mock.initConverseWithPromises = function (spies, promise_names, settings, func) {
return function (done) {
const _converse = initConverse(settings, spies);
mock.initConverse = function (spies, promise_names=null, settings=null, func) {
if (_.isFunction(spies)) {
func = spies;
spies = null;
promise_names = null
settings = null;
}
return done => {
initConverse(settings, spies).then(_converse => {
const promises = _.map(promise_names, _converse.api.waitUntil);
Promise.all(promises)
.then(_.partial(func, done, _converse))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
});
}
};
mock.initConverseWithConnectionSpies = function (spies, settings, func) {
return function (done) {
return func(done, initConverse(settings, spies));
};
};
mock.initConverseWithAsync = function (settings, func) {
if (_.isFunction(settings)) {
var _func = settings;
settings = func;
func = _func;
}
return function (done) {
return func(done, initConverse(settings));
};
};
mock.initConverse = function (settings, func) {
if (_.isFunction(settings)) {
var _func = settings;
settings = func;
func = _func;
}
return function () {
return func(initConverse(settings));
};
};
return mock;
}));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment