testUtils.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import {
  2. decideDefault,
  3. getUserDefaultValues,
  4. } from 'sentry/views/settings/account/notifications/utils';
  5. describe('Notification Settings Utils', () => {
  6. describe('getUserDefaultValues', () => {
  7. describe('when notificationsSettings are empty', () => {
  8. it('should return fallback values', () => {
  9. expect(getUserDefaultValues('deploy', {})).toEqual({
  10. email: 'committed_only',
  11. slack: 'never',
  12. });
  13. });
  14. });
  15. describe('when notificationsSettings are not empty', () => {
  16. it('should return the parent-independent notificationSettings', () => {
  17. expect(
  18. getUserDefaultValues('alerts', {
  19. alerts: {
  20. user: {
  21. me: {
  22. email: 'never',
  23. slack: 'never',
  24. },
  25. },
  26. },
  27. })
  28. ).toEqual({
  29. email: 'never',
  30. slack: 'never',
  31. });
  32. });
  33. });
  34. });
  35. describe('decideDefault', () => {
  36. describe('when there are no parent-specific settings', () => {
  37. describe('when the parent-independent settings match', () => {
  38. it('should return always when the settings are always', () => {
  39. expect(
  40. decideDefault('alerts', {
  41. alerts: {
  42. user: {
  43. me: {
  44. email: 'always',
  45. slack: 'always',
  46. },
  47. },
  48. },
  49. })
  50. ).toEqual('always');
  51. });
  52. it('should return never when the settings are never', () => {
  53. expect(
  54. decideDefault('alerts', {
  55. alerts: {
  56. user: {
  57. me: {
  58. email: 'never',
  59. slack: 'never',
  60. },
  61. },
  62. },
  63. })
  64. ).toEqual('never');
  65. });
  66. });
  67. describe('when the parent-independent settings do not match', () => {
  68. it('should return the always when the other value is never', () => {
  69. expect(
  70. decideDefault('alerts', {
  71. alerts: {
  72. user: {
  73. me: {
  74. email: 'always',
  75. slack: 'never',
  76. },
  77. },
  78. },
  79. })
  80. ).toEqual('always');
  81. });
  82. });
  83. });
  84. describe('when there are parent-specific settings', () => {
  85. describe('when the parent-specific settings are "below" the parent-independent settings', () => {
  86. it('should "prioritize" always over never', () => {
  87. expect(
  88. decideDefault('alerts', {
  89. alerts: {
  90. user: {
  91. me: {
  92. email: 'never',
  93. slack: 'never',
  94. },
  95. },
  96. project: {
  97. 1: {
  98. email: 'always',
  99. slack: 'always',
  100. },
  101. },
  102. },
  103. })
  104. ).toEqual('always');
  105. });
  106. it('should "prioritize" sometimes over always', () => {
  107. expect(
  108. decideDefault('alerts', {
  109. alerts: {
  110. user: {
  111. me: {
  112. email: 'never',
  113. slack: 'never',
  114. },
  115. },
  116. project: {
  117. 1: {
  118. email: 'subscribe_only',
  119. slack: 'subscribe_only',
  120. },
  121. },
  122. },
  123. })
  124. ).toEqual('subscribe_only');
  125. });
  126. });
  127. describe('when the parent-specific settings are "above" the parent-independent settings', () => {
  128. it('should return the parent-specific settings', () => {
  129. expect(
  130. decideDefault('alerts', {
  131. alerts: {
  132. user: {
  133. me: {
  134. email: 'always',
  135. slack: 'always',
  136. },
  137. },
  138. project: {
  139. 1: {
  140. email: 'never',
  141. slack: 'never',
  142. },
  143. },
  144. },
  145. })
  146. ).toEqual('always');
  147. });
  148. });
  149. });
  150. });
  151. });