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() { ...@@ -62984,7 +62984,7 @@ function cleanup() {
initClientConfig(); initClientConfig();
} }
_converse.initialize = function (settings, callback) { _converse.initialize = async function (settings, callback) {
settings = !_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(settings) ? settings : {}; 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(); const init_promise = _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].getResolveablePromise();
...@@ -63821,17 +63821,22 @@ _converse.initialize = function (settings, callback) { ...@@ -63821,17 +63821,22 @@ _converse.initialize = function (settings, callback) {
this.connection = settings.connection; 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(); finishInitialization();
return _converse; return _converse;
} else if (_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_i18n__WEBPACK_IMPORTED_MODULE_6__["default"])) { } else if (!_lodash_noconflict__WEBPACK_IMPORTED_MODULE_4___default.a.isUndefined(_i18n__WEBPACK_IMPORTED_MODULE_6__["default"])) {
finishInitialization(); const url = _converse_headless_utils_core__WEBPACK_IMPORTED_MODULE_11__["default"].interpolate(_converse.locales_url, {
} 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, {
'locale': _converse.locale '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; return init_promise;
}; };
/** /**
...@@ -69717,6 +69722,10 @@ __webpack_require__.r(__webpack_exports__); ...@@ -69717,6 +69722,10 @@ __webpack_require__.r(__webpack_exports__);
const u = {}; const u = {};
u.toStanza = function (string) {
return strophe_js__WEBPACK_IMPORTED_MODULE_2__["Strophe"].xmlHtmlNode(string).firstElementChild;
};
u.getLongestSubstring = function (string, candidates) { u.getLongestSubstring = function (string, candidates) {
function reducer(accumulator, current_value) { function reducer(accumulator, current_value) {
if (string.startsWith(current_value)) { if (string.startsWith(current_value)) {
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
describe("The nickname autocomplete feature", function () { describe("The nickname autocomplete feature", function () {
it("shows all autocompletion options when the user presses @", it("shows all autocompletion options when the user presses @",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
})); }));
it("autocompletes when the user presses tab", it("autocompletes when the user presses tab",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
describe("A chat room", function () { describe("A chat room", function () {
it("can be bookmarked", mock.initConverseWithPromises( it("can be bookmarked", mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -141,7 +141,7 @@ ...@@ -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'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
describe("when bookmarked", function () { 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'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -194,7 +194,7 @@ ...@@ -194,7 +194,7 @@
done(); done();
})); }));
it("can be unbookmarked", mock.initConverseWithPromises( it("can be unbookmarked", mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -270,7 +270,7 @@ ...@@ -270,7 +270,7 @@
describe("and when autojoin is set", function () { 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'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -303,7 +303,7 @@ ...@@ -303,7 +303,7 @@
describe("Bookmarks", function () { 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'], {}, ['send'], ['rosterGroupsFetched', 'connected'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -361,7 +361,7 @@ ...@@ -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'], {}, ['send'], ['chatBoxesFetched', 'roomsPanelRendered', 'rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -452,7 +452,7 @@ ...@@ -452,7 +452,7 @@
describe("The rooms panel", function () { describe("The rooms panel", function () {
it("shows a list of bookmarks", mock.initConverseWithPromises( it("shows a list of bookmarks", mock.initConverse(
['send'], ['rosterGroupsFetched'], {}, ['send'], ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -540,7 +540,7 @@ ...@@ -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'], {}, ['send'], ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -606,7 +606,7 @@ ...@@ -606,7 +606,7 @@
describe("When hide_open_bookmarks is true and a bookmarked room is opened", function () { 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'], null, ['rosterGroupsFetched'],
{ hide_open_bookmarks: true }, { hide_open_bookmarks: true },
async function (done, _converse) { async function (done, _converse) {
......
This diff is collapsed.
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
describe("The Controlbox", function () { describe("The Controlbox", function () {
it("can be opened by clicking a DOM element with class 'toggle-controlbox'", it("can be opened by clicking a DOM element with class 'toggle-controlbox'",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
describe("The \"Contacts\" section", function () { describe("The \"Contacts\" section", function () {
it("can be used to add contact and it checks for case-sensivity", it("can be used to add contact and it checks for case-sensivity",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
})); }));
it("shows the number of unread mentions received", it("shows the number of unread mentions received",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
describe("The Status Widget", function () { describe("The Status Widget", function () {
it("shows the user's chat status, which is online by default", it("shows the user's chat status, which is online by default",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
})); }));
it("can be used to set the current user's chat status", it("can be used to set the current user's chat status",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -149,7 +149,7 @@ ...@@ -149,7 +149,7 @@
})); }));
it("can be used to set a custom status message", it("can be used to set a custom status message",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -178,7 +178,7 @@ ...@@ -178,7 +178,7 @@
describe("The 'Add Contact' widget", function () { describe("The 'Add Contact' widget", function () {
it("opens up an add modal when you click on it", it("opens up an add modal when you click on it",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -215,7 +215,7 @@ ...@@ -215,7 +215,7 @@
it("integrates with xhr_user_search_url to search for contacts", it("integrates with xhr_user_search_url to search for contacts",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], null, ['rosterGroupsFetched'],
{ 'xhr_user_search': true, { 'xhr_user_search': true,
'xhr_user_search_url': 'http://example.org/' 'xhr_user_search_url': 'http://example.org/'
......
This diff is collapsed.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
describe("Whenever converse.js queries a server for its features", function () { describe("Whenever converse.js queries a server for its features", function () {
it("stores the features it receives", it("stores the features it receives",
mock.initConverseWithPromises( mock.initConverse(
null, ['discoInitialized'], {}, null, ['discoInitialized'], {},
function (done, _converse) { function (done, _converse) {
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
describe("Whenever converse.js discovers a new server feature", function () { describe("Whenever converse.js discovers a new server feature", function () {
it("emits the serviceDiscovered event", it("emits the serviceDiscovered event",
mock.initConverseWithPromises( mock.initConverse(
null, ['discoInitialized'], {}, null, ['discoInitialized'], {},
function (done, _converse) { function (done, _converse) {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
return describe("The _converse Event Emitter", function() { 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 () {}; this.callback = function () {};
spyOn(this, 'callback'); spyOn(this, 'callback');
_converse.on('connected', this.callback); _converse.on('connected', this.callback);
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
expect(this.callback.calls.count(), 2); expect(this.callback.calls.count(), 2);
_converse.emit('connected'); _converse.emit('connected');
expect(this.callback.calls.count(), 3); 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 () {}; this.callback = function () {};
spyOn(this, 'callback'); spyOn(this, 'callback');
_converse.once('connected', this.callback); _converse.once('connected', this.callback);
...@@ -26,9 +27,10 @@ ...@@ -26,9 +27,10 @@
expect(this.callback.calls.count(), 1); expect(this.callback.calls.count(), 1);
_converse.emit('connected'); _converse.emit('connected');
expect(this.callback.calls.count(), 1); 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.callback = function () {};
this.anotherCallback = function () {}; this.anotherCallback = function () {};
this.neverCalled = function () {}; this.neverCalled = function () {};
...@@ -56,6 +58,7 @@ ...@@ -56,6 +58,7 @@
expect(this.callback.calls.count(), 1); expect(this.callback.calls.count(), 1);
expect(this.anotherCallback.calls.count(), 3); expect(this.anotherCallback.calls.count(), 3);
expect(this.neverCalled).not.toHaveBeenCalled(); expect(this.neverCalled).not.toHaveBeenCalled();
done();
})); }));
}); });
})); }));
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
describe("A headlines box", function () { 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: /* XMPP spam message:
* *
* <message xmlns="jabber:client" * <message xmlns="jabber:client"
...@@ -37,9 +37,10 @@ ...@@ -37,9 +37,10 @@
expect(utils.isHeadlineMessage.called).toBeTruthy(); expect(utils.isHeadlineMessage.called).toBeTruthy();
expect(utils.isHeadlineMessage.returned(false)).toBeTruthy(); expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
utils.isHeadlineMessage.restore(); 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) { null, ['rosterGroupsFetched'], {}, function (done, _converse) {
/* <message from='notify.example.com' /* <message from='notify.example.com'
...@@ -84,7 +85,7 @@ ...@@ -84,7 +85,7 @@
})); }));
it("will not show a headline messages from a full JID if allow_non_roster_messaging is false", 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; _converse.allow_non_roster_messaging = false;
sinon.spy(utils, 'isHeadlineMessage'); sinon.spy(utils, 'isHeadlineMessage');
...@@ -101,6 +102,7 @@ ...@@ -101,6 +102,7 @@
expect(utils.isHeadlineMessage.called).toBeTruthy(); expect(utils.isHeadlineMessage.called).toBeTruthy();
expect(utils.isHeadlineMessage.returned(true)).toBeTruthy(); expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
utils.isHeadlineMessage.restore(); // unwraps utils.isHeadlineMessage.restore(); // unwraps
done();
})); }));
}); });
})); }));
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
describe("The Login Form", function () { describe("The Login Form", function () {
it("contains a checkbox to indicate whether the computer is trusted or not", it("contains a checkbox to indicate whether the computer is trusted or not",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: false }, allow_registration: false },
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
})); }));
it("checkbox can be set to false by default", it("checkbox can be set to false by default",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
trusted: false, trusted: false,
......
This diff is collapsed.
This diff is collapsed.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
describe("The Minimized Chats Widget", function () { describe("The Minimized Chats Widget", function () {
it("shows chats that have been minimized", it("shows chats that have been minimized",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
})); }));
it("can be toggled to hide or show minimized chats", it("can be toggled to hide or show minimized chats",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
})); }));
it("shows the number messages received to minimized chats", it("shows the number messages received to minimized chats",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
})); }));
it("shows the number messages received to minimized groupchats", it("shows the number messages received to minimized groupchats",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
......
This diff is collapsed.
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
describe("an HTML5 Notification", function () { describe("an HTML5 Notification", function () {
it("is shown when a new private message is received", it("is shown when a new private message is received",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async (done, _converse) => {
// TODO: not yet testing show_desktop_notifications setting // TODO: not yet testing show_desktop_notifications setting
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
...@@ -42,9 +42,9 @@ ...@@ -42,9 +42,9 @@
})); }));
it("is shown when you are mentioned in a groupchat", it("is shown when you are mentioned in a groupchat",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async (done, _converse) => {
await test_utils.createContacts(_converse, 'current'); await test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
...@@ -83,9 +83,9 @@ ...@@ -83,9 +83,9 @@
})); }));
it("is shown for headline messages", it("is shown for headline messages",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async (done, _converse) => {
spyOn(_converse, 'showMessageNotification').and.callThrough(); spyOn(_converse, 'showMessageNotification').and.callThrough();
spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true); spyOn(_converse, 'isMessageToHiddenChat').and.returnValue(true);
...@@ -112,11 +112,11 @@ ...@@ -112,11 +112,11 @@
done(); 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; _converse.allow_non_roster_messaging = false;
spyOn(_converse, 'showMessageNotification').and.callThrough(); spyOn(_converse, 'showMessageNotification').and.callThrough();
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true); spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
var stanza = $msg({ const stanza = $msg({
'type': 'headline', 'type': 'headline',
'from': 'someone@notify.example.com', 'from': 'someone@notify.example.com',
'to': 'dummy@localhost', 'to': 'dummy@localhost',
...@@ -132,30 +132,33 @@ ...@@ -132,30 +132,33 @@
'someone@notify.example.com') 'someone@notify.example.com')
).toBeFalsy(); ).toBeFalsy();
expect(_converse.showMessageNotification).not.toHaveBeenCalled(); 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 // TODO: not yet testing show_desktop_notifications setting
_converse.show_chatstate_notifications = true; _converse.show_chatstate_notifications = true;
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true); spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'showChatStateNotification'); 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' _converse.roster.get(jid).presence.set('show', 'busy'); // This will emit 'contactStatusChanged'
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled(); expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showChatStateNotification).toHaveBeenCalled(); expect(_converse.showChatStateNotification).toHaveBeenCalled();
done()
})); }));
}); });
}); });
describe("When a new contact request is received", function () { 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, 'areDesktopNotificationsEnabled').and.returnValue(true);
spyOn(_converse, 'showContactRequestNotification'); spyOn(_converse, 'showContactRequestNotification');
_converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'}); _converse.emit('contactRequest', {'fullname': 'Peter Parker', 'jid': 'peter@parker.com'});
expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled(); expect(_converse.areDesktopNotificationsEnabled).toHaveBeenCalled();
expect(_converse.showContactRequestNotification).toHaveBeenCalled(); expect(_converse.showContactRequestNotification).toHaveBeenCalled();
done();
})); }));
}); });
}); });
...@@ -164,9 +167,9 @@ ...@@ -164,9 +167,9 @@
describe("A notification sound", function () { describe("A notification sound", function () {
it("is played when the current user is mentioned in a groupchat", it("is played when the current user is mentioned in a groupchat",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async (done, _converse) => {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy'); await test_utils.openAndEnterChatRoom(_converse, 'lounge', 'localhost', 'dummy');
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
describe("The OMEMO module", function() { describe("The OMEMO module", function() {
it("adds methods for encrypting and decrypting messages via AES GCM", it("adds methods for encrypting and decrypting messages via AES GCM",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
it("enables encrypted messages to be sent and received", it("enables encrypted messages to be sent and received",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
})); }));
it("enables encrypted groupchat messages to be sent and received", it("enables encrypted groupchat messages to be sent and received",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -377,7 +377,7 @@ ...@@ -377,7 +377,7 @@
})); }));
it("gracefully handles auth errors when trying to send encrypted groupchat messages", it("gracefully handles auth errors when trying to send encrypted groupchat messages",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -506,7 +506,7 @@ ...@@ -506,7 +506,7 @@
})); }));
it("can receive a PreKeySignalMessage", it("can receive a PreKeySignalMessage",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -607,7 +607,7 @@ ...@@ -607,7 +607,7 @@
it("updates device lists based on PEP messages", it("updates device lists based on PEP messages",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true}, null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true},
async function (done, _converse) { async function (done, _converse) {
...@@ -771,7 +771,7 @@ ...@@ -771,7 +771,7 @@
it("updates device bundles based on PEP messages", it("updates device bundles based on PEP messages",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -921,7 +921,7 @@ ...@@ -921,7 +921,7 @@
})); }));
it("publishes a bundle with which an encrypted session can be created", it("publishes a bundle with which an encrypted session can be created",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -1000,7 +1000,7 @@ ...@@ -1000,7 +1000,7 @@
it("adds a toolbar button for starting an encrypted chat session", it("adds a toolbar button for starting an encrypted chat session",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -1165,7 +1165,7 @@ ...@@ -1165,7 +1165,7 @@
})); }));
it("adds a toolbar button for starting an encrypted groupchat session", it("adds a toolbar button for starting an encrypted groupchat session",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'},
async function (done, _converse) { async function (done, _converse) {
...@@ -1347,7 +1347,7 @@ ...@@ -1347,7 +1347,7 @@
it("shows OMEMO device fingerprints in the user details modal", it("shows OMEMO device fingerprints in the user details modal",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -1447,7 +1447,7 @@ ...@@ -1447,7 +1447,7 @@
describe("A chatbox with an active OMEMO session", function() { describe("A chatbox with an active OMEMO session", function() {
it("will not show the spoiler toolbar button", it("will not show the spoiler toolbar button",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
// TODO // TODO
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
describe("Ping and pong handlers", function () { describe("Ping and pong handlers", function () {
it("are registered when _converse.js is connected", it("are registered when _converse.js is connected",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
})); }));
it("are registered when _converse.js reconnected", it("are registered when _converse.js reconnected",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
describe("An IQ stanza", function () { describe("An IQ stanza", function () {
it("is sent out when _converse.js pings a server", mock.initConverse(function (_converse) { it("is sent out when _converse.js pings a server", mock.initConverse((done, _converse) => {
var sent_stanza, IQ_id; let sent_stanza, IQ_id;
var sendIQ = _converse.connection.sendIQ; const sendIQ = _converse.connection.sendIQ;
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) { spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
sent_stanza = iq; sent_stanza = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback); IQ_id = sendIQ.bind(this)(iq, callback, errback);
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
`<iq id="${IQ_id}" to="localhost" type="get" xmlns="jabber:client">`+ `<iq id="${IQ_id}" to="localhost" type="get" xmlns="jabber:client">`+
`<ping xmlns="urn:xmpp:ping"/>`+ `<ping xmlns="urn:xmpp:ping"/>`+
`</iq>`); `</iq>`);
done();
})); }));
}); });
}); });
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
describe("Profiling", function() { describe("Profiling", function() {
xit("adds hundreds of contacts to the roster", xit("adds hundreds of contacts to the roster",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
})); }));
xit("adds hundreds of contacts to the roster, with roster groups", xit("adds hundreds of contacts to the roster, with roster groups",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
* stanza of type "result". * stanza of type "result".
*/ */
it("Subscribe to contact, contact accepts and subscribes back", it("Subscribe to contact, contact accepts and subscribes back",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], null, ['rosterGroupsFetched'],
{ roster_groups: false }, { roster_groups: false },
async function (done, _converse) { async function (done, _converse) {
...@@ -366,7 +366,7 @@ ...@@ -366,7 +366,7 @@
})); }));
it("Alternate Flow: Contact Declines Subscription Request", it("Alternate Flow: Contact Declines Subscription Request",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
...@@ -453,7 +453,7 @@ ...@@ -453,7 +453,7 @@
})); }));
it("Unsubscribe to a contact when subscription is mutual", it("Unsubscribe to a contact when subscription is mutual",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], null, ['rosterGroupsFetched'],
{ roster_groups: false }, { roster_groups: false },
async function (done, _converse) { async function (done, _converse) {
...@@ -512,7 +512,7 @@ ...@@ -512,7 +512,7 @@
done(); done();
})); }));
it("Receiving a subscription request", mock.initConverseWithPromises( it("Receiving a subscription request", mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
describe("XEP-0357 Push Notifications", function () { describe("XEP-0357 Push Notifications", function () {
it("can be enabled", it("can be enabled",
mock.initConverseWithPromises(null, mock.initConverse(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'push_app_servers': [{ 'push_app_servers': [{
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
})); }));
it("can be enabled for a MUC domain", it("can be enabled for a MUC domain",
mock.initConverseWithPromises(null, mock.initConverse(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'enable_muc_push': true, 'enable_muc_push': true,
'push_app_servers': [{ 'push_app_servers': [{
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
})); }));
it("can be disabled", it("can be disabled",
mock.initConverseWithPromises(null, mock.initConverse(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'push_app_servers': [{ 'push_app_servers': [{
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
...@@ -126,7 +126,7 @@ ...@@ -126,7 +126,7 @@
it("can require a secret token to be included", it("can require a secret token to be included",
mock.initConverseWithPromises(null, mock.initConverse(null,
['rosterGroupsFetched'], { ['rosterGroupsFetched'], {
'push_app_servers': [{ 'push_app_servers': [{
'jid': 'push-5@client.example', 'jid': 'push-5@client.example',
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
describe("The Registration Panel", function () { describe("The Registration Panel", function () {
it("is not available unless allow_registration=true", it("is not available unless allow_registration=true",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: false }, allow_registration: false },
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
})); }));
it("can be opened by clicking on the registration tab", it("can be opened by clicking on the registration tab",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
})); }));
it("allows the user to choose an XMPP provider's domain", it("allows the user to choose an XMPP provider's domain",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
})); }));
it("will render a registration form as received from the XMPP provider", it("will render a registration form as received from the XMPP provider",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
})); }));
it("will set form_type to legacy and submit it as legacy", it("will set form_type to legacy and submit it as legacy",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
...@@ -193,7 +193,7 @@ ...@@ -193,7 +193,7 @@
})); }));
it("will set form_type to xform and submit it as xform", it("will set form_type to xform and submit it as xform",
mock.initConverseWithPromises( mock.initConverse(
null, ['connectionInitialized', 'chatBoxesInitialized'], null, ['connectionInitialized', 'chatBoxesInitialized'],
{ auto_login: false, { auto_login: false,
allow_registration: true }, allow_registration: true },
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
describe("The /register commmand", function () { describe("The /register commmand", function () {
it("allows you to register your nickname in a room", it("allows you to register your nickname in a room",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
function (done, _converse) { function (done, _converse) {
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
describe("The auto_register_muc_nickname option", function () { describe("The auto_register_muc_nickname option", function () {
it("allows you to automatically register your nickname when joining a room", it("allows you to automatically register your nickname when joining a room",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {'auto_register_muc_nickname': true},
function (done, _converse) { function (done, _converse) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
describe("A list of open groupchats", function () { describe("A list of open groupchats", function () {
it("is shown in controlbox", mock.initConverseWithPromises( it("is shown in controlbox", mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ allow_bookmarks: false // Makes testing easier, otherwise we { allow_bookmarks: false // Makes testing easier, otherwise we
// have to mock stanza traffic. // have to mock stanza traffic.
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
)); ));
it("uses bookmarks to determine groupchat names", it("uses bookmarks to determine groupchat names",
mock.initConverseWithPromises( mock.initConverse(
['send'], ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'}, ['send'], ['rosterGroupsFetched', 'chatBoxesFetched'], {'view_mode': 'fullscreen'},
async function (done, _converse) { async function (done, _converse) {
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
describe("A groupchat shown in the groupchats list", function () { 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'], null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ whitelisted_plugins: ['converse-roomslist'], { whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we allow_bookmarks: false // Makes testing easier, otherwise we
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
done(); 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'], null, ['rosterGroupsFetched', 'chatBoxesFetched'],
{ whitelisted_plugins: ['converse-roomslist'], { whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we allow_bookmarks: false // Makes testing easier, otherwise we
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
done(); done();
})); }));
it("can be closed", mock.initConverseWithPromises( it("can be closed", mock.initConverse(
null, ['rosterGroupsFetched'], null, ['rosterGroupsFetched'],
{ whitelisted_plugins: ['converse-roomslist'], { whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic. allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
...@@ -272,10 +272,11 @@ ...@@ -272,10 +272,11 @@
done(); done();
})); }));
it("shows unread messages directed at the user", mock.initConverseWithAsync( it("shows unread messages directed at the user", mock.initConverse(
{ whitelisted_plugins: ['converse-roomslist'], null, null,
{ whitelisted_plugins: ['converse-roomslist'],
allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic. allow_bookmarks: false // Makes testing easier, otherwise we have to mock stanza traffic.
}, async function (done, _converse) { }, async (done, _converse) => {
test_utils.openControlBox(); test_utils.openControlBox();
const room_jid = 'kitchen@conference.shakespeare.lit'; const room_jid = 'kitchen@conference.shakespeare.lit';
......
This diff is collapsed.
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
describe("A spoiler message", function () { describe("A spoiler message", function () {
it("can be received with a hint", it("can be received with a hint",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async (done, _converse) => {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
...@@ -47,9 +47,9 @@ ...@@ -47,9 +47,9 @@
})); }));
it("can be received without a hint", it("can be received without a hint",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async (done, _converse) => {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const sender_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
...@@ -80,9 +80,9 @@ ...@@ -80,9 +80,9 @@
})); }));
it("can be sent without a hint", it("can be sent without a hint",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async (done, _converse) => {
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
...@@ -155,9 +155,9 @@ ...@@ -155,9 +155,9 @@
})); }));
it("can be sent with a hint", it("can be sent with a hint",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async (done, _converse) => {
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
return describe("Transcripts of chat logs", function () { return describe("Transcripts of chat logs", function () {
it("can be used to replay conversations", it("can be used to replay conversations",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
......
...@@ -6,16 +6,16 @@ ...@@ -6,16 +6,16 @@
], factory); ], factory);
} (this, function (jasmine, mock, test_utils) { } (this, function (jasmine, mock, test_utils) {
"use strict"; "use strict";
var _ = converse.env._; const _ = converse.env._;
var $iq = converse.env.$iq; const $iq = converse.env.$iq;
var $msg = converse.env.$msg; const $msg = converse.env.$msg;
var Strophe = converse.env.Strophe; const Strophe = converse.env.Strophe;
var u = converse.env.utils; const u = converse.env.utils;
return describe("The User Details Modal", function () { return describe("The User Details Modal", function () {
it("can be used to remove a contact", it("can be used to remove a contact",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
})); }));
it("shows an alert when an error happened while removing the contact", it("shows an alert when an error happened while removing the contact",
mock.initConverseWithPromises( mock.initConverse(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
async function (done, _converse) { async function (done, _converse) {
......
(function (root, factory) { (function (root, factory) {
define(["jquery", "jasmine", "mock", "test-utils"], factory); define(["jasmine", "mock", "test-utils"], factory);
} (this, function ($, jasmine, mock, test_utils) { } (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'}); _converse.xmppstatus.save({'status': 'online'});
spyOn(_converse.connection, 'send'); spyOn(_converse.connection, 'send');
_converse.api.user.status.message.set("I'm also happy!"); _converse.api.user.status.message.set("I'm also happy!");
expect(_converse.connection.send).toHaveBeenCalled(); expect(_converse.connection.send).toHaveBeenCalled();
var $stanza = $(_converse.connection.send.calls.argsFor(0)[0].tree()); const stanza = _converse.connection.send.calls.argsFor(0)[0].tree();
expect($stanza.children().length).toBe(3); expect(stanza.childNodes.length).toBe(3);
expect($stanza.children('status').length).toBe(1); expect(stanza.querySelectorAll('status').length).toBe(1);
expect($stanza.children('status').text()).toBe("I'm also happy!"); expect(stanza.querySelector('status').textContent).toBe("I'm also happy!");
expect($stanza.children('show').length).toBe(0); expect(stanza.querySelectorAll('show').length).toBe(0);
expect($stanza.children('priority').length).toBe(1); expect(stanza.querySelectorAll('priority').length).toBe(1);
expect($stanza.children('priority').text()).toBe('0'); expect(stanza.querySelector('priority').textContent).toBe('0');
done();
})); }));
}); });
})); }));
...@@ -463,7 +463,7 @@ function cleanup () { ...@@ -463,7 +463,7 @@ function cleanup () {
} }
_converse.initialize = function (settings, callback) { _converse.initialize = async function (settings, callback) {
settings = !_.isUndefined(settings) ? settings : {}; settings = !_.isUndefined(settings) ? settings : {};
const init_promise = u.getResolveablePromise(); const init_promise = u.getResolveablePromise();
_.each(PROMISES, addPromise); _.each(PROMISES, addPromise);
...@@ -1212,21 +1212,18 @@ _converse.initialize = function (settings, callback) { ...@@ -1212,21 +1212,18 @@ _converse.initialize = function (settings, callback) {
this.connection = settings.connection; this.connection = settings.connection;
} }
if (!_.isUndefined(_converse.connection) && if (_.get(_converse.connection, 'service') === 'jasmine tests') {
_converse.connection.service === 'jasmine tests') {
finishInitialization(); finishInitialization();
return _converse; return _converse;
} else if (_.isUndefined(i18n)) { } else if (!_.isUndefined(i18n)) {
finishInitialization(); const url = u.interpolate(_converse.locales_url, {'locale': _converse.locale});
} else { try {
i18n.fetchTranslations( await i18n.fetchTranslations(_converse.locale, _converse.locales, url);
_converse.locale, } catch (e) {
_converse.locales, _converse.log(e.message, Strophe.LogLevel.FATAL);
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));
} }
finishInitialization();
return init_promise; return init_promise;
}; };
......
...@@ -16,6 +16,10 @@ import sizzle from "sizzle"; ...@@ -16,6 +16,10 @@ import sizzle from "sizzle";
const u = {}; const u = {};
u.toStanza = function (string) {
return Strophe.xmlHtmlNode(string).firstElementChild;
}
u.getLongestSubstring = function (string, candidates) { u.getLongestSubstring = function (string, candidates) {
function reducer (accumulator, current_value) { function reducer (accumulator, current_value) {
if (string.startsWith(current_value)) { if (string.startsWith(current_value)) {
......
(function (root, factory) { (function (root, factory) {
define("mock", [], factory); define("mock", [], factory);
}(this, function () { }(this, function () {
var _ = converse.env._; const _ = converse.env._;
var Promise = converse.env.Promise; const Promise = converse.env.Promise;
var Strophe = converse.env.Strophe; const Strophe = converse.env.Strophe;
var moment = converse.env.moment; const moment = converse.env.moment;
var $iq = converse.env.$iq; const $iq = converse.env.$iq;
var u = converse.env.utils; const u = converse.env.utils;
window.libsignal = { window.libsignal = {
'SignalProtocolAddress': function (name, device_id) { 'SignalProtocolAddress': function (name, device_id) {
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
this.encrypt = () => Promise.resolve({ this.encrypt = () => Promise.resolve({
'type': 1, 'type': 1,
'body': 'c1ph3R73X7', 'body': 'c1ph3R73X7',
'registrationId': '1337' 'registrationId': '1337'
}); });
this.decryptPreKeyWhisperMessage = (key_and_tag) => { this.decryptPreKeyWhisperMessage = (key_and_tag) => {
return Promise.resolve(key_and_tag); return Promise.resolve(key_and_tag);
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
} }
}; };
var mock = {}; const mock = {};
mock.view_mode = 'overlayed'; mock.view_mode = 'overlayed';
// Names from http://www.fakenamegenerator.com/ // Names from http://www.fakenamegenerator.com/
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
}; };
}(); }();
function initConverse (settings, spies, promises) { async function initConverse (settings, spies, promises) {
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear(); window.sessionStorage.clear();
const el = document.querySelector('#conversejs'); const el = document.querySelector('#conversejs');
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
}); });
} }
const _converse = converse.initialize(_.extend({ const _converse = await converse.initialize(_.extend({
'i18n': 'en', 'i18n': 'en',
'auto_subscribe': false, 'auto_subscribe': false,
'play_sounds': false, 'play_sounds': false,
...@@ -196,19 +196,19 @@ ...@@ -196,19 +196,19 @@
} else if (!model.get('vcard_updated') || force) { } else if (!model.get('vcard_updated') || force) {
jid = model.get('jid') || model.get('muc_jid'); jid = model.get('jid') || model.get('muc_jid');
} }
var fullname; let fullname;
if (!jid || jid == 'dummy@localhost') { if (!jid || jid == 'dummy@localhost') {
jid = 'dummy@localhost'; jid = 'dummy@localhost';
fullname = 'Max Mustermann' ; fullname = 'Max Mustermann' ;
} else { } else {
var name = jid.split('@')[0].replace(/\./g, ' ').split(' '); const name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
var last = name.length-1; const last = name.length-1;
name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1); name[0] = name[0].charAt(0).toUpperCase()+name[0].slice(1);
name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1); name[last] = name[last].charAt(0).toUpperCase()+name[last].slice(1);
fullname = name.join(' '); fullname = name.join(' ');
} }
var vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree; const vcard = $iq().c('vCard').c('FN').t(fullname).nodeTree;
var result = { const result = {
'vcard': vcard, 'vcard': vcard,
'fullname': _.get(vcard.querySelector('FN'), 'textContent'), 'fullname': _.get(vcard.querySelector('FN'), 'textContent'),
'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'), 'image': _.get(vcard.querySelector('PHOTO BINVAL'), 'textContent'),
...@@ -230,41 +230,21 @@ ...@@ -230,41 +230,21 @@
return _converse; return _converse;
} }
mock.initConverseWithPromises = function (spies, promise_names, settings, func) { mock.initConverse = function (spies, promise_names=null, settings=null, func) {
return function (done) { if (_.isFunction(spies)) {
const _converse = initConverse(settings, spies); func = spies;
const promises = _.map(promise_names, _converse.api.waitUntil); spies = null;
Promise.all(promises) promise_names = null
.then(_.partial(func, done, _converse)) settings = null;
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
} }
}; return done => {
initConverse(settings, spies).then(_converse => {
mock.initConverseWithConnectionSpies = function (spies, settings, func) { const promises = _.map(promise_names, _converse.api.waitUntil);
return function (done) { Promise.all(promises)
return func(done, initConverse(settings, spies)); .then(_.partial(func, done, _converse))
}; .catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
}; });
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; 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