metricsExtractionRuleForm.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import selectEvent from 'sentry-test/selectEvent';
  4. import {textWithMarkupMatcher} from 'sentry-test/utils';
  5. import {INITIAL_DATA} from 'sentry/views/settings/projectMetrics/metricsExtractionRuleCreateModal';
  6. import {MetricsExtractionRuleForm} from 'sentry/views/settings/projectMetrics/metricsExtractionRuleForm';
  7. function renderMockRequests({orgSlug, projectId}: {orgSlug: string; projectId: string}) {
  8. MockApiClient.addMockResponse({
  9. url: `/organizations/${orgSlug}/spans/fields/`,
  10. body: [],
  11. });
  12. MockApiClient.addMockResponse({
  13. url: `/projects/${orgSlug}/${projectId}/metrics/extraction-rules/`,
  14. method: 'GET',
  15. body: [
  16. {
  17. aggregates: ['count'],
  18. conditions: [{id: 102, value: '', mris: ['c:custom/span_attribute_102@none']}],
  19. createdById: 3142223,
  20. dateAdded: '2024-07-29T12:04:23.196785Z',
  21. dateUpdated: '2024-07-29T12:04:23.197008Z',
  22. projectId,
  23. spanAttribute: 'A',
  24. tags: ['release', 'environment'],
  25. unit: 'none',
  26. },
  27. ],
  28. });
  29. }
  30. describe('Metrics Extraction Rule Form', function () {
  31. it('by focusing on the "select span attribute" field, the UI shall display a hint about custom attribute', async function () {
  32. const {project} = initializeOrg();
  33. renderMockRequests({orgSlug: project.organization.slug, projectId: project.id});
  34. render(
  35. <MetricsExtractionRuleForm initialData={INITIAL_DATA} projectId={project.id} />
  36. );
  37. await userEvent.click(screen.getByText('Select span attribute'));
  38. expect(screen.getByText(/See how to instrument a custom attribute/)).toHaveAttribute(
  39. 'href',
  40. 'https://docs.sentry.io/product/explore/metrics/metrics-set-up/'
  41. );
  42. });
  43. it('by focusing on the "group and filter by" field, the UI shall display a hint about custom attribute', async function () {
  44. const {project} = initializeOrg();
  45. renderMockRequests({orgSlug: project.organization.slug, projectId: project.id});
  46. render(
  47. <MetricsExtractionRuleForm initialData={INITIAL_DATA} projectId={project.id} />
  48. );
  49. await userEvent.click(screen.getByLabelText('Select tags'));
  50. expect(screen.getByText(/See how to instrument a custom tag/)).toHaveAttribute(
  51. 'href',
  52. 'https://docs.sentry.io/product/explore/metrics/metrics-set-up/'
  53. );
  54. });
  55. it('by selecting a custom attribute the alert about delay in ingestion shall render different info', async function () {
  56. const {project} = initializeOrg();
  57. renderMockRequests({orgSlug: project.organization.slug, projectId: project.id});
  58. render(
  59. <MetricsExtractionRuleForm initialData={INITIAL_DATA} projectId={project.id} />
  60. );
  61. await userEvent.type(screen.getByText('Select span attribute'), 'new-metric');
  62. await userEvent.click(
  63. // the dom renders 2x of this text because of aria
  64. screen.getAllByText(textWithMarkupMatcher('Create "new-metric"'))[1]
  65. );
  66. await userEvent.click(screen.getByText(/we’ll need a moment/));
  67. expect(
  68. screen.getByText(
  69. /collect data from spans sent after you created the metric and not before/
  70. )
  71. ).toBeInTheDocument();
  72. expect(screen.getByText(/instrument your custom attribute/)).toHaveAttribute(
  73. 'href',
  74. 'https://docs.sentry.io/product/explore/metrics/metrics-set-up/'
  75. );
  76. await selectEvent.select(screen.getByText('new-metric'), 'browser.name');
  77. expect(
  78. screen.getByText(
  79. /if you deleted an existing metric, then we’ll stop collecting data/
  80. )
  81. ).toBeInTheDocument();
  82. });
  83. });