headline.js 4.8 KB

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