mriField.spec.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import MriField from 'sentry/views/alerts/rules/metric/mriField';
  4. describe('MRIField', () => {
  5. beforeEach(() => {
  6. MockApiClient.addMockResponse({
  7. url: '/organizations/org-slug/metrics/meta/',
  8. body: [
  9. {
  10. type: 'd',
  11. name: 'sentry.distribution.metric',
  12. unit: 'second',
  13. mri: 'd:custom/sentry.distribution.metric@second',
  14. operations: [
  15. 'avg',
  16. 'count',
  17. 'histogram',
  18. 'max',
  19. 'max_timestamp',
  20. 'min',
  21. 'min_timestamp',
  22. 'p50',
  23. 'p75',
  24. 'p90',
  25. 'p95',
  26. 'p99',
  27. 'sum',
  28. ],
  29. projectIds: [1],
  30. blockingStatus: [],
  31. },
  32. ],
  33. });
  34. });
  35. it('should call onChange with the new aggregate string when switching aggregates', async () => {
  36. const {project} = initializeOrg();
  37. const onChange = jest.fn();
  38. render(
  39. <MriField
  40. aggregate={'sum(d:custom/sentry.distribution.metric@second)'}
  41. onChange={onChange}
  42. project={project}
  43. />
  44. );
  45. await screen.findByText('Select an operation');
  46. await userEvent.click(screen.getByText('sum'));
  47. await userEvent.click(await screen.findByText('p95'));
  48. await waitFor(() =>
  49. expect(onChange).toHaveBeenCalledWith(
  50. 'p95(d:custom/sentry.distribution.metric@second)',
  51. {}
  52. )
  53. );
  54. });
  55. });