transcripts.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. (function (root, factory) {
  2. define([
  3. "converse-core",
  4. "mock",
  5. "test_utils",
  6. "utils",
  7. "transcripts"
  8. ], factory
  9. );
  10. } (this, function (converse, mock, test_utils, utils, transcripts) {
  11. var Strophe = converse.env.Strophe;
  12. var _ = converse.env._;
  13. var $ = converse.env.jQuery;
  14. var IGNORED_TAGS = [
  15. 'stream:features',
  16. 'auth',
  17. 'challenge',
  18. 'success',
  19. 'stream:features',
  20. 'response'
  21. ];
  22. function traverseElement (el, _stanza) {
  23. if (typeof _stanza !== 'undefined') {
  24. if (el.nodeType === 3) {
  25. _stanza.t(el.nodeValue);
  26. return _stanza;
  27. } else {
  28. _stanza = _stanza.c(el.nodeName.toLowerCase(), getAttributes(el));
  29. }
  30. } else {
  31. _stanza = new Strophe.Builder(
  32. el.nodeName.toLowerCase(),
  33. getAttributes(el)
  34. );
  35. }
  36. _.each(el.childNodes, _.partial(traverseElement, _, _stanza));
  37. return _stanza.up();
  38. }
  39. function getAttributes (el) {
  40. var attributes = {};
  41. _.each(el.attributes, function (att) {
  42. attributes[att.nodeName] = att.nodeValue;
  43. });
  44. return attributes;
  45. }
  46. return describe("Transcripts of chat logs", function () {
  47. it("can be used to replay conversations", mock.initConverse(function (_converse) {
  48. /*
  49. test_utils.openChatRoom("discuss", 'conference.conversejs.org', 'jc');
  50. test_utils.openChatRoom("dummy", 'rooms.localhost', 'jc');
  51. test_utils.openChatRoom("prosody", 'conference.prosody.im', 'jc');
  52. */
  53. spyOn(_converse, 'areDesktopNotificationsEnabled').andReturn(true);
  54. _.each(transcripts, function (transcript) {
  55. var text = transcript();
  56. var xml = Strophe.xmlHtmlNode(text);
  57. $(xml).children('log').children('body').each(function (i, el) {
  58. $(el).children().each(function (i, el) {
  59. if (el.nodeType === 3) {
  60. return; // Ignore text
  61. }
  62. if (_.includes(IGNORED_TAGS, el.nodeName.toLowerCase())) {
  63. return;
  64. }
  65. var _stanza = traverseElement(el);
  66. _converse.connection._dataRecv(test_utils.createRequest(_stanza));
  67. });
  68. });
  69. });
  70. }));
  71. });
  72. }));