2016-02-19 14:02:42 +01:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
2017-06-19 11:08:57 +02:00
|
|
|
} (this, function (jasmine, 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
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are registered when _converse.js is connected",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2017-07-11 10:41:11 +02:00
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'registerPingHandler').and.callThrough();
|
|
|
|
spyOn(_converse, 'registerPongHandler').and.callThrough();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.emit('connected');
|
|
|
|
expect(_converse.registerPingHandler).toHaveBeenCalled();
|
|
|
|
expect(_converse.registerPongHandler).toHaveBeenCalled();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-03-21 10:53:09 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("are registered when _converse.js reconnected",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2017-07-11 10:41:11 +02:00
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse, 'registerPingHandler').and.callThrough();
|
|
|
|
spyOn(_converse, 'registerPongHandler').and.callThrough();
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.emit('reconnected');
|
|
|
|
expect(_converse.registerPingHandler).toHaveBeenCalled();
|
|
|
|
expect(_converse.registerPongHandler).toHaveBeenCalled();
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
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
|
|
|
|
2019-02-12 14:21:45 +01:00
|
|
|
it("is sent out when _converse.js pings a server", mock.initConverse((done, _converse) => {
|
|
|
|
let sent_stanza, IQ_id;
|
|
|
|
const sendIQ = _converse.connection.sendIQ;
|
2017-04-05 11:01:31 +02:00
|
|
|
spyOn(_converse.connection, 'sendIQ').and.callFake(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(
|
2018-10-02 17:01:39 +02:00
|
|
|
`<iq id="${IQ_id}" to="localhost" type="get" xmlns="jabber:client">`+
|
|
|
|
`<ping xmlns="urn:xmpp:ping"/>`+
|
|
|
|
`</iq>`);
|
2019-02-12 14:21:45 +01:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-03-21 10:53:09 +01:00
|
|
|
});
|
|
|
|
});
|
2016-02-19 14:02:42 +01:00
|
|
|
}));
|