metricsExtractionRulesTable.spec.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import * as useNavigate from 'sentry/utils/useNavigate';
  9. import {MetricsExtractionRulesTable} from './metricsExtractionRulesTable';
  10. const MockNavigate = jest.fn();
  11. jest.mock('sentry/utils/useNavigate', () => ({
  12. useNavigate: () => MockNavigate,
  13. }));
  14. describe('Metrics Extraction Rules Table', function () {
  15. const {router, project, organization} = initializeOrg();
  16. beforeEach(function () {
  17. MockApiClient.addMockResponse({
  18. url: `/projects/${organization.slug}/${project.slug}/metrics/extraction-rules/`,
  19. method: 'GET',
  20. body: [
  21. {
  22. spanAttribute: 'span.duration',
  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. },
  50. ],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: `/organizations/${organization.slug}/spans/fields/`,
  54. body: [],
  55. });
  56. });
  57. it('shall open the modal to edit a rule by clicking on edit', async function () {
  58. jest.spyOn(useNavigate, 'useNavigate');
  59. render(<MetricsExtractionRulesTable project={project} />);
  60. const editButton = await screen.findByLabelText('Edit metric');
  61. await userEvent.click(editButton);
  62. expect(MockNavigate).toHaveBeenCalledWith(
  63. `/settings/projects/${project.slug}/metrics/span.duration/edit/`
  64. );
  65. });
  66. it('shall open the modal to edit a rule if edit path in URL', async function () {
  67. jest.spyOn(useNavigate, 'useNavigate');
  68. render(<MetricsExtractionRulesTable project={project} />, {
  69. router: {
  70. location: {
  71. ...router.location,
  72. pathname: `/settings/projects/${project.slug}/metrics/span.duration/edit/`,
  73. },
  74. params: {
  75. spanAttribute: 'span.duration',
  76. },
  77. },
  78. });
  79. renderGlobalModal();
  80. expect(
  81. await screen.findByRole('heading', {name: /span.duration/})
  82. ).toBeInTheDocument();
  83. });
  84. });