index.spec.tsx 2.2 KB

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