index.spec.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {EventsStats} from 'sentry-fixture/events';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import TriggersChart from 'sentry/views/alerts/rules/metric/triggers/chart';
  5. import {
  6. AlertRuleComparisonType,
  7. AlertRuleThresholdType,
  8. Dataset,
  9. } from 'sentry/views/alerts/rules/metric/types';
  10. describe('Incident Rules Create', () => {
  11. let eventStatsMock: jest.Func;
  12. let eventCountsMock: jest.Func;
  13. beforeEach(() => {
  14. eventStatsMock = MockApiClient.addMockResponse({
  15. url: '/organizations/org-slug/events-stats/',
  16. body: EventsStats(),
  17. });
  18. eventCountsMock = MockApiClient.addMockResponse({
  19. url: '/organizations/org-slug/events-meta/',
  20. body: {count: 5},
  21. });
  22. });
  23. afterEach(() => {
  24. MockApiClient.clearMockResponses();
  25. });
  26. const api = new MockApiClient();
  27. it('renders a metric', async () => {
  28. const {organization, project, router} = initializeOrg();
  29. render(
  30. <TriggersChart
  31. api={api}
  32. location={router.location}
  33. organization={organization}
  34. projects={[project]}
  35. query="event.type:error"
  36. timeWindow={1}
  37. aggregate="count()"
  38. dataset={Dataset.ERRORS}
  39. triggers={[]}
  40. environment={null}
  41. comparisonType={AlertRuleComparisonType.COUNT}
  42. resolveThreshold={null}
  43. thresholdType={AlertRuleThresholdType.BELOW}
  44. newAlertOrQuery
  45. onDataLoaded={() => {}}
  46. isQueryValid
  47. />
  48. );
  49. expect(await screen.findByTestId('area-chart')).toBeInTheDocument();
  50. expect(eventStatsMock).toHaveBeenCalledWith(
  51. expect.anything(),
  52. expect.objectContaining({
  53. query: {
  54. interval: '1m',
  55. project: [2],
  56. query: 'event.type:error',
  57. statsPeriod: '10000m',
  58. yAxis: 'count()',
  59. referrer: 'api.organization-event-stats',
  60. },
  61. })
  62. );
  63. expect(eventCountsMock).toHaveBeenCalledWith(
  64. expect.anything(),
  65. expect.objectContaining({
  66. query: {
  67. project: ['2'],
  68. query: 'event.type:error',
  69. statsPeriod: '10000m',
  70. environment: [],
  71. },
  72. })
  73. );
  74. });
  75. });