notification.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. describe('getDndModeSimplified', function() {
  112. let process = (dnd, sound) => {
  113. return $service.getDndModeSimplified({
  114. notifications: {dnd: dnd, sound: sound},
  115. })
  116. };
  117. it('dnd enabled', () => {
  118. expect(process(
  119. {mode: 'on'},
  120. {mode: 'default'}
  121. )).toEqual('on');
  122. });
  123. it('dnd enabled (no sound)', () => {
  124. expect(process(
  125. {mode: 'on'},
  126. {mode: 'muted'}
  127. )).toEqual('on');
  128. });
  129. it('dnd disabled', () => {
  130. expect(process(
  131. {mode: 'off'},
  132. {mode: 'default'}
  133. )).toEqual('off');
  134. });
  135. it('dnd disabled (no sound)', () => {
  136. expect(process(
  137. {mode: 'off'},
  138. {mode: 'muted'}
  139. )).toEqual('off');
  140. });
  141. it('mention only', () => {
  142. expect(process(
  143. {mode: 'on', mentionOnly: true},
  144. {mode: 'default'}
  145. )).toEqual('mention');
  146. });
  147. it('mention only (no sound)', () => {
  148. expect(process(
  149. {mode: 'on', mentionOnly: true},
  150. {mode: 'muted'}
  151. )).toEqual('mention');
  152. });
  153. it('until (not expired)', () => {
  154. jasmine.clock().install();
  155. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  156. expect(process(
  157. {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50))},
  158. {mode: 'default'}
  159. )).toEqual('on');
  160. });
  161. it('until (expired)', () => {
  162. jasmine.clock().install();
  163. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  164. expect(process(
  165. {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50))},
  166. {mode: 'default'}
  167. )).toEqual('off');
  168. });
  169. it('until (mention only, not expired)', () => {
  170. jasmine.clock().install();
  171. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  172. expect(process(
  173. {mode: 'until', until: +(new Date(2018, 9, 9, 20, 50)), mentionOnly: true},
  174. {mode: 'default'}
  175. )).toEqual('mention');
  176. });
  177. it('until (mention only, expired)', () => {
  178. jasmine.clock().install();
  179. jasmine.clock().mockDate(new Date(2018, 9, 9, 20, 42));
  180. expect(process(
  181. {mode: 'until', until: +(new Date(2018, 9, 9, 19, 50)), mentionOnly: true},
  182. {mode: 'default'}
  183. )).toEqual('off');
  184. });
  185. });
  186. });