quickTraceMeta.spec.tsx 6.0 KB

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