quickTraceMeta.spec.jsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {OrganizationContext} from 'sentry/views/organizationContext';
  3. import QuickTraceMeta from 'sentry/views/performance/transactionDetails/quickTraceMeta';
  4. const WrappedQuickTraceMeta = ({organization, ...rest}) => {
  5. return (
  6. <OrganizationContext.Provider value={organization}>
  7. <QuickTraceMeta {...rest} />
  8. </OrganizationContext.Provider>
  9. );
  10. };
  11. describe('QuickTraceMeta', function () {
  12. const routerContext = TestStubs.routerContext();
  13. const location = routerContext.context.location;
  14. const organization = TestStubs.Organization({features: ['performance-view']});
  15. const project = TestStubs.Project({platform: 'javascript'});
  16. const event = TestStubs.Event({contexts: {trace: {trace_id: 'a'.repeat(32)}}});
  17. const emptyQuickTrace = {
  18. isLoading: false,
  19. error: null,
  20. trace: [],
  21. type: 'empty',
  22. currentEvent: null,
  23. };
  24. const emptyTraceMeta = {
  25. projects: 0,
  26. transactions: 0,
  27. errors: 0,
  28. };
  29. it('renders basic UI', async function () {
  30. const wrapper = mountWithTheme(
  31. <WrappedQuickTraceMeta
  32. event={event}
  33. project={project}
  34. organization={organization}
  35. location={location}
  36. quickTrace={emptyQuickTrace}
  37. traceMeta={emptyTraceMeta}
  38. anchor="left"
  39. errorDest="issue"
  40. transactionDest="performance"
  41. />,
  42. routerContext
  43. );
  44. await tick();
  45. wrapper.update();
  46. expect(wrapper.find('MetaData').exists()).toBe(true);
  47. expect(wrapper.find('div[data-test-id="quick-trace-body"] QuickTrace').exists()).toBe(
  48. true
  49. );
  50. expect(wrapper.find('div[data-test-id="quick-trace-footer"]').text()).toEqual(
  51. `View Full Trace: ${'a'.repeat(8)} (0 events)`
  52. );
  53. });
  54. it('renders placeholder while loading', async function () {
  55. const wrapper = mountWithTheme(
  56. <WrappedQuickTraceMeta
  57. event={event}
  58. project={project}
  59. organization={organization}
  60. location={location}
  61. quickTrace={{
  62. ...emptyQuickTrace,
  63. isLoading: true,
  64. }}
  65. traceMeta={emptyTraceMeta}
  66. anchor="left"
  67. errorDest="issue"
  68. transactionDest="performance"
  69. />,
  70. routerContext
  71. );
  72. await tick();
  73. wrapper.update();
  74. expect(wrapper.find('MetaData').exists()).toBe(true);
  75. expect(
  76. wrapper.find('div[data-test-id="quick-trace-body"] Placeholder').exists()
  77. ).toBe(true);
  78. expect(wrapper.find('div[data-test-id="quick-trace-footer"]').text()).toEqual(
  79. `View Full Trace: ${'a'.repeat(8)} (0 events)`
  80. );
  81. });
  82. it('renders errors', async function () {
  83. const wrapper = mountWithTheme(
  84. <WrappedQuickTraceMeta
  85. event={event}
  86. project={project}
  87. organization={organization}
  88. location={location}
  89. quickTrace={{
  90. ...emptyQuickTrace,
  91. error: 'something bad',
  92. }}
  93. traceMeta={emptyTraceMeta}
  94. anchor="left"
  95. errorDest="issue"
  96. transactionDest="performance"
  97. />,
  98. routerContext
  99. );
  100. await tick();
  101. wrapper.update();
  102. expect(wrapper.find('MetaData').exists()).toBe(true);
  103. expect(wrapper.find('div[data-test-id="quick-trace-body"]').text()).toEqual('\u2014');
  104. expect(wrapper.find('div[data-test-id="quick-trace-footer"]').text()).toEqual(
  105. `View Full Trace: ${'a'.repeat(8)} (0 events)`
  106. );
  107. });
  108. it('renders missing trace when trace id is not present', async function () {
  109. const newEvent = TestStubs.Event();
  110. const wrapper = mountWithTheme(
  111. <WrappedQuickTraceMeta
  112. event={newEvent}
  113. project={project}
  114. organization={organization}
  115. location={location}
  116. quickTrace={emptyQuickTrace}
  117. traceMeta={emptyTraceMeta}
  118. anchor="left"
  119. errorDest="issue"
  120. transactionDest="performance"
  121. />,
  122. routerContext
  123. );
  124. await tick();
  125. wrapper.update();
  126. expect(wrapper.find('MetaData').exists()).toBe(true);
  127. expect(wrapper.find('div[data-test-id="quick-trace-body"]').text()).toEqual(
  128. 'Missing Trace'
  129. );
  130. expect(wrapper.find('div[data-test-id="quick-trace-footer"]').text()).toEqual(
  131. 'Read the docs'
  132. );
  133. });
  134. it('renders missing trace with hover card when feature disabled', async function () {
  135. const newEvent = TestStubs.Event();
  136. const newOrg = TestStubs.Organization();
  137. const wrapper = mountWithTheme(
  138. <WrappedQuickTraceMeta
  139. event={newEvent}
  140. project={project}
  141. organization={newOrg}
  142. location={location}
  143. quickTrace={emptyQuickTrace}
  144. traceMeta={emptyTraceMeta}
  145. anchor="left"
  146. errorDest="issue"
  147. transactionDest="performance"
  148. />,
  149. routerContext
  150. );
  151. await tick();
  152. wrapper.update();
  153. expect(wrapper.find('MetaData').exists()).toBe(true);
  154. expect(wrapper.find('div[data-test-id="quick-trace-body"]').text()).toEqual(
  155. 'Missing Trace'
  156. );
  157. expect(wrapper.find('div[data-test-id="quick-trace-footer"]').text()).toEqual(
  158. 'Read the docs'
  159. );
  160. expect(
  161. wrapper.find('div[data-test-id="quick-trace-footer"] Hovercard').exists()
  162. ).toEqual(true);
  163. });
  164. it('does not render when platform does not support tracing', async function () {
  165. const newProject = TestStubs.Project();
  166. const newEvent = TestStubs.Event();
  167. const wrapper = mountWithTheme(
  168. <WrappedQuickTraceMeta
  169. event={newEvent}
  170. project={newProject}
  171. organization={organization}
  172. location={location}
  173. quickTrace={emptyQuickTrace}
  174. traceMeta={emptyTraceMeta}
  175. anchor="left"
  176. errorDest="issue"
  177. transactionDest="performance"
  178. />,
  179. routerContext
  180. );
  181. await tick();
  182. wrapper.update();
  183. expect(wrapper.isEmptyRender()).toBe(true);
  184. });
  185. });