eapField.spec.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import EAPField from 'sentry/views/alerts/rules/metric/eapField';
  4. describe('EAPField', () => {
  5. it('renders', () => {
  6. const {project} = initializeOrg();
  7. render(
  8. <EAPField
  9. aggregate={'count(span.duration)'}
  10. onChange={() => {}}
  11. project={project}
  12. />
  13. );
  14. screen.getByText('count');
  15. screen.getByText('span.duration');
  16. });
  17. it('should call onChange with the new aggregate string when switching aggregates', async () => {
  18. const {project} = initializeOrg();
  19. const onChange = jest.fn();
  20. render(
  21. <EAPField
  22. aggregate={'count(span.duration)'}
  23. onChange={onChange}
  24. project={project}
  25. />
  26. );
  27. await userEvent.click(screen.getByText('count'));
  28. await userEvent.click(await screen.findByText('max'));
  29. await waitFor(() => expect(onChange).toHaveBeenCalledWith('max(span.duration)', {}));
  30. });
  31. });