content.spec.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  5. import {OrganizationContext} from 'sentry/views/organizationContext';
  6. import {SpanOperationBreakdownFilter} from 'sentry/views/performance/transactionSummary/filter';
  7. import SummaryContent from 'sentry/views/performance/transactionSummary/transactionOverview/content';
  8. function initialize(project, query, additionalFeatures: string[] = []) {
  9. const features = ['transaction-event', 'performance-view', ...additionalFeatures];
  10. const organization = TestStubs.Organization({
  11. features,
  12. projects: [project],
  13. });
  14. const initialOrgData = {
  15. organization,
  16. router: {
  17. location: {
  18. query: {...query},
  19. },
  20. },
  21. project: parseInt(project.id, 10),
  22. projects: [],
  23. };
  24. const initialData = initializeOrg(initialOrgData);
  25. const eventView = EventView.fromNewQueryWithLocation(
  26. {
  27. id: undefined,
  28. version: 2,
  29. name: 'test-transaction',
  30. fields: ['id', 'user.display', 'transaction.duration', 'trace', 'timestamp'],
  31. projects: [],
  32. },
  33. initialData.router.location
  34. );
  35. const spanOperationBreakdownFilter = SpanOperationBreakdownFilter.None;
  36. const transactionName = 'example-transaction';
  37. return {
  38. ...initialData,
  39. spanOperationBreakdownFilter,
  40. transactionName,
  41. location: initialData.router.location,
  42. eventView,
  43. };
  44. }
  45. const WrappedComponent = ({
  46. organization,
  47. ...props
  48. }: React.ComponentProps<typeof SummaryContent>) => {
  49. return (
  50. <OrganizationContext.Provider value={organization}>
  51. <MEPSettingProvider>
  52. <SummaryContent organization={organization} {...props} />
  53. </MEPSettingProvider>
  54. </OrganizationContext.Provider>
  55. );
  56. };
  57. describe('Transaction Summary Content', function () {
  58. beforeEach(function () {
  59. MockApiClient.addMockResponse({
  60. method: 'GET',
  61. url: '/prompts-activity/',
  62. body: {},
  63. });
  64. MockApiClient.addMockResponse({
  65. url: '/organizations/org-slug/sdk-updates/',
  66. body: [],
  67. });
  68. MockApiClient.addMockResponse({
  69. url: '/organizations/org-slug/eventsv2/',
  70. body: {data: [{'event.type': 'error'}], meta: {'event.type': 'string'}},
  71. });
  72. MockApiClient.addMockResponse({
  73. url: '/organizations/org-slug/users/',
  74. body: [],
  75. });
  76. MockApiClient.addMockResponse({
  77. url: '/organizations/org-slug/issues/?limit=5&query=is%3Aunresolved%20transaction%3Aexample-transaction&sort=new&statsPeriod=14d',
  78. body: [],
  79. });
  80. MockApiClient.addMockResponse({
  81. url: '/organizations/org-slug/events-facets/',
  82. body: [],
  83. });
  84. MockApiClient.addMockResponse({
  85. url: '/organizations/org-slug/releases/stats/',
  86. body: [],
  87. });
  88. MockApiClient.addMockResponse({
  89. url: '/organizations/org-slug/events-stats/',
  90. body: [],
  91. });
  92. MockApiClient.addMockResponse({
  93. url: '/organizations/org-slug/events-facets-performance/',
  94. body: {},
  95. });
  96. MockApiClient.addMockResponse({
  97. url: '/organizations/org-slug/events-has-measurements/',
  98. body: {measurements: false},
  99. });
  100. });
  101. afterEach(function () {
  102. MockApiClient.clearMockResponses();
  103. });
  104. it('Basic Rendering', async function () {
  105. const project = TestStubs.Project();
  106. const {
  107. organization,
  108. location,
  109. eventView,
  110. spanOperationBreakdownFilter,
  111. transactionName,
  112. } = initialize(project, {});
  113. const routerContext = TestStubs.routerContext([{organization}]);
  114. const wrapper = mountWithTheme(
  115. <WrappedComponent
  116. location={location}
  117. organization={organization}
  118. eventView={eventView}
  119. projectId={project.id}
  120. transactionName={transactionName}
  121. isLoading={false}
  122. totalValues={null}
  123. spanOperationBreakdownFilter={spanOperationBreakdownFilter}
  124. error={null}
  125. onChangeFilter={() => {}}
  126. />,
  127. routerContext
  128. );
  129. await tick();
  130. wrapper.update();
  131. expect(wrapper.find('Filter')).toHaveLength(1);
  132. expect(wrapper.find('SearchBar')).toHaveLength(1);
  133. expect(wrapper.find('TransactionSummaryCharts')).toHaveLength(1);
  134. expect(wrapper.find('TransactionsList')).toHaveLength(1);
  135. expect(wrapper.find('UserStats')).toHaveLength(1);
  136. expect(wrapper.find('StatusBreakdown')).toHaveLength(1);
  137. expect(wrapper.find('SidebarCharts')).toHaveLength(1);
  138. expect(wrapper.find('DiscoverQuery')).toHaveLength(2);
  139. const transactionListProps = wrapper.find('TransactionsList').first().props();
  140. expect(transactionListProps.generateDiscoverEventView).toBeUndefined();
  141. expect(transactionListProps.handleOpenInDiscoverClick).toBeUndefined();
  142. expect(transactionListProps.generatePerformanceTransactionEventsView).toBeDefined();
  143. expect(transactionListProps.handleOpenAllEventsClick).toBeDefined();
  144. });
  145. it('Renders TransactionSummaryCharts withoutZerofill', async function () {
  146. const project = TestStubs.Project();
  147. const {
  148. organization,
  149. location,
  150. eventView,
  151. spanOperationBreakdownFilter,
  152. transactionName,
  153. } = initialize(project, {}, ['performance-chart-interpolation']);
  154. const routerContext = TestStubs.routerContext([{organization}]);
  155. const wrapper = mountWithTheme(
  156. <WrappedComponent
  157. location={location}
  158. organization={organization}
  159. eventView={eventView}
  160. projectId={project.id}
  161. transactionName={transactionName}
  162. isLoading={false}
  163. totalValues={null}
  164. spanOperationBreakdownFilter={spanOperationBreakdownFilter}
  165. error={null}
  166. onChangeFilter={() => {}}
  167. />,
  168. routerContext
  169. );
  170. await tick();
  171. wrapper.update();
  172. expect(wrapper.find('TransactionSummaryCharts')).toHaveLength(1);
  173. const transactionSummaryChartsProps = wrapper
  174. .find('TransactionSummaryCharts')
  175. .first()
  176. .props();
  177. expect(transactionSummaryChartsProps.withoutZerofill).toEqual(true);
  178. });
  179. });