quickTraceMeta.spec.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {LocationFixture} from 'sentry-fixture/locationFixture';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  5. import {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
  6. import type {
  7. QuickTraceQueryChildrenProps,
  8. TraceMeta,
  9. } from 'sentry/utils/performance/quickTrace/types';
  10. import QuickTraceMeta from 'sentry/views/performance/transactionDetails/quickTraceMeta';
  11. describe('QuickTraceMeta', function () {
  12. const location = LocationFixture();
  13. const project = ProjectFixture({platform: 'javascript'});
  14. const event = EventFixture({contexts: {trace: {trace_id: 'a'.repeat(32)}}});
  15. const emptyQuickTrace: QuickTraceQueryChildrenProps = {
  16. isLoading: false,
  17. error: null,
  18. trace: [],
  19. type: 'empty',
  20. currentEvent: null,
  21. };
  22. const emptyTraceMeta: TraceMeta = {
  23. projects: 0,
  24. transactions: 0,
  25. errors: 0,
  26. performance_issues: 0,
  27. transaction_child_count_map: {},
  28. span_count: 0,
  29. span_count_map: {},
  30. };
  31. it('renders basic UI', function () {
  32. render(
  33. <QuickTraceMeta
  34. event={event}
  35. project={project}
  36. location={location}
  37. quickTrace={emptyQuickTrace}
  38. traceMeta={emptyTraceMeta}
  39. anchor="left"
  40. errorDest="issue"
  41. transactionDest="performance"
  42. />
  43. );
  44. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  45. expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
  46. });
  47. it('renders placeholder while loading', function () {
  48. render(
  49. <QuickTraceMeta
  50. event={event}
  51. project={project}
  52. location={location}
  53. quickTrace={{
  54. ...emptyQuickTrace,
  55. isLoading: true,
  56. }}
  57. traceMeta={emptyTraceMeta}
  58. anchor="left"
  59. errorDest="issue"
  60. transactionDest="performance"
  61. />
  62. );
  63. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  64. const qtBody = screen.getByTestId('quick-trace-body');
  65. expect(within(qtBody).getByTestId('loading-placeholder')).toBeInTheDocument();
  66. });
  67. it('renders errors', function () {
  68. render(
  69. <QuickTraceMeta
  70. event={event}
  71. project={project}
  72. location={location}
  73. quickTrace={{
  74. ...emptyQuickTrace,
  75. error: new QueryError('something bad'),
  76. }}
  77. traceMeta={emptyTraceMeta}
  78. anchor="left"
  79. errorDest="issue"
  80. transactionDest="performance"
  81. />
  82. );
  83. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  84. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('\u2014');
  85. });
  86. it('renders footer', function () {
  87. render(
  88. <QuickTraceMeta
  89. event={event}
  90. project={project}
  91. location={location}
  92. quickTrace={{
  93. ...emptyQuickTrace,
  94. type: 'full',
  95. trace: [
  96. {
  97. event_id: '6c2fa0db524a41b784db2de220f9754c',
  98. span_id: '9f4d8db340e5b9c2',
  99. transaction: '/api/0/internal/health/',
  100. 'transaction.duration': 15,
  101. project_id: 1,
  102. project_slug: 'sentry',
  103. parent_span_id: '87a45c44efdf60d5',
  104. parent_event_id: null,
  105. generation: 0,
  106. errors: [],
  107. performance_issues: [],
  108. timestamp: 123213123,
  109. },
  110. ],
  111. }}
  112. traceMeta={{
  113. projects: 0,
  114. transactions: 1,
  115. errors: 0,
  116. performance_issues: 0,
  117. transaction_child_count_map: {},
  118. span_count: 0,
  119. span_count_map: {},
  120. }}
  121. anchor="left"
  122. errorDest="issue"
  123. transactionDest="performance"
  124. />
  125. );
  126. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  127. expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
  128. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
  129. `View Full Trace: ${'a'.repeat(8)} (1 event)`
  130. );
  131. });
  132. it('renders missing trace when trace id is not present', function () {
  133. const newEvent = EventFixture();
  134. render(
  135. <QuickTraceMeta
  136. event={newEvent}
  137. project={project}
  138. location={location}
  139. quickTrace={emptyQuickTrace}
  140. traceMeta={emptyTraceMeta}
  141. anchor="left"
  142. errorDest="issue"
  143. transactionDest="performance"
  144. />
  145. );
  146. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  147. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  148. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent('Read the docs');
  149. });
  150. it('renders missing trace with hover card when feature disabled', async function () {
  151. const newEvent = EventFixture();
  152. render(
  153. <QuickTraceMeta
  154. event={newEvent}
  155. project={project}
  156. location={location}
  157. quickTrace={emptyQuickTrace}
  158. traceMeta={emptyTraceMeta}
  159. anchor="left"
  160. errorDest="issue"
  161. transactionDest="performance"
  162. />
  163. );
  164. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  165. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  166. const qtFooter = screen.getByTestId('quick-trace-footer');
  167. expect(qtFooter).toHaveTextContent('Read the docs');
  168. const child = qtFooter.firstChild;
  169. if (!child) {
  170. throw new Error('child is null');
  171. }
  172. await userEvent.hover(child as HTMLElement);
  173. expect(await screen.findByText('Requires tracing.')).toBeInTheDocument();
  174. });
  175. it('does not render when platform does not support tracing', function () {
  176. const newProject = ProjectFixture();
  177. const newEvent = EventFixture();
  178. const result = render(
  179. <QuickTraceMeta
  180. event={newEvent}
  181. project={newProject}
  182. location={location}
  183. quickTrace={emptyQuickTrace}
  184. traceMeta={emptyTraceMeta}
  185. anchor="left"
  186. errorDest="issue"
  187. transactionDest="performance"
  188. />
  189. );
  190. expect(result.container).toBeEmptyDOMElement();
  191. });
  192. });