metricField.spec.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import Form from 'sentry/components/forms/form';
  4. import FormModel from 'sentry/components/forms/model';
  5. import MetricField from 'sentry/views/alerts/rules/metric/metricField';
  6. import {Dataset} from 'sentry/views/alerts/rules/metric/types';
  7. async function openSelectMenu(text) {
  8. const placeholder = screen.getByText(text);
  9. await userEvent.type(placeholder, '{keyDown}');
  10. }
  11. describe('MetricField', function () {
  12. let model;
  13. const {organization} = initializeOrg({
  14. organization: {features: ['performance-view']},
  15. });
  16. beforeEach(function () {
  17. model = new FormModel();
  18. });
  19. it('renders', function () {
  20. render(
  21. <Form initialData={{dataset: Dataset.ERRORS}} model={model}>
  22. <MetricField name="metric" organization={organization} />
  23. </Form>
  24. );
  25. });
  26. it('has a select subset of error fields', async function () {
  27. render(
  28. <Form initialData={{dataset: Dataset.ERRORS}} model={model}>
  29. <MetricField name="metric" organization={organization} />
  30. </Form>
  31. );
  32. await openSelectMenu('(Required)');
  33. expect(screen.getByText('count()')).toBeInTheDocument();
  34. expect(screen.getByText('count_unique(…)')).toBeInTheDocument();
  35. // Select count_unique and verify the tags
  36. await userEvent.click(screen.getByText('count_unique(…)'));
  37. expect(model.fields.get('metric')).toBe('count_unique(tags[sentry:user])');
  38. expect(screen.getByText('tags[sentry:user]')).toBeInTheDocument();
  39. });
  40. it('has a select subset of transaction fields', async function () {
  41. render(
  42. <Form initialData={{dataset: Dataset.TRANSACTIONS}} model={model}>
  43. <MetricField name="metric" organization={organization} />
  44. </Form>
  45. );
  46. await openSelectMenu('(Required)');
  47. // 9 error aggregate configs
  48. [
  49. 'avg(…)',
  50. 'p50(…)',
  51. 'p75(…)',
  52. 'p95(…)',
  53. 'p99(…)',
  54. 'p100(…)',
  55. 'failure_rate()',
  56. 'apdex(…)',
  57. 'count()',
  58. ].forEach(label => {
  59. expect(screen.getByText(label)).toBeInTheDocument();
  60. });
  61. await userEvent.click(screen.getByText('avg(…)'));
  62. expect(model.fields.get('metric')).toBe('avg(transaction.duration)');
  63. await openSelectMenu('transaction.duration');
  64. expect(screen.getByText('measurements.lcp')).toBeInTheDocument();
  65. expect(screen.getByText('measurements.fcp')).toBeInTheDocument();
  66. expect(screen.getByText('measurements.ttfb.requesttime')).toBeInTheDocument();
  67. });
  68. });