quickTraceMeta.spec.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {LocationFixture} from 'sentry-fixture/locationFixture';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  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 location = LocationFixture();
  13. const project = ProjectFixture({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. transactiontoSpanChildrenCount: {},
  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. transactiontoSpanChildrenCount: {},
  116. }}
  117. anchor="left"
  118. errorDest="issue"
  119. transactionDest="performance"
  120. />
  121. );
  122. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  123. expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
  124. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
  125. `View Full Trace: ${'a'.repeat(8)} (1 event)`
  126. );
  127. });
  128. it('renders missing trace when trace id is not present', function () {
  129. const newEvent = EventFixture();
  130. render(
  131. <QuickTraceMeta
  132. event={newEvent}
  133. project={project}
  134. location={location}
  135. quickTrace={emptyQuickTrace}
  136. traceMeta={emptyTraceMeta}
  137. anchor="left"
  138. errorDest="issue"
  139. transactionDest="performance"
  140. />
  141. );
  142. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  143. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  144. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent('Read the docs');
  145. });
  146. it('renders missing trace with hover card when feature disabled', async function () {
  147. const newEvent = EventFixture();
  148. render(
  149. <QuickTraceMeta
  150. event={newEvent}
  151. project={project}
  152. location={location}
  153. quickTrace={emptyQuickTrace}
  154. traceMeta={emptyTraceMeta}
  155. anchor="left"
  156. errorDest="issue"
  157. transactionDest="performance"
  158. />
  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(await screen.findByText('Requires tracing.')).toBeInTheDocument();
  170. });
  171. it('does not render when platform does not support tracing', function () {
  172. const newProject = ProjectFixture();
  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. });