transcripts.js 2.5 KB

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