notificationSettings.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import {SELF_NOTIFICATION_SETTINGS_TYPES} from 'sentry/views/settings/account/notifications/constants';
  5. import {NOTIFICATION_SETTING_FIELDS} from 'sentry/views/settings/account/notifications/fields2';
  6. import NotificationSettings from 'sentry/views/settings/account/notifications/notificationSettings';
  7. function renderMockRequests({}: {}) {
  8. MockApiClient.addMockResponse({
  9. url: '/users/me/notifications/',
  10. method: 'GET',
  11. body: {
  12. personalActivityNotifications: true,
  13. selfAssignOnResolve: true,
  14. },
  15. });
  16. }
  17. describe('NotificationSettings', function () {
  18. it('should render', async function () {
  19. const {router, organization} = initializeOrg();
  20. renderMockRequests({});
  21. render(<NotificationSettings organizations={[organization]} />, {
  22. router,
  23. });
  24. // There are 8 notification setting Selects/Toggles.
  25. for (const field of [
  26. 'alerts',
  27. 'workflow',
  28. 'deploy',
  29. 'approval',
  30. 'reports',
  31. 'email',
  32. ...SELF_NOTIFICATION_SETTINGS_TYPES,
  33. ]) {
  34. expect(
  35. await screen.findByText(String(NOTIFICATION_SETTING_FIELDS[field].label))
  36. ).toBeInTheDocument();
  37. }
  38. expect(screen.getByText('Issue Alerts')).toBeInTheDocument();
  39. });
  40. it('renders quota section with feature flag', async function () {
  41. const {router, organization} = initializeOrg({
  42. organization: {
  43. features: ['user-spend-notifications-settings'],
  44. },
  45. });
  46. renderMockRequests({});
  47. render(<NotificationSettings organizations={[organization]} />, {
  48. router,
  49. });
  50. // There are 9 notification setting Selects/Toggles.
  51. for (const field of [
  52. 'alerts',
  53. 'workflow',
  54. 'deploy',
  55. 'approval',
  56. 'reports',
  57. 'email',
  58. 'quota',
  59. ...SELF_NOTIFICATION_SETTINGS_TYPES,
  60. ]) {
  61. expect(
  62. await screen.findByText(String(NOTIFICATION_SETTING_FIELDS[field].label))
  63. ).toBeInTheDocument();
  64. }
  65. expect(screen.getByText('Issue Alerts')).toBeInTheDocument();
  66. });
  67. it('renders spend section instead of quota section with feature flag', async function () {
  68. const {router, organization} = initializeOrg({
  69. organization: {
  70. features: ['user-spend-notifications-settings', 'spend-visibility-notifications'],
  71. },
  72. });
  73. const organizationNoFlag = OrganizationFixture();
  74. organizationNoFlag.features.push('user-spend-notifications-settings');
  75. renderMockRequests({});
  76. render(<NotificationSettings organizations={[organization, organizationNoFlag]} />, {
  77. router,
  78. });
  79. expect(await screen.findByText('Spend')).toBeInTheDocument();
  80. expect(screen.queryByText('Quota')).not.toBeInTheDocument();
  81. });
  82. });