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. };
  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. timestamp: 123213123,
  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. );
  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 = 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. });