quickTraceMeta.spec.tsx 6.1 KB

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