notificationSettings.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. organization: {
  61. features: ['slack-overage-notifications'],
  62. },
  63. });
  64. renderMockRequests({
  65. notificationSettings: {
  66. alerts: {user: {me: {email: 'never', slack: 'never'}}},
  67. deploy: {user: {me: {email: 'never', slack: 'never'}}},
  68. workflow: {user: {me: {email: 'never', slack: 'never'}}},
  69. },
  70. });
  71. render(<NotificationSettings organizations={[organization]} />, {
  72. context: routerContext,
  73. });
  74. // There are 9 notification setting Selects/Toggles.
  75. [
  76. 'alerts',
  77. 'workflow',
  78. 'deploy',
  79. 'approval',
  80. 'quota',
  81. 'reports',
  82. 'email',
  83. ...SELF_NOTIFICATION_SETTINGS_TYPES,
  84. ].forEach(field => {
  85. expect(
  86. screen.getByText(String(NOTIFICATION_SETTING_FIELDS[field].label))
  87. ).toBeInTheDocument();
  88. });
  89. });
  90. });