2016-02-19 14:02:42 +01:00
|
|
|
(function (root, factory) {
|
2017-02-14 15:08:39 +01:00
|
|
|
define(["mock", "converse-core", "test_utils", "converse-ping"], factory);
|
2016-12-19 10:32:48 +01:00
|
|
|
} (this, function (mock, 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
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("are registered when _converse.js is connected", mock.initConverse(function (_converse) {
|
|
|
|
spyOn(_converse, 'registerPingHandler').andCallThrough();
|
|
|
|
spyOn(_converse, 'registerPongHandler').andCallThrough();
|
|
|
|
_converse.emit('connected');
|
|
|
|
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-12-20 10:30:20 +01:00
|
|
|
it("are registered when _converse.js reconnected", mock.initConverse(function (_converse) {
|
|
|
|
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
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
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;
|
2016-12-20 10:30:20 +01:00
|
|
|
var sendIQ = _converse.connection.sendIQ;
|
|
|
|
spyOn(_converse.connection, 'sendIQ').andCallFake(function (iq, callback, errback) {
|
2016-02-19 14:02:42 +01:00
|
|
|
sent_stanza = iq;
|
|
|
|
IQ_id = sendIQ.bind(this)(iq, callback, errback);
|
|
|
|
});
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.ping();
|
2016-02-19 14:02:42 +01:00
|
|
|
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
|
|
|
}));
|