create.spec.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {EventsStatsFixture} from 'sentry-fixture/events';
  2. import {LocationFixture} from 'sentry-fixture/locationFixture';
  3. import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, waitFor} from 'sentry-test/reactTestingLibrary';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import MetricRulesCreate from 'sentry/views/alerts/rules/metric/create';
  8. describe('Incident Rules Create', function () {
  9. let eventStatsMock;
  10. beforeEach(function () {
  11. MockApiClient.clearMockResponses();
  12. MockApiClient.addMockResponse({
  13. url: '/organizations/org-slug/tags/',
  14. body: [],
  15. });
  16. MockApiClient.addMockResponse({
  17. url: '/organizations/org-slug/users/',
  18. body: [],
  19. });
  20. MockApiClient.addMockResponse({
  21. url: '/projects/org-slug/project-slug/environments/',
  22. body: [],
  23. });
  24. eventStatsMock = MockApiClient.addMockResponse({
  25. url: '/organizations/org-slug/events-stats/',
  26. body: EventsStatsFixture(),
  27. });
  28. MockApiClient.addMockResponse({
  29. url: '/organizations/org-slug/events/anomalies/',
  30. body: [],
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/organizations/org-slug/alert-rules/available-actions/',
  34. body: [
  35. {
  36. allowedTargetTypes: ['user', 'team'],
  37. integrationName: null,
  38. type: 'email',
  39. integrationId: null,
  40. },
  41. ],
  42. });
  43. });
  44. it('renders', async function () {
  45. const {organization, project} = initializeOrg();
  46. MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/events-meta/`,
  48. body: {count: 0},
  49. });
  50. render(
  51. <MetricRulesCreate
  52. {...RouteComponentPropsFixture()}
  53. eventView={EventView.fromLocation(LocationFixture())}
  54. params={{projectId: project.slug}}
  55. organization={organization}
  56. project={project}
  57. userTeamIds={[]}
  58. />
  59. );
  60. await waitFor(() =>
  61. expect(eventStatsMock).toHaveBeenCalledWith(
  62. expect.anything(),
  63. expect.objectContaining({
  64. query: {
  65. interval: '60m',
  66. project: [2],
  67. query: 'event.type:error',
  68. statsPeriod: '9998m',
  69. yAxis: 'count()',
  70. referrer: 'api.organization-event-stats',
  71. },
  72. })
  73. )
  74. );
  75. });
  76. });