errorsAndTransactions.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  5. import type {EventViewOptions} from 'sentry/utils/discover/eventView';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {getCustomEventsFieldRenderer} from 'sentry/views/dashboards/datasetConfig/errorsAndTransactions';
  8. describe('getCustomFieldRenderer', function () {
  9. const {organization, router, routerContext} = initializeOrg();
  10. const baseEventViewOptions: EventViewOptions = {
  11. start: undefined,
  12. end: undefined,
  13. createdBy: UserFixture(),
  14. display: undefined,
  15. fields: [],
  16. sorts: [],
  17. query: '',
  18. project: [],
  19. environment: [],
  20. yAxis: 'count()',
  21. id: undefined,
  22. name: undefined,
  23. statsPeriod: '14d',
  24. team: [],
  25. topEvents: undefined,
  26. };
  27. it('links trace ids to performance', async function () {
  28. const customFieldRenderer = getCustomEventsFieldRenderer('trace', {});
  29. render(
  30. customFieldRenderer(
  31. {trace: 'abcd'},
  32. {
  33. organization,
  34. location: router.location,
  35. eventView: new EventView({
  36. ...baseEventViewOptions,
  37. fields: [{field: 'trace'}],
  38. }),
  39. }
  40. ) as React.ReactElement<any, any>,
  41. {context: routerContext}
  42. );
  43. await userEvent.click(await screen.findByText('abcd'));
  44. expect(router.push).toHaveBeenCalledWith({
  45. pathname: '/organizations/org-slug/performance/trace/abcd/',
  46. query: {
  47. pageEnd: undefined,
  48. pageStart: undefined,
  49. statsPeriod: '14d',
  50. },
  51. });
  52. });
  53. it('links event ids to event details', async function () {
  54. const project = ProjectFixture();
  55. const customFieldRenderer = getCustomEventsFieldRenderer('id', {});
  56. render(
  57. customFieldRenderer(
  58. {id: 'defg', 'project.name': project.slug},
  59. {
  60. organization,
  61. location: router.location,
  62. eventView: new EventView({
  63. ...baseEventViewOptions,
  64. fields: [{field: 'id'}],
  65. project: [parseInt(project.id, 10)],
  66. }),
  67. }
  68. ) as React.ReactElement<any, any>,
  69. {context: routerContext}
  70. );
  71. await userEvent.click(await screen.findByText('defg'));
  72. expect(router.push).toHaveBeenCalledWith({
  73. pathname: `/organizations/org-slug/discover/${project.slug}:defg/`,
  74. query: {
  75. display: undefined,
  76. environment: [],
  77. field: ['id'],
  78. id: undefined,
  79. interval: undefined,
  80. name: undefined,
  81. project: [parseInt(project.id, 10)],
  82. query: '',
  83. sort: [],
  84. topEvents: undefined,
  85. widths: [],
  86. yAxis: 'count()',
  87. pageEnd: undefined,
  88. pageStart: undefined,
  89. statsPeriod: '14d',
  90. },
  91. });
  92. });
  93. it('links << unparameterized >> title/transaction columns to event details', async function () {
  94. const project = ProjectFixture();
  95. const customFieldRenderer = getCustomEventsFieldRenderer('title', {});
  96. render(
  97. customFieldRenderer(
  98. {title: '<< unparameterized >>'},
  99. {
  100. organization,
  101. location: router.location,
  102. eventView: new EventView({
  103. ...baseEventViewOptions,
  104. fields: [{field: 'id'}],
  105. project: [parseInt(project.id, 10)],
  106. }),
  107. }
  108. ) as React.ReactElement<any, any>,
  109. {context: routerContext}
  110. );
  111. await userEvent.click(await screen.findByText('<< unparameterized >>'));
  112. expect(router.push).toHaveBeenCalledWith(
  113. expect.objectContaining({
  114. pathname: `/organizations/org-slug/discover/results/`,
  115. query: expect.objectContaining({
  116. query: 'event.type:transaction transaction.source:"url"',
  117. }),
  118. })
  119. );
  120. });
  121. });