index.spec.tsx 2.0 KB

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