index.spec.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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('LLM Monitoring')).toBeInTheDocument();
  68. expect(screen.getByText('Custom')).toBeInTheDocument();
  69. const alertGroups = screen.getAllByRole('radiogroup');
  70. expect(alertGroups.length).toEqual(5);
  71. });
  72. it('should only render alerts for errors in self-hosted errors only', () => {
  73. ConfigStore.set('isSelfHostedErrorsOnly', true);
  74. const {organization, project, routerProps, router} = initializeOrg({
  75. organization: {
  76. features: [
  77. 'alert-crash-free-metrics',
  78. 'incidents',
  79. 'performance-view',
  80. 'crash-rate-alerts',
  81. ],
  82. access: ['org:write', 'alerts:write'],
  83. },
  84. });
  85. render(
  86. <AlertWizard
  87. organization={organization}
  88. projectId={project.slug}
  89. {...routerProps}
  90. />,
  91. {router, organization}
  92. );
  93. expect(screen.getByText('Errors')).toBeInTheDocument();
  94. const alertGroups = screen.getAllByRole('radiogroup');
  95. expect(alertGroups.length).toEqual(1);
  96. });
  97. });