metricsExtractionRulesTable.spec.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import type {MetricsExtractionRule} from 'sentry/types/metrics';
  9. import {MetricsExtractionRulesTable} from './metricsExtractionRulesTable';
  10. describe('Metrics Extraction Rules Table', function () {
  11. const {project, organization} = initializeOrg();
  12. beforeEach(function () {
  13. MockApiClient.addMockResponse({
  14. url: `/projects/${organization.slug}/${project.id}/metrics/extraction-rules/`,
  15. method: 'GET',
  16. body: [
  17. {
  18. spanAttribute: 'span.duration',
  19. projectId: Number(project.id),
  20. createdById: null,
  21. dateAdded: '2021-09-29T20:00:00',
  22. dateUpdated: '2021-09-29T20:00:00',
  23. aggregates: [
  24. 'count',
  25. 'count_unique',
  26. 'min',
  27. 'max',
  28. 'sum',
  29. 'avg',
  30. 'p50',
  31. 'p75',
  32. 'p95',
  33. 'p99',
  34. ],
  35. unit: 'millisecond',
  36. tags: ['release', 'environment', 'sdk.name', 'span.op'],
  37. conditions: [
  38. {
  39. id: 1,
  40. value: '',
  41. mris: [
  42. 'g:custom/span_attribute_1@millisecond',
  43. 's:custom/span_attribute_1@millisecond',
  44. 'd:custom/span_attribute_1@millisecond',
  45. 'c:custom/span_attribute_1@millisecond',
  46. ],
  47. },
  48. ],
  49. } satisfies MetricsExtractionRule,
  50. ],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: `/organizations/${organization.slug}/spans/fields/`,
  54. body: [],
  55. });
  56. MockApiClient.addMockResponse({
  57. url: `/organizations/${organization.slug}/metrics/query/`,
  58. method: 'POST',
  59. body: {data: []},
  60. });
  61. });
  62. it('shall open the modal to edit a rule by clicking on edit', async function () {
  63. render(<MetricsExtractionRulesTable project={project} />);
  64. renderGlobalModal();
  65. const editButton = await screen.findByLabelText('Edit metric');
  66. await userEvent.click(editButton);
  67. expect(
  68. await screen.findByRole('heading', {name: /span.duration/})
  69. ).toBeInTheDocument();
  70. });
  71. });