create.spec.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/alert-rules/available-actions/',
  30. body: [
  31. {
  32. allowedTargetTypes: ['user', 'team'],
  33. integrationName: null,
  34. type: 'email',
  35. integrationId: null,
  36. },
  37. ],
  38. });
  39. });
  40. it('renders', async function () {
  41. const {organization, project} = initializeOrg();
  42. MockApiClient.addMockResponse({
  43. url: `/organizations/${organization.slug}/events-meta/`,
  44. body: {count: 0},
  45. });
  46. render(
  47. <MetricRulesCreate
  48. {...RouteComponentPropsFixture()}
  49. eventView={EventView.fromLocation(LocationFixture())}
  50. params={{projectId: project.slug}}
  51. organization={organization}
  52. project={project}
  53. userTeamIds={[]}
  54. />
  55. );
  56. await waitFor(() =>
  57. expect(eventStatsMock).toHaveBeenCalledWith(
  58. expect.anything(),
  59. expect.objectContaining({
  60. query: {
  61. interval: '60m',
  62. project: [2],
  63. query: 'event.type:error',
  64. statsPeriod: '9998m',
  65. yAxis: 'count()',
  66. referrer: 'api.organization-event-stats',
  67. },
  68. })
  69. )
  70. );
  71. });
  72. });