headline.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*global converse */
  2. (function (root, factory) {
  3. define([
  4. "jquery",
  5. "utils",
  6. "mock",
  7. "test_utils"
  8. ], factory);
  9. } (this, function ($, utils, mock, test_utils) {
  10. "use strict";
  11. var $msg = converse_api.env.$msg,
  12. _ = converse_api.env._;
  13. describe("When a headline message is received", function () {
  14. it("a chat box will open and display it", function () {
  15. /*
  16. * <message from='notify.example.com'
  17. * to='romeo@im.example.com'
  18. * type='headline'
  19. * xml:lang='en'>
  20. * <subject>SIEVE</subject>
  21. * <body>&lt;juliet@example.com&gt; You got mail.</body>
  22. * <x xmlns='jabber:x:oob'>
  23. * <url>
  24. * imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18
  25. * </url>
  26. * </x>
  27. * </message>
  28. */
  29. sinon.spy(utils, 'isHeadlineMessage');
  30. runs(function () {
  31. var stanza = $msg({
  32. 'type': 'headline',
  33. 'from': 'notify.example.com',
  34. 'to': 'dummy@localhost',
  35. 'xml:lang': 'en'
  36. })
  37. .c('subject').t('SIEVE').up()
  38. .c('body').t('&lt;juliet@example.com&gt; You got mail.').up()
  39. .c('x', {'xmlns': 'jabber:x:oob'})
  40. .c('url').t('imap://romeo@example.com/INBOX;UIDVALIDITY=385759043/;UID=18');
  41. converse.connection._dataRecv(test_utils.createRequest(stanza));
  42. });
  43. waits(250);
  44. runs(function () {
  45. expect(
  46. _.contains(
  47. converse.chatboxviews.keys(),
  48. 'notify.example.com')
  49. ).toBeTruthy();
  50. expect(utils.isHeadlineMessage.called).toBeTruthy();
  51. expect(utils.isHeadlineMessage.returned(true)).toBeTruthy();
  52. utils.isHeadlineMessage.restore(); // unwraps
  53. });
  54. });
  55. });
  56. }));