transcripts.js 2.6 KB

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