metricField.spec.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. function openSelectMenu(text) {
  8. const placeholder = screen.getByText(text);
  9. 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', function () {
  27. render(
  28. <Form initialData={{dataset: Dataset.ERRORS}} model={model}>
  29. <MetricField name="metric" organization={organization} />
  30. </Form>
  31. );
  32. openSelectMenu('(Required)');
  33. expect(screen.getByText('count()')).toBeInTheDocument();
  34. expect(screen.getByText('count_unique(…)')).toBeInTheDocument();
  35. // Select count_unique and verify the tags
  36. 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', function () {
  41. render(
  42. <Form initialData={{dataset: Dataset.TRANSACTIONS}} model={model}>
  43. <MetricField name="metric" organization={organization} />
  44. </Form>
  45. );
  46. openSelectMenu('(Required)');
  47. // 10 error aggregate configs
  48. [
  49. 'avg(…)',
  50. 'percentile(…)',
  51. 'p50(…)',
  52. 'p75(…)',
  53. 'p95(…)',
  54. 'p99(…)',
  55. 'p100(…)',
  56. 'failure_rate()',
  57. 'apdex(…)',
  58. 'count()',
  59. ].forEach(label => {
  60. expect(screen.getByText(label)).toBeInTheDocument();
  61. });
  62. userEvent.click(screen.getByText('avg(…)'));
  63. expect(model.fields.get('metric')).toBe('avg(transaction.duration)');
  64. openSelectMenu('transaction.duration');
  65. expect(screen.getByText('measurements.lcp')).toBeInTheDocument();
  66. expect(screen.getByText('measurements.fcp')).toBeInTheDocument();
  67. expect(screen.getByText('measurements.ttfb.requesttime')).toBeInTheDocument();
  68. });
  69. });