errorsAndTransactions.spec.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {WidgetQueryFixture} from 'sentry-fixture/widgetQuery';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  6. import type {TableData} from 'sentry/utils/discover/discoverQuery';
  7. import type {EventViewOptions} from 'sentry/utils/discover/eventView';
  8. import EventView from 'sentry/utils/discover/eventView';
  9. import {
  10. getCustomEventsFieldRenderer,
  11. transformEventsResponseToTable,
  12. } from 'sentry/views/dashboards/datasetConfig/errorsAndTransactions';
  13. describe('transformEventsResponseToTable', function () {
  14. it('unsplats table meta field types', function () {
  15. const rawData = {
  16. data: [{'p75(measurements.inp)': null}],
  17. meta: {
  18. 'p75(measurements.inp)': 'duration',
  19. units: {
  20. 'p75(measurements.inp)': 'millisecond',
  21. },
  22. dataset: 'metricsEnhanced',
  23. fields: {
  24. 'p75(measurements.inp)': 'duration',
  25. },
  26. },
  27. title: 'A Query',
  28. } as unknown as TableData;
  29. const widgetQuery = WidgetQueryFixture();
  30. expect(transformEventsResponseToTable(rawData, widgetQuery).meta).toEqual({
  31. 'p75(measurements.inp)': 'duration',
  32. units: {
  33. 'p75(measurements.inp)': 'millisecond',
  34. },
  35. dataset: 'metricsEnhanced',
  36. fields: {
  37. 'p75(measurements.inp)': 'duration',
  38. },
  39. });
  40. });
  41. });
  42. describe('getCustomFieldRenderer', function () {
  43. const {organization, router} = initializeOrg();
  44. const baseEventViewOptions: EventViewOptions = {
  45. start: undefined,
  46. end: undefined,
  47. createdBy: UserFixture(),
  48. display: undefined,
  49. fields: [],
  50. sorts: [],
  51. query: '',
  52. project: [],
  53. environment: [],
  54. yAxis: 'count()',
  55. id: undefined,
  56. name: undefined,
  57. statsPeriod: '14d',
  58. team: [],
  59. topEvents: undefined,
  60. };
  61. it('links trace ids to performance', async function () {
  62. const customFieldRenderer = getCustomEventsFieldRenderer('trace', {});
  63. render(
  64. customFieldRenderer(
  65. {trace: 'abcd'},
  66. {
  67. organization,
  68. location: router.location,
  69. eventView: new EventView({
  70. ...baseEventViewOptions,
  71. fields: [{field: 'trace'}],
  72. }),
  73. }
  74. ) as React.ReactElement<any, any>,
  75. {router}
  76. );
  77. await userEvent.click(await screen.findByText('abcd'));
  78. expect(router.push).toHaveBeenCalledWith({
  79. pathname: '/organizations/org-slug/performance/trace/abcd/',
  80. query: {
  81. pageEnd: undefined,
  82. pageStart: undefined,
  83. statsPeriod: '14d',
  84. },
  85. });
  86. });
  87. it('links event ids to event details', async function () {
  88. const project = ProjectFixture();
  89. const customFieldRenderer = getCustomEventsFieldRenderer('id', {});
  90. render(
  91. customFieldRenderer(
  92. {id: 'defg', 'project.name': project.slug},
  93. {
  94. organization,
  95. location: router.location,
  96. eventView: new EventView({
  97. ...baseEventViewOptions,
  98. fields: [{field: 'id'}],
  99. project: [parseInt(project.id, 10)],
  100. }),
  101. }
  102. ) as React.ReactElement<any, any>,
  103. {router}
  104. );
  105. await userEvent.click(await screen.findByText('defg'));
  106. expect(router.push).toHaveBeenCalledWith({
  107. pathname: `/organizations/org-slug/discover/${project.slug}:defg/`,
  108. query: {
  109. display: undefined,
  110. environment: undefined,
  111. field: 'id',
  112. id: undefined,
  113. interval: undefined,
  114. name: undefined,
  115. project: project.id,
  116. query: '',
  117. sort: undefined,
  118. topEvents: undefined,
  119. widths: undefined,
  120. yAxis: 'count()',
  121. pageEnd: undefined,
  122. pageStart: undefined,
  123. statsPeriod: '14d',
  124. },
  125. });
  126. });
  127. it('links << unparameterized >> title/transaction columns to event details', async function () {
  128. const project = ProjectFixture();
  129. const customFieldRenderer = getCustomEventsFieldRenderer('title', {});
  130. render(
  131. customFieldRenderer(
  132. {title: '<< unparameterized >>'},
  133. {
  134. organization,
  135. location: router.location,
  136. eventView: new EventView({
  137. ...baseEventViewOptions,
  138. fields: [{field: 'id'}],
  139. project: [parseInt(project.id, 10)],
  140. }),
  141. }
  142. ) as React.ReactElement<any, any>,
  143. {router}
  144. );
  145. await userEvent.click(await screen.findByText('<< unparameterized >>'));
  146. expect(router.push).toHaveBeenCalledWith(
  147. expect.objectContaining({
  148. pathname: `/organizations/org-slug/discover/results/`,
  149. query: expect.objectContaining({
  150. query: 'event.type:transaction transaction.source:"url"',
  151. }),
  152. })
  153. );
  154. });
  155. });