xmpp.chapril.org-conversejs/spec/transcripts.js

81 lines
2.6 KiB
JavaScript
Raw Normal View History

(function (root, factory) {
define([
2018-01-09 14:52:27 +01:00
"jasmine",
2017-02-24 16:11:57 +01:00
"converse-core",
"mock",
2018-01-09 14:52:27 +01:00
"test-utils",
"utils",
"transcripts"
], factory
);
2019-04-06 16:31:42 +02:00
} (this, function (jasmine, converse, mock, test_utils, utils, transcripts) {
var Strophe = converse.env.Strophe;
var _ = converse.env._;
var IGNORED_TAGS = [
'stream:features',
'auth',
'challenge',
'success',
'stream:features',
'response'
];
function traverseElement (el, _stanza) {
if (typeof _stanza !== 'undefined') {
if (el.nodeType === 3) {
_stanza.t(el.nodeValue);
return _stanza;
} else {
_stanza = _stanza.c(el.nodeName.toLowerCase(), getAttributes(el));
}
} else {
_stanza = new Strophe.Builder(
el.nodeName.toLowerCase(),
getAttributes(el)
);
}
_.each(el.childNodes, _.partial(traverseElement, _, _stanza));
return _stanza.up();
}
function getAttributes (el) {
var attributes = {};
_.each(el.attributes, function (att) {
attributes[att.nodeName] = att.nodeValue;
});
return attributes;
}
return describe("Transcripts of chat logs", function () {
2017-02-24 16:11:57 +01:00
2018-01-09 14:52:27 +01:00
it("can be used to replay conversations",
mock.initConverse(
2018-01-09 14:52:27 +01:00
null, ['rosterGroupsFetched'], {},
function (done, _converse) {
_converse.allow_non_roster_messaging = true;
test_utils.openAndEnterChatRoom(_converse, 'discuss', 'conference.conversejs.org', 'dummy').then(function () {
spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
_.each(transcripts, function (transcript) {
var text = transcript();
var xml = Strophe.xmlHtmlNode(text);
_.each(xml.firstElementChild.children, function (el) {
_.each(el.children, function (el) {
if (el.nodeType === 3) {
return; // Ignore text
}
if (_.includes(IGNORED_TAGS, el.nodeName.toLowerCase())) {
return;
}
var _stanza = traverseElement(el);
_converse.connection._dataRecv(test_utils.createRequest(_stanza));
});
});
});
2018-01-09 14:52:27 +01:00
done();
});
2017-02-24 16:11:57 +01:00
}));
});
}));