headline.js 4.5 KB

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