2013-11-02 09:56:20 +01:00
|
|
|
(function (root, factory) {
|
2014-08-08 22:06:01 +02:00
|
|
|
define("test_utils", [
|
2013-11-02 12:37:38 +01:00
|
|
|
'jquery',
|
|
|
|
'mock'
|
|
|
|
],
|
|
|
|
function($, mock) {
|
|
|
|
return factory($, mock);
|
2013-11-02 09:56:20 +01:00
|
|
|
});
|
2013-11-02 12:37:38 +01:00
|
|
|
}(this, function ($, mock) {
|
2013-11-02 09:56:20 +01:00
|
|
|
var utils = {};
|
|
|
|
|
|
|
|
utils.closeAllChatBoxes = function () {
|
2013-11-03 11:02:25 +01:00
|
|
|
var i, chatbox;
|
|
|
|
for (i=converse.chatboxes.models.length-1; i>-1; i--) {
|
2013-11-02 09:56:20 +01:00
|
|
|
chatbox = converse.chatboxes.models[i];
|
2014-05-27 18:34:22 +02:00
|
|
|
converse.chatboxviews.get(chatbox.get('id')).close();
|
2013-11-02 09:56:20 +01:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.removeAllChatBoxes = function () {
|
|
|
|
var i, chatbox, num_chatboxes = converse.chatboxes.models.length;
|
|
|
|
for (i=num_chatboxes-1; i>-1; i--) {
|
|
|
|
chatbox = converse.chatboxes.models[i];
|
2014-05-27 18:34:22 +02:00
|
|
|
converse.chatboxviews.get(chatbox.get('id')).close();
|
2014-03-04 14:54:36 +01:00
|
|
|
converse.chatboxviews.get(chatbox.get('id')).$el.remove();
|
2013-11-02 09:56:20 +01:00
|
|
|
}
|
2014-05-27 18:34:22 +02:00
|
|
|
converse.chatboxviews.get('controlbox').close();
|
2014-03-04 14:54:36 +01:00
|
|
|
converse.chatboxviews.get('controlbox').$el.remove();
|
2013-11-02 09:56:20 +01:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-11-03 10:38:48 +01:00
|
|
|
utils.initConverse = function () {
|
2014-05-27 19:18:02 +02:00
|
|
|
converse._initialize();
|
2013-11-03 10:38:48 +01:00
|
|
|
converse.onConnected();
|
|
|
|
};
|
|
|
|
|
2013-11-02 09:56:20 +01:00
|
|
|
utils.initRoster = function () {
|
2014-08-03 23:02:25 +02:00
|
|
|
converse.roster.browserStorage._clear();
|
2013-11-02 09:56:20 +01:00
|
|
|
converse.initRoster();
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.openControlBox = function () {
|
2014-06-21 11:32:05 +02:00
|
|
|
var toggle = $(".toggle-controlbox");
|
2013-11-02 09:56:20 +01:00
|
|
|
if (!$("#controlbox").is(':visible')) {
|
2014-02-28 03:04:52 +01:00
|
|
|
if (!toggle.is(':visible')) {
|
|
|
|
toggle.show(toggle.click);
|
|
|
|
} else {
|
|
|
|
toggle.click();
|
|
|
|
}
|
2013-11-02 09:56:20 +01:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-11-03 10:38:48 +01:00
|
|
|
utils.closeControlBox = function () {
|
|
|
|
if ($("#controlbox").is(':visible')) {
|
2014-02-28 03:04:52 +01:00
|
|
|
$("#controlbox").find(".close-chatbox-button").click();
|
2013-11-03 10:38:48 +01:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
utils.removeControlBox = function () {
|
2014-02-28 03:04:52 +01:00
|
|
|
converse.controlboxtoggle.show();
|
2013-11-03 10:38:48 +01:00
|
|
|
$('#controlbox').remove();
|
|
|
|
};
|
|
|
|
|
2013-11-02 09:56:20 +01:00
|
|
|
utils.openContactsPanel = function () {
|
2014-03-04 14:54:36 +01:00
|
|
|
var cbview = converse.chatboxviews.get('controlbox');
|
2013-11-02 09:56:20 +01:00
|
|
|
var $tabs = cbview.$el.find('#controlbox-tabs');
|
|
|
|
$tabs.find('li').first().find('a').click();
|
|
|
|
};
|
|
|
|
|
2013-11-02 12:37:38 +01:00
|
|
|
utils.openRoomsPanel = function () {
|
2014-03-04 14:54:36 +01:00
|
|
|
var cbview = converse.chatboxviews.get('controlbox');
|
2013-11-02 12:37:38 +01:00
|
|
|
var $tabs = cbview.$el.find('#controlbox-tabs');
|
|
|
|
$tabs.find('li').last().find('a').click();
|
|
|
|
};
|
|
|
|
|
2013-11-03 10:38:48 +01:00
|
|
|
utils.openChatBoxes = function (amount) {
|
2014-03-04 12:22:49 +01:00
|
|
|
var i = 0, jid, views = [];
|
2013-11-03 10:38:48 +01:00
|
|
|
for (i; i<amount; i++) {
|
2014-06-30 20:26:45 +02:00
|
|
|
jid = mock.cur_names[i].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2014-08-03 23:02:25 +02:00
|
|
|
views[i] = converse.roster.get(jid).trigger("open");
|
2013-11-03 10:38:48 +01:00
|
|
|
}
|
2014-03-04 12:22:49 +01:00
|
|
|
return views;
|
2013-11-03 10:38:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
utils.openChatBoxFor = function (jid) {
|
2014-08-03 23:02:25 +02:00
|
|
|
return converse.roster.get(jid).trigger("open");
|
2014-08-01 20:09:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
utils.removeRosterContacts = function () {
|
|
|
|
var model;
|
|
|
|
while (converse.rosterview.model.length) {
|
|
|
|
model = converse.rosterview.model.pop();
|
|
|
|
converse.rosterview.model.remove(model);
|
|
|
|
}
|
2013-11-03 10:38:48 +01:00
|
|
|
};
|
|
|
|
|
2014-06-30 19:55:26 +02:00
|
|
|
utils.clearBrowserStorage = function () {
|
|
|
|
window.localStorage.clear();
|
|
|
|
window.sessionStorage.clear();
|
2014-07-04 20:37:37 +02:00
|
|
|
return this;
|
2014-06-30 19:55:26 +02:00
|
|
|
};
|
|
|
|
|
2013-11-03 12:24:18 +01:00
|
|
|
utils.clearChatBoxMessages = function (jid) {
|
2014-03-04 14:54:36 +01:00
|
|
|
var view = converse.chatboxviews.get(jid);
|
2013-11-03 12:24:18 +01:00
|
|
|
view.$el.find('.chat-content').empty();
|
2014-04-19 05:12:24 +02:00
|
|
|
view.model.messages.reset();
|
2014-06-30 19:21:16 +02:00
|
|
|
view.model.messages.browserStorage._clear();
|
2013-11-03 12:24:18 +01:00
|
|
|
};
|
|
|
|
|
2014-07-04 20:37:37 +02:00
|
|
|
utils.createContacts = function (type) {
|
2013-11-02 12:37:38 +01:00
|
|
|
// Create current (as opposed to requesting or pending) contacts
|
|
|
|
// for the user's roster.
|
2014-07-04 20:37:37 +02:00
|
|
|
var names;
|
|
|
|
if (type === 'requesting') {
|
|
|
|
names = mock.req_names;
|
|
|
|
subscription = 'none';
|
|
|
|
requesting = true;
|
|
|
|
ask = null;
|
|
|
|
} else if (type === 'pending') {
|
|
|
|
names = mock.pend_names;
|
|
|
|
subscription = 'none';
|
|
|
|
requesting = false;
|
|
|
|
ask = 'subscribe';
|
|
|
|
} else if (type === 'all') {
|
|
|
|
this.createContacts().createContacts('request').createContacts('pending');
|
|
|
|
return this;
|
|
|
|
} else {
|
|
|
|
names = mock.cur_names;
|
|
|
|
subscription = 'both';
|
|
|
|
requesting = false;
|
|
|
|
ask = null;
|
|
|
|
}
|
|
|
|
for (i=0; i<names.length; i++) {
|
2014-08-03 23:02:25 +02:00
|
|
|
converse.roster.create({
|
2014-07-04 20:37:37 +02:00
|
|
|
ask: ask,
|
|
|
|
fullname: names[i],
|
|
|
|
jid: names[i].replace(/ /g,'.').toLowerCase() + '@localhost',
|
|
|
|
requesting: requesting,
|
|
|
|
subscription: subscription
|
2013-11-02 09:56:20 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
2014-03-05 03:29:10 +01:00
|
|
|
|
|
|
|
utils.sendMessage = function (chatboxview, message) {
|
|
|
|
chatboxview.$el.find('.chat-textarea').val(message);
|
|
|
|
chatboxview.$el.find('textarea.chat-textarea').trigger($.Event('keypress', {keyCode: 13}));
|
|
|
|
};
|
2013-11-02 09:56:20 +01:00
|
|
|
return utils;
|
|
|
|
}));
|