quickTraceMeta.spec.tsx 6.1 KB

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