transcripts.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. function (done, _converse) {
  51. _converse.allow_non_roster_messaging = true;
  52. test_utils.openAndEnterChatRoom(_converse, 'discuss', 'conference.conversejs.org', 'romeo').then(function () {
  53. spyOn(_converse, 'areDesktopNotificationsEnabled').and.returnValue(true);
  54. _.each(transcripts, function (transcript) {
  55. var text = transcript();
  56. var 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. var _stanza = traverseElement(el);
  66. _converse.connection._dataRecv(test_utils.createRequest(_stanza));
  67. });
  68. });
  69. });
  70. done();
  71. });
  72. }));
  73. });
  74. }));