index.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import AlertWizard from 'sentry/views/alerts/wizard/index';
  5. describe('AlertWizard', () => {
  6. beforeEach(() => {
  7. ConfigStore.init();
  8. });
  9. it('sets crash free dataset to metrics', async () => {
  10. const {organization, project, routerProps, router} = initializeOrg({
  11. organization: {
  12. features: [
  13. 'alert-crash-free-metrics',
  14. 'incidents',
  15. 'performance-view',
  16. 'crash-rate-alerts',
  17. ],
  18. access: ['org:write', 'alerts:write'],
  19. },
  20. });
  21. render(
  22. <AlertWizard
  23. organization={organization}
  24. projectId={project.slug}
  25. {...routerProps}
  26. />,
  27. {router, organization}
  28. );
  29. await userEvent.click(screen.getByText('Crash Free Session Rate'));
  30. await userEvent.click(screen.getByText('Set Conditions'));
  31. expect(router.push).toHaveBeenCalledWith({
  32. pathname: '/organizations/org-slug/alerts/new/metric/',
  33. query: {
  34. aggregate:
  35. 'percentage(sessions_crashed, sessions) AS _crash_rate_alert_aggregate',
  36. dataset: 'metrics',
  37. eventTypes: 'session',
  38. project: 'project-slug',
  39. referrer: undefined,
  40. },
  41. });
  42. });
  43. it('should render alerts for enabled features', () => {
  44. const {organization, project, routerProps, router} = initializeOrg({
  45. organization: {
  46. features: [
  47. 'alert-crash-free-metrics',
  48. 'incidents',
  49. 'performance-view',
  50. 'crash-rate-alerts',
  51. 'insights-addon-modules',
  52. 'uptime',
  53. ],
  54. access: ['org:write', 'alerts:write'],
  55. },
  56. });
  57. render(
  58. <AlertWizard
  59. organization={organization}
  60. projectId={project.slug}
  61. {...routerProps}
  62. />,
  63. {router, organization}
  64. );
  65. expect(screen.getByText('Errors')).toBeInTheDocument();
  66. expect(screen.getByText('Sessions')).toBeInTheDocument();
  67. expect(screen.getByText('Performance')).toBeInTheDocument();
  68. expect(screen.getByText('Uptime Monitoring')).toBeInTheDocument();
  69. expect(screen.getByText('Custom')).toBeInTheDocument();
  70. const alertGroups = screen.getAllByRole('radiogroup');
  71. expect(alertGroups).toHaveLength(5);
  72. });
  73. it('should only render alerts for errors in self-hosted errors only', () => {
  74. ConfigStore.set('isSelfHostedErrorsOnly', true);
  75. const {organization, project, routerProps, router} = initializeOrg({
  76. organization: {
  77. features: [
  78. 'alert-crash-free-metrics',
  79. 'incidents',
  80. 'performance-view',
  81. 'crash-rate-alerts',
  82. ],
  83. access: ['org:write', 'alerts:write'],
  84. },
  85. });
  86. render(
  87. <AlertWizard
  88. organization={organization}
  89. projectId={project.slug}
  90. {...routerProps}
  91. />,
  92. {router, organization}
  93. );
  94. expect(screen.getByText('Errors')).toBeInTheDocument();
  95. const alertGroups = screen.getAllByRole('radiogroup');
  96. expect(alertGroups).toHaveLength(1);
  97. });
  98. it('shows uptime alert according to feature flag', () => {
  99. const {organization, project, routerProps, router} = initializeOrg({
  100. organization: {
  101. features: [
  102. 'alert-crash-free-metrics',
  103. 'incidents',
  104. 'performance-view',
  105. 'crash-rate-alerts',
  106. 'uptime',
  107. ],
  108. access: ['org:write', 'alerts:write'],
  109. },
  110. });
  111. render(
  112. <AlertWizard
  113. organization={organization}
  114. projectId={project.slug}
  115. {...routerProps}
  116. />,
  117. {router, organization}
  118. );
  119. expect(screen.getByText('Uptime Monitor')).toBeInTheDocument();
  120. });
  121. });