eapField.spec.tsx 1.9 KB

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