transcripts.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. (function (root, factory) {
  2. define([
  3. "jasmine",
  4. "converse-core",
  5. "mock",
  6. "test-utils",
  7. "utils",
  8. "transcripts"
  9. ], factory
  10. );
  11. } (this, function (jasmine, converse, mock, test_utils, utils, transcripts) {
  12. var Strophe = converse.env.Strophe;
  13. var _ = converse.env._;
  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",
  48. mock.initConverse(
  49. null, ['rosterGroupsFetched'], {},
  50. async function (done, _converse) {
  51. _converse.allow_non_roster_messaging = true;
  52. await test_utils.openAndEnterChatRoom(_converse, 'discuss@conference.conversejs.org', 'romeo');
  53. spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
  54. _.each(transcripts, function (transcript) {
  55. const text = transcript();
  56. const xml = Strophe.xmlHtmlNode(text);
  57. _.each(xml.firstElementChild.children, function (el) {
  58. _.each(el.children, function (el) {
  59. if (el.nodeType === 3) {
  60. return; // Ignore text
  61. }
  62. if (_.includes(IGNORED_TAGS, el.nodeName.toLowerCase())) {
  63. return;
  64. }
  65. const _stanza = traverseElement(el);
  66. _converse.connection._dataRecv(test_utils.createRequest(_stanza));
  67. });
  68. });
  69. });
  70. done();
  71. }));
  72. });
  73. }));