2016-02-19 14:02:42 +01:00
|
|
|
(function (root, factory) {
|
2016-11-30 13:18:58 +01:00
|
|
|
define(["mock", "converse-api", "test_utils", "converse-ping"], factory);
|
|
|
|
} (this, function (mock, converse_api, test_utils) {
|
2016-02-19 14:02:42 +01:00
|
|
|
"use strict";
|
|
|
|
|
2016-03-21 10:53:09 +01:00
|
|
|
describe("XMPP Ping", function () {
|
|
|
|
describe("Ping and pong handlers", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
afterEach(function () {
|
|
|
|
converse_api.user.logout();
|
|
|
|
test_utils.clearBrowserStorage();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("are registered when converse.js is connected", mock.initConverse(function (converse) {
|
2016-02-19 14:02:42 +01:00
|
|
|
spyOn(converse, 'registerPingHandler').andCallThrough();
|
|
|
|
spyOn(converse, 'registerPongHandler').andCallThrough();
|
2016-03-21 10:53:09 +01:00
|
|
|
converse.emit('connected');
|
2016-02-19 14:02:42 +01:00
|
|
|
expect(converse.registerPingHandler).toHaveBeenCalled();
|
|
|
|
expect(converse.registerPongHandler).toHaveBeenCalled();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-03-21 10:53:09 +01:00
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
it("are registered when converse.js reconnected", mock.initConverse(function (converse) {
|
2016-03-21 10:53:09 +01:00
|
|
|
spyOn(converse, 'registerPingHandler').andCallThrough();
|
|
|
|
spyOn(converse, 'registerPongHandler').andCallThrough();
|
|
|
|
converse.emit('reconnected');
|
|
|
|
expect(converse.registerPingHandler).toHaveBeenCalled();
|
|
|
|
expect(converse.registerPongHandler).toHaveBeenCalled();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-03-21 10:53:09 +01:00
|
|
|
});
|
2016-02-19 14:02:42 +01:00
|
|
|
|
2016-03-21 10:53:09 +01:00
|
|
|
describe("An IQ stanza", function () {
|
2016-11-03 11:01:09 +01:00
|
|
|
afterEach(function () {
|
|
|
|
converse_api.user.logout();
|
|
|
|
test_utils.clearBrowserStorage();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("is sent out when converse.js pings a server", mock.initConverse(function (converse) {
|
2016-02-19 14:02:42 +01:00
|
|
|
var sent_stanza, IQ_id;
|
|
|
|
var sendIQ = converse.connection.sendIQ;
|
|
|
|
spyOn(converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
|
|
|
converse.ping();
|
|
|
|
expect(sent_stanza.toLocaleString()).toBe(
|
|
|
|
"<iq type='get' to='localhost' id='"+IQ_id+"' xmlns='jabber:client'>"+
|
|
|
|
"<ping xmlns='urn:xmpp:ping'/>"+
|
|
|
|
"</iq>");
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-03-21 10:53:09 +01:00
|
|
|
});
|
|
|
|
});
|
2016-02-19 14:02:42 +01:00
|
|
|
}));
|