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 @@ ...@@ -292,15 +292,8 @@
*/ */
})); }));
it("can be retrieved from the XMPP server", mock.initConverse(function (_converse) { it("can be retrieved from the XMPP server",
var sent_stanza, IQ_id, mock.initConverseWithConnectionSpies(['send'], function (_converse) {
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');
/* Client requests all items /* Client requests all items
* ------------------------- * -------------------------
* *
...@@ -310,13 +303,23 @@ ...@@ -310,13 +303,23 @@
* </pubsub> * </pubsub>
* </iq> * </iq>
*/ */
expect(sent_stanza.toLocaleString()).toBe( var IQ_id;
"<iq from='dummy@localhost/resource' type='get' xmlns='jabber:client' id='"+IQ_id+"'>"+ expect(_.filter(_converse.connection.send.calls.all(), function (call) {
"<pubsub xmlns='http://jabber.org/protocol/pubsub'>"+ var stanza = call.args[0]
"<items node='storage:bookmarks'/>"+ if (!(stanza instanceof Element) || stanza.nodeName !== 'iq') {
"</pubsub>"+ return;
"</iq>" }
); 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 * Server returns all items
......
...@@ -76,24 +76,39 @@ ...@@ -76,24 +76,39 @@
}; };
}(); }();
function initConverse (settings) { function initConverse (settings, spies) {
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.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({ var converse = converse_api.initialize(_.extend({
i18n: 'en', 'i18n': 'en',
auto_subscribe: false, 'auto_subscribe': false,
bosh_service_url: 'localhost', 'bosh_service_url': 'localhost',
connection: mock.mock_connection(), 'connection': connection,
animate: false, 'animate': false,
no_trimming: true, 'no_trimming': true,
auto_login: true, 'auto_login': true,
jid: 'dummy@localhost', 'jid': 'dummy@localhost',
password: 'secret', 'password': 'secret',
debug: false 'debug': false
}, settings || {})); }, settings || {}));
converse.ChatBoxViews.prototype.trimChat = function () {}; converse.ChatBoxViews.prototype.trimChat = function () {};
return converse; return converse;
} }
mock.initConverseWithConnectionSpies = function (spies, func, settings) {
return function () {
return func(initConverse(settings, spies));
};
};
mock.initConverseWithAsync = function (func, settings) { mock.initConverseWithAsync = function (func, settings) {
return function (done) { return function (done) {
return func(done, initConverse(settings)); return func(done, initConverse(settings));
...@@ -101,7 +116,6 @@ ...@@ -101,7 +116,6 @@
}; };
mock.initConverse = function (func, settings) { mock.initConverse = function (func, settings) {
return function () { return function () {
initConverse(settings);
return func(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