eapField.spec.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  4. import EAPField from 'sentry/views/alerts/rules/metric/eapField';
  5. import {SpanTagsProvider} from 'sentry/views/explore/contexts/spanTagsContext';
  6. describe('EAPField', () => {
  7. const organization = OrganizationFixture();
  8. let fieldsMock;
  9. beforeEach(() => {
  10. fieldsMock = MockApiClient.addMockResponse({
  11. url: `/organizations/${organization.slug}/spans/fields/`,
  12. method: 'GET',
  13. });
  14. });
  15. it('renders', () => {
  16. render(
  17. <SpanTagsProvider dataset={DiscoverDatasets.SPANS_EAP} enabled>
  18. <EAPField aggregate={'count(span.duration)'} onChange={() => {}} />
  19. </SpanTagsProvider>
  20. );
  21. expect(fieldsMock).toHaveBeenCalledWith(
  22. `/organizations/${organization.slug}/spans/fields/`,
  23. expect.objectContaining({
  24. query: expect.objectContaining({type: 'number'}),
  25. })
  26. );
  27. expect(fieldsMock).toHaveBeenCalledWith(
  28. `/organizations/${organization.slug}/spans/fields/`,
  29. expect.objectContaining({
  30. query: expect.objectContaining({type: 'string'}),
  31. })
  32. );
  33. screen.getByText('count');
  34. screen.getByText('span.duration');
  35. });
  36. it('should call onChange with the new aggregate string when switching aggregates', async () => {
  37. const onChange = jest.fn();
  38. render(
  39. <SpanTagsProvider dataset={DiscoverDatasets.SPANS_EAP} enabled>
  40. <EAPField aggregate={'count(span.duration)'} onChange={onChange} />
  41. </SpanTagsProvider>
  42. );
  43. expect(fieldsMock).toHaveBeenCalledWith(
  44. `/organizations/${organization.slug}/spans/fields/`,
  45. expect.objectContaining({
  46. query: expect.objectContaining({type: 'number'}),
  47. })
  48. );
  49. expect(fieldsMock).toHaveBeenCalledWith(
  50. `/organizations/${organization.slug}/spans/fields/`,
  51. expect.objectContaining({
  52. query: expect.objectContaining({type: 'string'}),
  53. })
  54. );
  55. await userEvent.click(screen.getByText('count'));
  56. await userEvent.click(await screen.findByText('max'));
  57. await waitFor(() => expect(onChange).toHaveBeenCalledWith('max(span.duration)', {}));
  58. });
  59. });