index.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. ],
  53. access: ['org:write', 'alerts:write'],
  54. },
  55. });
  56. render(
  57. <AlertWizard
  58. organization={organization}
  59. projectId={project.slug}
  60. {...routerProps}
  61. />,
  62. {router, organization}
  63. );
  64. expect(screen.getByText('Errors')).toBeInTheDocument();
  65. expect(screen.getByText('Sessions')).toBeInTheDocument();
  66. expect(screen.getByText('Performance')).toBeInTheDocument();
  67. expect(screen.getByText('Uptime Monitoring')).toBeInTheDocument();
  68. expect(screen.getByText('LLM Monitoring')).toBeInTheDocument();
  69. expect(screen.getByText('Custom')).toBeInTheDocument();
  70. const alertGroups = screen.getAllByRole('radiogroup');
  71. expect(alertGroups.length).toEqual(6);
  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.length).toEqual(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. ],
  107. access: ['org:write', 'alerts:write'],
  108. },
  109. });
  110. render(
  111. <AlertWizard
  112. organization={organization}
  113. projectId={project.slug}
  114. {...routerProps}
  115. />,
  116. {router, organization}
  117. );
  118. expect(screen.getByText('Uptime Monitor')).toBeInTheDocument();
  119. });
  120. });