headline.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. (function (root, factory) {
  2. define([
  3. "jasmine",
  4. "jquery",
  5. "converse-core",
  6. "utils",
  7. "mock",
  8. "test-utils"
  9. ], factory);
  10. } (this, function (jasmine, $, converse, utils, mock, test_utils) {
  11. "use strict";
  12. var $msg = converse.env.$msg,
  13. _ = converse.env._;
  14. describe("A headlines box", function () {
  15. it("will not open nor display non-headline messages", mock.initConverse(function (_converse) {
  16. /* XMPP spam message:
  17. *
  18. * <message xmlns="jabber:client"
  19. * to="dummy@localhost"
  20. * type="chat"
  21. * from="gapowa20102106@rds-rostov.ru/Adium">
  22. * <nick xmlns="http://jabber.org/protocol/nick">-wwdmz</nick>
  23. * <body>SORRY FOR THIS ADVERT</body
  24. * </message
  25. */
  26. sinon.spy(utils, 'isHeadlineMessage');
  27. var stanza = $msg({
  28. 'xmlns': 'jabber:client',
  29. 'to': 'dummy@localhost',
  30. 'type': 'chat',
  31. 'from': 'gapowa20102106@rds-rostov.ru/Adium',
  32. })
  33. .c('nick', {'xmlns': "http://jabber.org/protocol/nick"}).t("-wwdmz").up()
  34. .c('body').t('SORRY FOR THIS ADVERT');
  35. _converse.connection._dataRecv(test_utils.createRequest(stanza));
  36. expect(utils.isHeadlineMessage.called).toBeTruthy();
  37. expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
  38. utils.isHeadlineMessage.restore();
  39. }));
  40. it("will open and display headline messages", mock.initConverseWithPromises(
  41. null, ['rosterGroupsFetched'], {}, function (done, _converse) {
  42. /* <message from='notify.example.com'
  43. * to='romeo@im.example.com'
  44. * type='headline'
  45. * xml:lang='en'>
  46. * <subject>SIEVE</subject>
  47. * <body>&lt;juliet@example.com&gt; You got mail.</body>
  48. * <x xmlns='jabber:x:oob'>
  49. * <url>
  50. * imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
  51. * </url>
  52. * </x>
  53. * </message>
  54. */
  55. sinon.spy(utils, 'isHeadlineMessage');
  56. var stanza = $msg({
  57. 'type': 'headline',
  58. 'from': 'notify.example.com',
  59. 'to': 'dummy@localhost',
  60. 'xml:lang': 'en'
  61. })
  62. .c('subject').t('SIEVE').up()
  63. .c('body').t('&lt;juliet@example.com&gt; You got mail.').up()
  64. .c('x', {'xmlns': 'jabber:x:oob'})
  65. .c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
  66. _converse.connection._dataRecv(test_utils.createRequest(stanza));
  67. expect(
  68. _.includes(
  69. _converse.chatboxviews.keys(),
  70. 'notify.example.com')
  71. ).toBeTruthy();
  72. expect(utils.isHeadlineMessage.called).toBeTruthy();
  73. expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
  74. utils.isHeadlineMessage.restore(); // unwraps
  75. // Headlines boxes don't show an avatar
  76. var view = _converse.chatboxviews.get('notify.example.com');
  77. expect(view.model.get('show_avatar')).toBeFalsy();
  78. expect(view.el.querySelector('img.avatar')).toBe(null);
  79. done();
  80. }));
  81. it("will not show a headline messages from a full JID if allow_non_roster_messaging is false",
  82. mock.initConverse(function (_converse) {
  83. _converse.allow_non_roster_messaging = false;
  84. sinon.spy(utils, 'isHeadlineMessage');
  85. var stanza = $msg({
  86. 'type': 'headline',
  87. 'from': 'andre5114@jabber.snc.ru/Spark',
  88. 'to': 'dummy@localhost',
  89. 'xml:lang': 'en'
  90. })
  91. .c('nick').t('gpocy').up()
  92. .c('body').t('Здравствуйте друзья');
  93. _converse.connection._dataRecv(test_utils.createRequest(stanza));
  94. expect(_.without('controlbox', _converse.chatboxviews.keys()).length).toBe(0);
  95. expect(utils.isHeadlineMessage.called).toBeTruthy();
  96. expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
  97. utils.isHeadlineMessage.restore(); // unwraps
  98. }));
  99. });
  100. }));