quickTraceMeta.spec.jsx 5.1 KB

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