appNotification.test.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { AppNotificationSeverity, AppNotificationsState } from 'app/types/';
  2. import { appNotificationsReducer, clearNotification, notifyApp } from './appNotification';
  3. const timestamp = 1649849468889;
  4. describe('clear alert', () => {
  5. it('should filter alert', () => {
  6. const id1 = '1767d3d9-4b99-40eb-ab46-de734a66f21d';
  7. const id2 = '4767b3de-12dd-40e7-b58c-f778bd59d675';
  8. const initialState: AppNotificationsState = {
  9. byId: {
  10. [id1]: {
  11. id: id1,
  12. severity: AppNotificationSeverity.Success,
  13. icon: 'success',
  14. title: 'test',
  15. text: 'test alert',
  16. showing: true,
  17. timestamp,
  18. },
  19. [id2]: {
  20. id: id2,
  21. severity: AppNotificationSeverity.Warning,
  22. icon: 'warning',
  23. title: 'test2',
  24. text: 'test alert fail 2',
  25. showing: true,
  26. timestamp,
  27. },
  28. },
  29. lastRead: timestamp - 10,
  30. };
  31. const result = appNotificationsReducer(initialState, clearNotification(id2));
  32. const expectedResult: AppNotificationsState = {
  33. byId: {
  34. [id1]: {
  35. id: id1,
  36. severity: AppNotificationSeverity.Success,
  37. icon: 'success',
  38. title: 'test',
  39. text: 'test alert',
  40. showing: true,
  41. timestamp,
  42. },
  43. },
  44. lastRead: timestamp - 10,
  45. };
  46. expect(result).toEqual(expectedResult);
  47. });
  48. });
  49. describe('notify', () => {
  50. it('create notify message', () => {
  51. const id1 = '696da53b-6ae7-4824-9e0e-d6a3b54a2c74';
  52. const id2 = '4477fcd9-246c-45a5-8818-e22a16683dae';
  53. const id3 = '55be87a8-bbab-45c7-b481-1f9d46f0d2ee';
  54. const initialState: AppNotificationsState = {
  55. byId: {
  56. [id1]: {
  57. id: id1,
  58. severity: AppNotificationSeverity.Success,
  59. icon: 'success',
  60. title: 'test',
  61. text: 'test alert',
  62. showing: true,
  63. timestamp,
  64. },
  65. [id2]: {
  66. id: id2,
  67. severity: AppNotificationSeverity.Warning,
  68. icon: 'warning',
  69. title: 'test2',
  70. text: 'test alert fail 2',
  71. showing: true,
  72. timestamp,
  73. },
  74. },
  75. lastRead: timestamp - 10,
  76. };
  77. const result = appNotificationsReducer(
  78. initialState,
  79. notifyApp({
  80. id: id3,
  81. severity: AppNotificationSeverity.Info,
  82. icon: 'info',
  83. title: 'test3',
  84. text: 'test alert info 3',
  85. showing: true,
  86. timestamp: 1649802870373,
  87. })
  88. );
  89. const expectedResult: AppNotificationsState = {
  90. byId: {
  91. [id1]: {
  92. id: id1,
  93. severity: AppNotificationSeverity.Success,
  94. icon: 'success',
  95. title: 'test',
  96. text: 'test alert',
  97. timestamp,
  98. showing: true,
  99. },
  100. [id2]: {
  101. id: id2,
  102. severity: AppNotificationSeverity.Warning,
  103. icon: 'warning',
  104. title: 'test2',
  105. text: 'test alert fail 2',
  106. timestamp,
  107. showing: true,
  108. },
  109. [id3]: {
  110. id: id3,
  111. severity: AppNotificationSeverity.Info,
  112. icon: 'info',
  113. title: 'test3',
  114. text: 'test alert info 3',
  115. timestamp: 1649802870373,
  116. showing: true,
  117. },
  118. },
  119. lastRead: timestamp - 10,
  120. };
  121. expect(result).toEqual(expectedResult);
  122. });
  123. it('Dedupe identical alerts', () => {
  124. const initialState: AppNotificationsState = {
  125. byId: {
  126. id1: {
  127. id: 'id1',
  128. severity: AppNotificationSeverity.Success,
  129. icon: 'success',
  130. title: 'test',
  131. text: 'test alert',
  132. showing: true,
  133. timestamp,
  134. },
  135. },
  136. lastRead: timestamp - 10,
  137. };
  138. const result = appNotificationsReducer(
  139. initialState,
  140. notifyApp({
  141. id: 'id2',
  142. severity: AppNotificationSeverity.Success,
  143. icon: 'success',
  144. title: 'test',
  145. text: 'test alert',
  146. showing: true,
  147. timestamp,
  148. })
  149. );
  150. const expectedResult: AppNotificationsState = {
  151. byId: {
  152. id1: {
  153. id: 'id1',
  154. severity: AppNotificationSeverity.Success,
  155. icon: 'success',
  156. title: 'test',
  157. text: 'test alert',
  158. showing: true,
  159. timestamp,
  160. },
  161. },
  162. lastRead: timestamp - 10,
  163. };
  164. expect(result).toEqual(expectedResult);
  165. });
  166. });