headline.js 4.7 KB

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