headline.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. (function (root, factory) {
  2. define([
  3. "jasmine",
  4. "jquery",
  5. "mock",
  6. "test-utils"
  7. ], factory);
  8. } (this, function (jasmine, $, mock, test_utils) {
  9. "use strict";
  10. var $msg = converse.env.$msg,
  11. _ = converse.env._,
  12. utils = converse.env.utils;
  13. describe("A headlines box", function () {
  14. it("will not open nor display non-headline messages", mock.initConverse(function (_converse) {
  15. /* XMPP spam message:
  16. *
  17. * <message xmlns="jabber:client"
  18. * to="dummy@localhost"
  19. * type="chat"
  20. * from="gapowa20102106@rds-rostov.ru/Adium">
  21. * <nick xmlns="http://jabber.org/protocol/nick">-wwdmz</nick>
  22. * <body>SORRY FOR THIS ADVERT</body
  23. * </message
  24. */
  25. sinon.spy(utils, 'isHeadlineMessage');
  26. var stanza = $msg({
  27. 'xmlns': 'jabber:client',
  28. 'to': 'dummy@localhost',
  29. 'type': 'chat',
  30. 'from': 'gapowa20102106@rds-rostov.ru/Adium',
  31. })
  32. .c('nick', {'xmlns': "http://jabber.org/protocol/nick"}).t("-wwdmz").up()
  33. .c('body').t('SORRY FOR THIS ADVERT');
  34. _converse.connection._dataRecv(test_utils.createRequest(stanza));
  35. expect(utils.isHeadlineMessage.called).toBeTruthy();
  36. expect(utils.isHeadlineMessage.returned(false)).toBeTruthy();
  37. utils.isHeadlineMessage.restore();
  38. }));
  39. it("will open and display headline messages", mock.initConverseWithPromises(
  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. var stanza = $msg({
  56. 'type': 'headline',
  57. 'from': 'notify.example.com',
  58. 'to': 'dummy@localhost',
  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. var 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(function (_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': 'dummy@localhost',
  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. }));
  98. });
  99. }));