metricsExtractionRulesTable.spec.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. waitForElementToBeRemoved,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import type {MetricsQueryApiResponse} from 'sentry/types';
  10. import {MetricsExtractionRulesTable} from 'sentry/views/settings/projectMetrics/metricsExtractionRulesTable';
  11. function renderMockRequests({
  12. orgSlug,
  13. projectId,
  14. metricsQueryApiResponse,
  15. }: {
  16. orgSlug: string;
  17. projectId: string;
  18. metricsQueryApiResponse?: Partial<MetricsQueryApiResponse>;
  19. }) {
  20. MockApiClient.addMockResponse({
  21. url: `/projects/${orgSlug}/${projectId}/metrics/extraction-rules/`,
  22. method: 'GET',
  23. body: [
  24. {
  25. spanAttribute: 'span.duration',
  26. aggregates: [
  27. 'count',
  28. 'count_unique',
  29. 'min',
  30. 'max',
  31. 'sum',
  32. 'avg',
  33. 'p50',
  34. 'p75',
  35. 'p95',
  36. 'p99',
  37. ],
  38. unit: 'millisecond',
  39. tags: ['browser.name'],
  40. conditions: [
  41. {
  42. id: 66,
  43. value: '',
  44. mris: [
  45. 'c:custom/span_attribute_66@millisecond',
  46. 's:custom/span_attribute_66@millisecond',
  47. 'd:custom/span_attribute_66@millisecond',
  48. 'g:custom/span_attribute_66@millisecond',
  49. ],
  50. },
  51. ],
  52. projectId,
  53. createdById: 3242858,
  54. dateAdded: '2024-07-17T07:06:33.253094Z',
  55. dateUpdated: '2024-07-17T21:27:54.742586Z',
  56. },
  57. {
  58. spanAttribute: 'browser.name',
  59. aggregates: ['count'],
  60. unit: 'none',
  61. tags: ['release'],
  62. conditions: [
  63. {
  64. id: 67,
  65. value: '',
  66. mris: [
  67. 'c:custom/span_attribute_67@none',
  68. 's:custom/span_attribute_67@none',
  69. 'd:custom/span_attribute_67@none',
  70. 'g:custom/span_attribute_67@none',
  71. ],
  72. },
  73. ],
  74. projectId,
  75. createdById: 588685,
  76. dateAdded: '2024-07-17T21:32:15.297483Z',
  77. dateUpdated: '2024-07-17T21:33:41.060903Z',
  78. },
  79. ],
  80. });
  81. MockApiClient.addMockResponse({
  82. url: `/organizations/${orgSlug}/spans/fields/`,
  83. body: [],
  84. });
  85. MockApiClient.addMockResponse({
  86. url: `/organizations/${orgSlug}/metrics/query/`,
  87. method: 'POST',
  88. body: metricsQueryApiResponse ?? {
  89. data: [
  90. [
  91. {
  92. by: {
  93. mri: 'c:custom/span_attribute_67@none',
  94. },
  95. totals: 2703.0,
  96. },
  97. ],
  98. ],
  99. start: '2024-07-16T21:00:00Z',
  100. end: '2024-07-17T22:00:00Z',
  101. },
  102. });
  103. }
  104. describe('Metrics Extraction Rules Table', function () {
  105. const {project, organization} = initializeOrg();
  106. it('shall open the modal to edit a rule by clicking on edit', async function () {
  107. renderMockRequests({orgSlug: organization.slug, projectId: project.id});
  108. render(<MetricsExtractionRulesTable project={project} />);
  109. renderGlobalModal();
  110. const editButtons = await screen.findAllByLabelText('Edit metric');
  111. await userEvent.click(editButtons[1]);
  112. expect(await screen.findByRole('heading', {name: 'Edit Metric'})).toBeInTheDocument();
  113. });
  114. it('shall display cardinality limit warning', async function () {
  115. renderMockRequests({orgSlug: organization.slug, projectId: project.id});
  116. render(<MetricsExtractionRulesTable project={project} />);
  117. expect(
  118. await screen.findByLabelText('Exceeding the cardinality limit warning')
  119. ).toBeInTheDocument();
  120. });
  121. it('shall NOT display cardinality limit warning', async function () {
  122. renderMockRequests({
  123. orgSlug: organization.slug,
  124. projectId: project.id,
  125. metricsQueryApiResponse: {
  126. data: [],
  127. },
  128. });
  129. render(<MetricsExtractionRulesTable project={project} />);
  130. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  131. expect(
  132. screen.queryByLabelText('Exceeding the cardinality limit warning')
  133. ).not.toBeInTheDocument();
  134. });
  135. });