quickTraceMeta.spec.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 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 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. timestamp: 123213123,
  107. },
  108. ],
  109. }}
  110. traceMeta={{
  111. projects: 0,
  112. transactions: 1,
  113. errors: 0,
  114. performance_issues: 0,
  115. }}
  116. anchor="left"
  117. errorDest="issue"
  118. transactionDest="performance"
  119. />
  120. );
  121. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  122. expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
  123. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
  124. `View Full Trace: ${'a'.repeat(8)} (1 event)`
  125. );
  126. });
  127. it('renders missing trace when trace id is not present', function () {
  128. const newEvent = EventFixture();
  129. render(
  130. <QuickTraceMeta
  131. event={newEvent}
  132. project={project}
  133. location={location}
  134. quickTrace={emptyQuickTrace}
  135. traceMeta={emptyTraceMeta}
  136. anchor="left"
  137. errorDest="issue"
  138. transactionDest="performance"
  139. />
  140. );
  141. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  142. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  143. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent('Read the docs');
  144. });
  145. it('renders missing trace with hover card when feature disabled', async function () {
  146. const newEvent = EventFixture();
  147. render(
  148. <QuickTraceMeta
  149. event={newEvent}
  150. project={project}
  151. location={location}
  152. quickTrace={emptyQuickTrace}
  153. traceMeta={emptyTraceMeta}
  154. anchor="left"
  155. errorDest="issue"
  156. transactionDest="performance"
  157. />,
  158. {context: routerContext}
  159. );
  160. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  161. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  162. const qtFooter = screen.getByTestId('quick-trace-footer');
  163. expect(qtFooter).toHaveTextContent('Read the docs');
  164. const child = qtFooter.firstChild;
  165. if (!child) {
  166. throw new Error('child is null');
  167. }
  168. await userEvent.hover(child as HTMLElement);
  169. expect(
  170. await screen.findByText('Requires performance monitoring.')
  171. ).toBeInTheDocument();
  172. });
  173. it('does not render when platform does not support tracing', function () {
  174. const newProject = ProjectFixture();
  175. const newEvent = EventFixture();
  176. const result = render(
  177. <QuickTraceMeta
  178. event={newEvent}
  179. project={newProject}
  180. location={location}
  181. quickTrace={emptyQuickTrace}
  182. traceMeta={emptyTraceMeta}
  183. anchor="left"
  184. errorDest="issue"
  185. transactionDest="performance"
  186. />
  187. );
  188. expect(result.container).toBeEmptyDOMElement();
  189. });
  190. });