notificationSettings.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {
  4. NotificationSettingsObject,
  5. SELF_NOTIFICATION_SETTINGS_TYPES,
  6. } from 'sentry/views/settings/account/notifications/constants';
  7. import {NOTIFICATION_SETTING_FIELDS} from 'sentry/views/settings/account/notifications/fields2';
  8. import NotificationSettings from 'sentry/views/settings/account/notifications/notificationSettings';
  9. function renderMockRequests({
  10. notificationSettings,
  11. }: {
  12. notificationSettings: NotificationSettingsObject;
  13. }) {
  14. MockApiClient.addMockResponse({
  15. url: '/users/me/notification-settings/',
  16. method: 'GET',
  17. body: notificationSettings,
  18. });
  19. MockApiClient.addMockResponse({
  20. url: '/users/me/notifications/',
  21. method: 'GET',
  22. body: {
  23. personalActivityNotifications: true,
  24. selfAssignOnResolve: true,
  25. weeklyReports: true,
  26. },
  27. });
  28. }
  29. describe('NotificationSettings', function () {
  30. it('should render', function () {
  31. const {routerContext, organization} = initializeOrg();
  32. renderMockRequests({
  33. notificationSettings: {
  34. alerts: {user: {me: {email: 'never', slack: 'never'}}},
  35. deploy: {user: {me: {email: 'never', slack: 'never'}}},
  36. workflow: {user: {me: {email: 'never', slack: 'never'}}},
  37. },
  38. });
  39. render(<NotificationSettings organizations={[organization]} />, {
  40. context: routerContext,
  41. });
  42. // There are 8 notification setting Selects/Toggles.
  43. [
  44. 'alerts',
  45. 'workflow',
  46. 'deploy',
  47. 'approval',
  48. 'reports',
  49. 'email',
  50. ...SELF_NOTIFICATION_SETTINGS_TYPES,
  51. ].forEach(field => {
  52. expect(
  53. screen.getByText(String(NOTIFICATION_SETTING_FIELDS[field].label))
  54. ).toBeInTheDocument();
  55. });
  56. expect(screen.getByText('Issue Alerts')).toBeInTheDocument();
  57. });
  58. it('renders quota section with feature flag', function () {
  59. const {routerContext, organization} = initializeOrg({
  60. ...initializeOrg(),
  61. organization: {
  62. ...initializeOrg().organization,
  63. features: ['slack-overage-notifications'],
  64. },
  65. });
  66. renderMockRequests({
  67. notificationSettings: {
  68. alerts: {user: {me: {email: 'never', slack: 'never'}}},
  69. deploy: {user: {me: {email: 'never', slack: 'never'}}},
  70. workflow: {user: {me: {email: 'never', slack: 'never'}}},
  71. },
  72. });
  73. render(<NotificationSettings organizations={[organization]} />, {
  74. context: routerContext,
  75. });
  76. // There are 9 notification setting Selects/Toggles.
  77. [
  78. 'alerts',
  79. 'workflow',
  80. 'deploy',
  81. 'approval',
  82. 'quota',
  83. 'reports',
  84. 'email',
  85. ...SELF_NOTIFICATION_SETTINGS_TYPES,
  86. ].forEach(field => {
  87. expect(
  88. screen.getByText(String(NOTIFICATION_SETTING_FIELDS[field].label))
  89. ).toBeInTheDocument();
  90. });
  91. });
  92. it('renders active release monitor', function () {
  93. const {routerContext, organization} = initializeOrg({
  94. ...initializeOrg(),
  95. organization: {
  96. ...initializeOrg().organization,
  97. features: ['active-release-monitor-alpha'],
  98. },
  99. });
  100. renderMockRequests({
  101. notificationSettings: {
  102. alerts: {user: {me: {email: 'never', slack: 'never'}}},
  103. deploy: {user: {me: {email: 'never', slack: 'never'}}},
  104. workflow: {user: {me: {email: 'never', slack: 'never'}}},
  105. },
  106. });
  107. render(<NotificationSettings organizations={[organization]} />, {
  108. context: routerContext,
  109. });
  110. // There are 9 notification setting Selects/Toggles.
  111. [
  112. 'alerts',
  113. 'activeRelease',
  114. 'workflow',
  115. 'deploy',
  116. 'approval',
  117. 'reports',
  118. 'email',
  119. ...SELF_NOTIFICATION_SETTINGS_TYPES,
  120. ].forEach(field => {
  121. if (field === 'activeRelease') {
  122. expect(screen.getByText('Release Issues')).toBeInTheDocument();
  123. return;
  124. }
  125. expect(
  126. screen.getByText(String(NOTIFICATION_SETTING_FIELDS[field].label))
  127. ).toBeInTheDocument();
  128. });
  129. });
  130. });