index.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. ],
  52. access: ['org:write', 'alerts:write'],
  53. },
  54. });
  55. render(
  56. <AlertWizard
  57. organization={organization}
  58. projectId={project.slug}
  59. {...routerProps}
  60. />,
  61. {router, organization}
  62. );
  63. expect(screen.getByText('Errors')).toBeInTheDocument();
  64. expect(screen.getByText('Sessions')).toBeInTheDocument();
  65. expect(screen.getByText('Performance')).toBeInTheDocument();
  66. expect(screen.getByText('Custom')).toBeInTheDocument();
  67. const alertGroups = screen.getAllByRole('radiogroup');
  68. expect(alertGroups.length).toEqual(4);
  69. });
  70. it('should only render alerts for errors in self-hosted errors only', () => {
  71. ConfigStore.set('isSelfHostedErrorsOnly', true);
  72. const {organization, project, routerProps, router} = initializeOrg({
  73. organization: {
  74. features: [
  75. 'alert-crash-free-metrics',
  76. 'incidents',
  77. 'performance-view',
  78. 'crash-rate-alerts',
  79. ],
  80. access: ['org:write', 'alerts:write'],
  81. },
  82. });
  83. render(
  84. <AlertWizard
  85. organization={organization}
  86. projectId={project.slug}
  87. {...routerProps}
  88. />,
  89. {router, organization}
  90. );
  91. expect(screen.getByText('Errors')).toBeInTheDocument();
  92. const alertGroups = screen.getAllByRole('radiogroup');
  93. expect(alertGroups.length).toEqual(1);
  94. });
  95. });