Commit 07dbf14a authored by JC Brand's avatar JC Brand

bookmarks: enable registration of spy on the mock connection during init

We need this because when the plugin listens to a promise, we can't trigger it
again later (after adding our spy), we instead need to add the spy beforehand.
parent 1ef99b3e
......@@ -292,15 +292,8 @@
*/
}));
it("can be retrieved from the XMPP server", mock.initConverse(function (_converse) {
var sent_stanza, IQ_id,
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);
});
_converse.emit('chatBoxesFetched');
it("can be retrieved from the XMPP server",
mock.initConverseWithConnectionSpies(['send'], function (_converse) {
/* Client requests all items
* -------------------------
*
......@@ -310,13 +303,23 @@
* </pubsub>
* </iq>
*/
expect(sent_stanza.toLocaleString()).toBe(
"<iq from='dummy@localhost/resource' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+
"<pubsub xmlns='http://jabber.org/protocol/pubsub'>"+
"<items node='storage:bookmarks'/>"+
"</pubsub>"+
"</iq>"
);
var IQ_id;
expect(_.filter(_converse.connection.send.calls.all(), function (call) {
var stanza = call.args[0]
if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
return;
}
if (stanza.outerHTML ===
'<iq from="dummy@localhost/resource" type="get" '+
'xmlns="jabber:client" id="'+stanza.getAttribute('id')+'">'+
'<pubsub xmlns="http://jabber.org/protocol/pubsub">'+
'<items node="storage:bookmarks"/>'+
'</pubsub>'+
'</iq>') {
IQ_id = stanza.getAttribute('id');
return true;
}
}).length).toBe(1);
/*
* Server returns all items
......
......@@ -76,24 +76,39 @@
};
}();
function initConverse (settings) {
function initConverse (settings, spies) {
window.localStorage.clear();
window.sessionStorage.clear();
var connection = mock.mock_connection();
if (!_.isUndefined(spies)) {
_.forEach(spies, function (method) {
spyOn(connection, method);
});
}
var converse = converse_api.initialize(_.extend({
i18n: 'en',
auto_subscribe: false,
bosh_service_url: 'localhost',
connection: mock.mock_connection(),
animate: false,
no_trimming: true,
auto_login: true,
jid: 'dummy@localhost',
password: 'secret',
debug: false
'i18n': 'en',
'auto_subscribe': false,
'bosh_service_url': 'localhost',
'connection': connection,
'animate': false,
'no_trimming': true,
'auto_login': true,
'jid': 'dummy@localhost',
'password': 'secret',
'debug': false
}, settings || {}));
converse.ChatBoxViews.prototype.trimChat = function () {};
return converse;
}
mock.initConverseWithConnectionSpies = function (spies, func, settings) {
return function () {
return func(initConverse(settings, spies));
};
};
mock.initConverseWithAsync = function (func, settings) {
return function (done) {
return func(done, initConverse(settings));
......@@ -101,7 +116,6 @@
};
mock.initConverse = function (func, settings) {
return function () {
initConverse(settings);
return func(initConverse(settings));
};
};
......
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