quickTraceMeta.spec.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  2. import {QueryError} from 'sentry/utils/discover/genericDiscoverQuery';
  3. import {
  4. QuickTraceQueryChildrenProps,
  5. TraceMeta,
  6. } from 'sentry/utils/performance/quickTrace/types';
  7. import QuickTraceMeta from 'sentry/views/performance/transactionDetails/quickTraceMeta';
  8. describe('QuickTraceMeta', function () {
  9. const routerContext = TestStubs.routerContext();
  10. const location = routerContext.context.location;
  11. const project = TestStubs.Project({platform: 'javascript'});
  12. const event = TestStubs.Event({contexts: {trace: {trace_id: 'a'.repeat(32)}}});
  13. const emptyQuickTrace: QuickTraceQueryChildrenProps = {
  14. isLoading: false,
  15. error: null,
  16. trace: [],
  17. type: 'empty',
  18. currentEvent: null,
  19. };
  20. const emptyTraceMeta: TraceMeta = {
  21. projects: 0,
  22. transactions: 0,
  23. errors: 0,
  24. performance_issues: 0,
  25. };
  26. it('renders basic UI', function () {
  27. render(
  28. <QuickTraceMeta
  29. event={event}
  30. project={project}
  31. location={location}
  32. quickTrace={emptyQuickTrace}
  33. traceMeta={emptyTraceMeta}
  34. anchor="left"
  35. errorDest="issue"
  36. transactionDest="performance"
  37. />
  38. );
  39. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  40. expect(screen.getByTestId('quick-trace-body')).toBeInTheDocument();
  41. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
  42. `View Full Trace: ${'a'.repeat(8)} (0 events)`
  43. );
  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. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
  65. `View Full Trace: ${'a'.repeat(8)} (0 events)`
  66. );
  67. });
  68. it('renders errors', function () {
  69. render(
  70. <QuickTraceMeta
  71. event={event}
  72. project={project}
  73. location={location}
  74. quickTrace={{
  75. ...emptyQuickTrace,
  76. error: new QueryError('something bad'),
  77. }}
  78. traceMeta={emptyTraceMeta}
  79. anchor="left"
  80. errorDest="issue"
  81. transactionDest="performance"
  82. />
  83. );
  84. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  85. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('\u2014');
  86. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent(
  87. `View Full Trace: ${'a'.repeat(8)} (0 events)`
  88. );
  89. });
  90. it('renders missing trace when trace id is not present', function () {
  91. const newEvent = TestStubs.Event();
  92. render(
  93. <QuickTraceMeta
  94. event={newEvent}
  95. project={project}
  96. location={location}
  97. quickTrace={emptyQuickTrace}
  98. traceMeta={emptyTraceMeta}
  99. anchor="left"
  100. errorDest="issue"
  101. transactionDest="performance"
  102. />
  103. );
  104. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  105. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  106. expect(screen.getByTestId('quick-trace-footer')).toHaveTextContent('Read the docs');
  107. });
  108. it('renders missing trace with hover card when feature disabled', async function () {
  109. const newEvent = TestStubs.Event();
  110. render(
  111. <QuickTraceMeta
  112. event={newEvent}
  113. project={project}
  114. location={location}
  115. quickTrace={emptyQuickTrace}
  116. traceMeta={emptyTraceMeta}
  117. anchor="left"
  118. errorDest="issue"
  119. transactionDest="performance"
  120. />,
  121. {context: routerContext}
  122. );
  123. expect(screen.getByRole('heading', {name: 'Trace Navigator'})).toBeInTheDocument();
  124. expect(screen.getByTestId('quick-trace-body')).toHaveTextContent('Missing Trace');
  125. const qtFooter = screen.getByTestId('quick-trace-footer');
  126. expect(qtFooter).toHaveTextContent('Read the docs');
  127. const child = qtFooter.firstChild;
  128. if (!child) {
  129. throw new Error('child is null');
  130. }
  131. await userEvent.hover(child as HTMLElement);
  132. expect(
  133. await screen.findByText('Requires performance monitoring.')
  134. ).toBeInTheDocument();
  135. });
  136. it('does not render when platform does not support tracing', function () {
  137. const newProject = TestStubs.Project();
  138. const newEvent = TestStubs.Event();
  139. const result = render(
  140. <QuickTraceMeta
  141. event={newEvent}
  142. project={newProject}
  143. location={location}
  144. quickTrace={emptyQuickTrace}
  145. traceMeta={emptyTraceMeta}
  146. anchor="left"
  147. errorDest="issue"
  148. transactionDest="performance"
  149. />
  150. );
  151. expect(result.container).toBeEmptyDOMElement();
  152. });
  153. });