2013-05-11 14:20:07 +02:00
|
|
|
(function (root, factory) {
|
2017-07-10 21:14:48 +02:00
|
|
|
define("mock", ['jquery.noconflict', 'converse'], factory);
|
|
|
|
}(this, function ($, converse_api) {
|
2017-01-26 10:08:43 +01:00
|
|
|
var _ = converse_api.env._;
|
2017-07-11 10:41:11 +02:00
|
|
|
var Promise = converse_api.env.Promise;
|
2016-11-02 21:19:17 +01:00
|
|
|
var Strophe = converse_api.env.Strophe;
|
|
|
|
var $iq = converse_api.env.$iq;
|
2013-11-02 09:56:20 +01:00
|
|
|
var mock = {};
|
|
|
|
// Names from http://www.fakenamegenerator.com/
|
|
|
|
mock.req_names = [
|
|
|
|
'Louw Spekman', 'Mohamad Stet', 'Dominik Beyer'
|
|
|
|
];
|
|
|
|
mock.pend_names = [
|
|
|
|
'Suleyman van Beusichem', 'Nanja van Yperen', 'Nicole Diederich'
|
|
|
|
];
|
|
|
|
mock.cur_names = [
|
|
|
|
'Max Frankfurter', 'Candice van der Knijff', 'Irini Vlastuin', 'Rinse Sommer', 'Annegreet Gomez',
|
|
|
|
'Robin Schook', 'Marcel Eberhardt', 'Simone Brauer', 'Asmaa Haakman', 'Felix Amsel',
|
|
|
|
'Lena Grunewald', 'Laura Grunewald', 'Mandy Seiler', 'Sven Bosch', 'Nuriye Cuypers'
|
|
|
|
];
|
|
|
|
mock.num_contacts = mock.req_names.length + mock.pend_names.length + mock.cur_names.length;
|
|
|
|
|
2014-08-18 20:37:38 +02:00
|
|
|
mock.groups = {
|
|
|
|
'colleagues': 3,
|
|
|
|
'friends & acquaintences': 3,
|
|
|
|
'Family': 4,
|
|
|
|
'ænemies': 3,
|
|
|
|
'Ungrouped': 2
|
|
|
|
};
|
|
|
|
|
2013-11-02 09:56:20 +01:00
|
|
|
mock.chatroom_names = [
|
|
|
|
'Dyon van de Wege', 'Thomas Kalb', 'Dirk Theissen', 'Felix Hofmann', 'Ka Lek', 'Anne Ebersbacher'
|
|
|
|
];
|
2015-03-01 11:58:07 +01:00
|
|
|
// TODO: need to also test other roles and affiliations
|
|
|
|
mock.chatroom_roles = {
|
|
|
|
'Anne Ebersbacher': { affiliation: "owner", role: "moderator" },
|
|
|
|
'Dirk Theissen': { affiliation: "admin", role: "moderator" },
|
2015-10-31 17:30:06 +01:00
|
|
|
'Dyon van de Wege': { affiliation: "member", role: "occupant" },
|
|
|
|
'Felix Hofmann': { affiliation: "member", role: "occupant" },
|
|
|
|
'Ka Lek': { affiliation: "member", role: "occupant" },
|
|
|
|
'Thomas Kalb': { affiliation: "member", role: "occupant" }
|
2015-03-01 11:58:07 +01:00
|
|
|
};
|
2013-11-02 09:56:20 +01:00
|
|
|
|
2013-11-03 10:36:31 +01:00
|
|
|
mock.event = {
|
|
|
|
'preventDefault': function () {}
|
|
|
|
};
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
mock.mock_connection = function () { // eslint-disable-line wrap-iife
|
2016-11-02 21:19:17 +01:00
|
|
|
return function () {
|
|
|
|
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
|
|
|
|
var c = new Strophe.Connection('jasmine tests');
|
2017-07-21 17:38:08 +02:00
|
|
|
var sendIQ = c.sendIQ;
|
|
|
|
|
|
|
|
c.IQ_stanzas = [];
|
|
|
|
c.IQ_ids = [];
|
|
|
|
c.sendIQ = function (iq, callback, errback) {
|
|
|
|
this.IQ_stanzas.push(iq);
|
|
|
|
var id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
this.IQ_ids.push(id);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2016-11-02 21:19:17 +01:00
|
|
|
c.vcard = {
|
|
|
|
'get': function (callback, jid) {
|
|
|
|
var fullname;
|
|
|
|
if (!jid) {
|
|
|
|
jid = 'dummy@localhost';
|
|
|
|
fullname = 'Max Mustermann' ;
|
|
|
|
} else {
|
|
|
|
var name = jid.split('@')[0].replace(/\./g, ' ').split(' ');
|
|
|
|
var 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);
|
|
|
|
callback(vcard.tree());
|
2014-10-24 18:58:42 +02:00
|
|
|
}
|
2016-11-02 21:19:17 +01:00
|
|
|
};
|
|
|
|
c._proto._connect = function () {
|
|
|
|
c.authenticated = true;
|
|
|
|
c.connected = true;
|
|
|
|
c.mock = true;
|
|
|
|
c.jid = 'dummy@localhost/resource';
|
|
|
|
c._changeConnectStatus(Strophe.Status.CONNECTED);
|
|
|
|
};
|
|
|
|
return c;
|
2014-10-24 18:58:42 +02:00
|
|
|
};
|
|
|
|
}();
|
2016-11-02 21:19:17 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
function initConverse (settings, spies, promises) {
|
2017-04-05 11:01:31 +02:00
|
|
|
window.localStorage.clear();
|
|
|
|
window.sessionStorage.clear();
|
2017-05-08 20:44:35 +02:00
|
|
|
|
|
|
|
var connection = mock.mock_connection();
|
|
|
|
if (!_.isUndefined(spies)) {
|
|
|
|
_.forEach(spies, function (method) {
|
|
|
|
spyOn(connection, method);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-15 15:15:37 +02:00
|
|
|
var _converse = converse_api.initialize(_.extend({
|
2017-05-08 20:44:35 +02:00
|
|
|
'i18n': 'en',
|
|
|
|
'auto_subscribe': false,
|
2017-06-14 20:14:45 +02:00
|
|
|
'play_sounds': false,
|
2017-05-08 20:44:35 +02:00
|
|
|
'bosh_service_url': 'localhost',
|
|
|
|
'connection': connection,
|
|
|
|
'animate': false,
|
|
|
|
'no_trimming': true,
|
|
|
|
'auto_login': true,
|
|
|
|
'jid': 'dummy@localhost',
|
|
|
|
'password': 'secret',
|
|
|
|
'debug': false
|
2017-04-05 11:01:31 +02:00
|
|
|
}, settings || {}));
|
2017-07-15 15:15:37 +02:00
|
|
|
_converse.ChatBoxViews.prototype.trimChat = function () {};
|
|
|
|
_converse.disable_effects = true;
|
2017-07-10 21:14:48 +02:00
|
|
|
$.fx.off = true;
|
2017-07-15 15:15:37 +02:00
|
|
|
return _converse;
|
2017-04-05 11:01:31 +02:00
|
|
|
}
|
2017-05-08 20:44:35 +02:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
mock.initConverseWithPromises = function (spies, promise_names, settings, func) {
|
|
|
|
return function (done) {
|
|
|
|
var _converse = initConverse(settings, spies);
|
|
|
|
var promises = _.map(promise_names, _converse.api.waitUntil);
|
2017-07-21 17:38:08 +02:00
|
|
|
Promise.all(promises)
|
|
|
|
.then(_.partial(func, done, _converse))
|
|
|
|
.catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
|
2017-07-11 10:41:11 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-23 18:16:07 +02:00
|
|
|
mock.initConverseWithConnectionSpies = function (spies, settings, func) {
|
2017-07-21 17:38:08 +02:00
|
|
|
return function (done) {
|
|
|
|
return func(done, initConverse(settings, spies));
|
2017-05-08 20:44:35 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-05-16 11:56:33 +02:00
|
|
|
mock.initConverseWithAsync = function (settings, func) {
|
|
|
|
if (_.isFunction(settings)) {
|
|
|
|
var _func = settings;
|
|
|
|
settings = func;
|
|
|
|
func = _func;
|
|
|
|
}
|
2017-04-05 11:01:31 +02:00
|
|
|
return function (done) {
|
|
|
|
return func(done, initConverse(settings));
|
|
|
|
};
|
|
|
|
};
|
2017-05-16 11:56:33 +02:00
|
|
|
mock.initConverse = function (settings, func) {
|
|
|
|
if (_.isFunction(settings)) {
|
|
|
|
var _func = settings;
|
|
|
|
settings = func;
|
|
|
|
func = _func;
|
|
|
|
}
|
2016-11-02 21:19:17 +01:00
|
|
|
return function () {
|
2017-04-05 11:01:31 +02:00
|
|
|
return func(initConverse(settings));
|
2016-11-02 21:19:17 +01:00
|
|
|
};
|
|
|
|
};
|
2013-11-02 09:56:20 +01:00
|
|
|
return mock;
|
2013-05-11 14:20:07 +02:00
|
|
|
}));
|