Commit 5e4d6bd3 authored by JC Brand's avatar JC Brand

Initial work on adding profiling tests.

parent 7e42783c
......@@ -139,6 +139,7 @@ config = {
'crypto.sha1': { deps: ['crypto.core'] },
'crypto.sha256': { deps: ['crypto.core'] },
'bigint': { deps: ['crypto'] },
'strophe': { exports: 'Strophe' },
'strophe.disco': { deps: ['strophe'] },
'strophe.muc': { deps: ['strophe'] },
'strophe.roster': { deps: ['strophe'] },
......
......@@ -385,6 +385,11 @@
}, converse));
it("can be removed by the user", $.proxy(function () {
// XXX
// This tests fails because "remove" function in strophe.roster
// (line 292) gets called and it then tries to actually remove
// the user which is not in the roster...
// We'll perhaps have to first add the user again...
_addContacts();
var name = mock.pend_names[0];
var jid = name.replace(/ /g,'.').toLowerCase() + '@localhost';
......@@ -764,6 +769,48 @@
// There should now be one less contact
expect(this.roster.length).toEqual(mock.req_names.length-1);
}, converse));
it("are persisted even if other contacts' change their presence ", $.proxy(function() {
/* This is a regression test.
* https://github.com/jcbrand/converse.js/issues/262
*/
this.rosterview.model.reset();
spyOn(this.roster, 'clearCache').andCallThrough();
expect(this.roster.pluck('jid').length).toBe(0);
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(this.roster.pluck('jid').length).toBe(1);
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
// Taken from the spec
// http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
stanza = $iq({
to: this.connection.jid,
type: 'result',
id: 'roster_1'
}).c('query', {
xmlns: 'jabber:iq:roster',
}).c('item', {
jid: 'romeo@example.net',
name: 'Romeo',
subscription:'both'
}).c('group').t('Friends').up().up()
.c('item', {
jid: 'mercutio@example.org',
name: 'Mercutio',
subscription:'from'
}).c('group').t('Friends').up().up()
.c('item', {
jid: 'benvolio@example.org',
name: 'Benvolio',
subscription:'both'
}).c('group').t('Friends');
this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
expect(this.roster.clearCache).toHaveBeenCalled();
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
}, converse));
}, converse));
describe("All Contacts", $.proxy(function () {
......
(function (root, factory) {
define([
"jquery",
"mock",
"test_utils"
], function ($, mock, test_utils) {
return factory($, mock, test_utils);
}
);
} (this, function ($, mock, test_utils) {
describe("Profiling", function() {
var roster;
beforeEach(function() {
roster = converse.connection.roster;
converse.connection._changeConnectStatus(Strophe.Status.CONNECTED);
});
it("adds contacts on presence stanza", $.proxy(function() {
spyOn(this.roster, 'clearCache').andCallThrough();
expect(this.roster.pluck('jid').length).toBe(0);
var stanza = $pres({from: 'data@enterprise/resource', type: 'subscribe'});
this.connection._dataRecv(test_utils.createRequest(stanza));
expect(this.roster.pluck('jid').length).toBe(1);
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
// Taken from the spec
// http://xmpp.org/rfcs/rfc3921.html#rfc.section.7.3
stanza = $iq({
to: this.connection.jid,
type: 'result',
id: 'roster_1'
}).c('query', {
xmlns: 'jabber:iq:roster',
}).c('item', {
jid: 'romeo@example.net',
name: 'Romeo',
subscription:'both'
}).c('group').t('Friends').up().up()
.c('item', {
jid: 'mercutio@example.org',
name: 'Mercutio',
subscription:'from'
}).c('group').t('Friends').up().up()
.c('item', {
jid: 'benvolio@example.org',
name: 'Benvolio',
subscription:'both'
}).c('group').t('Friends');
this.connection.roster._onReceiveRosterSuccess(null, stanza.tree());
expect(this.roster.clearCache).toHaveBeenCalled();
expect(_.contains(this.roster.pluck('jid'), 'data@enterprise')).toBeTruthy();
}, converse));
});
}));
......@@ -40,8 +40,6 @@ require([
window.converse_api = converse;
window.localStorage.clear();
window.sessionStorage.clear();
// XXX: call this to initialize Strophe plugins
new Strophe.Connection('localhost');
converse.initialize({
prebind: false,
......@@ -49,7 +47,8 @@ require([
auto_subscribe: false,
animate: false,
connection: mock.mock_connection,
no_trimming: true
no_trimming: true,
debug: true
}, function (converse) {
window.converse = converse;
window.crypto = {
......@@ -68,7 +67,8 @@ require([
"spec/controlbox",
"spec/chatbox",
"spec/chatroom",
"spec/minchats"
"spec/minchats",
"spec/profiling"
], function () {
// Make sure this callback is only called once.
delete converse.callback;
......
......@@ -36,11 +36,37 @@
'preventDefault': function () {}
};
mock.mock_connection = {
'_proto': {},
'connected': true,
'authenticated': true,
'mock': true,
mock.mock_connection = function () {
Strophe.Bosh.prototype._processRequest = function () {}; // Don't attempt to send out stanzas
var c = new Strophe.Connection('jasmine tests');
c.authenticated = true;
c.connected = true;
c.mock = true;
c.jid = 'dummy@localhost/resource';
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());
}
};
c._changeConnectStatus(Strophe.Status.CONNECTED);
c.attach(c.jid);
return c;
}();
/*
{
'muc': {
'listRooms': function () {},
'join': function () {},
......@@ -49,7 +75,6 @@
'groupchat': function () {return String((new Date()).getTime()); }
},
'service': 'jasmine tests',
'jid': 'dummy@localhost',
'addHandler': function (handler, ns, name, type, id, from, options) {
return function () {};
},
......@@ -87,5 +112,6 @@
'items': function () {}
}
};
*/
return mock;
}));
......@@ -8,6 +8,17 @@
});
}(this, function ($, mock) {
var utils = {};
utils.createRequest = function (iq) {
iq = typeof iq.tree == "function" ? iq.tree() : iq;
var req = new Strophe.Request(iq, function() {});
req.getResponse = function() {
var env = new Strophe.Builder('env', {type: 'mock'}).tree();
env.appendChild(iq);
return env;
};
return req;
};
utils.closeAllChatBoxes = function () {
var i, chatbox;
......
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