errorsAndTransactions.spec.tsx 3.7 KB

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