notification.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. describe('NotificationService', function() {
  2. let $service;
  3. // Ignoring page reload request
  4. beforeAll(() => window.onbeforeunload = () => null);
  5. beforeEach(function() {
  6. module(($provide) => {
  7. $provide.constant('$state', null);
  8. });
  9. module('3ema.services');
  10. // Inject the service
  11. inject(function(NotificationService) {
  12. $service = NotificationService;
  13. });
  14. });
  15. describe('getAppNotificationSettings', function () {
  16. let process = (dnd, sound) => {
  17. return $service.getAppNotificationSettings({
  18. notifications: {dnd: dnd, sound: sound},
  19. })
  20. };
  21. it('dnd enabled', () => {
  22. const res = process(
  23. {mode: 'on'},
  24. {mode: 'default'}
  25. );
  26. expect(res.sound.muted).toEqual(false);
  27. expect(res.dnd.enabled).toEqual(true);
  28. expect(res.dnd.mentionOnly).toEqual(false);
  29. });
  30. it('dnd enabled (no sound)', () => {
  31. const res = process(
  32. {mode: 'on'},
  33. {mode: 'muted'}
  34. );
  35. expect(res.sound.muted).toEqual(true);
  36. expect(res.dnd.enabled).toEqual(true);
  37. expect(res.dnd.mentionOnly).toEqual(false);
  38. });
  39. it('dnd disabled', () => {
  40. const res = process(
  41. {mode: 'off'},
  42. {mode: 'default'}
  43. );
  44. expect(res.sound.muted).toEqual(false);
  45. expect(res.dnd.enabled).toEqual(false);
  46. expect(res.dnd.mentionOnly).toEqual(false);
  47. });
  48. it('dnd disabled (no sound)', () => {
  49. const res = process(
  50. {mode: 'off'},
  51. {mode: 'muted'}
  52. );
  53. expect(res.sound.muted).toEqual(true);
  54. expect(res.dnd.enabled).toEqual(false);
  55. expect(res.dnd.mentionOnly).toEqual(false);
  56. });
  57. it('mention only', () => {
  58. const res = process(
  59. {mode: 'on', mentionOnly: true},
  60. {mode: 'default'}
  61. );
  62. expect(res.sound.muted).toEqual(false);
  63. expect(res.dnd.enabled).toEqual(true);
  64. expect(res.dnd.mentionOnly).toEqual(true);
  65. });
  66. it('until (not expired)', () => {
  67. jasmine.clock().install();
  68. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  69. const res = process(
  70. {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50))},
  71. {mode: 'default'}
  72. );
  73. expect(res.sound.muted).toEqual(false);
  74. expect(res.dnd.enabled).toEqual(true);
  75. expect(res.dnd.mentionOnly).toEqual(false);
  76. });
  77. it('until (expired)', () => {
  78. jasmine.clock().install();
  79. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  80. const res = process(
  81. {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50))},
  82. {mode: 'default'}
  83. );
  84. expect(res.sound.muted).toEqual(false);
  85. expect(res.dnd.enabled).toEqual(false);
  86. expect(res.dnd.mentionOnly).toEqual(false);
  87. });
  88. it('until (mention only, not expired)', () => {
  89. jasmine.clock().install();
  90. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  91. const res = process(
  92. {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50)), mentionOnly: true},
  93. {mode: 'default'}
  94. );
  95. expect(res.sound.muted).toEqual(false);
  96. expect(res.dnd.enabled).toEqual(true);
  97. expect(res.dnd.mentionOnly).toEqual(true);
  98. });
  99. it('until (mention only, expired)', () => {
  100. jasmine.clock().install();
  101. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  102. const res = process(
  103. {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50)), mentionOnly: true},
  104. {mode: 'default'}
  105. );
  106. expect(res.sound.muted).toEqual(false);
  107. expect(res.dnd.enabled).toEqual(false);
  108. expect(res.dnd.mentionOnly).toEqual(false);
  109. });
  110. });
  111. });