quickTraceMeta.spec.tsx 6.0 KB

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