content.spec.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import {InjectedRouter} from 'react-router';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen} from 'sentry-test/reactTestingLibrary';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  7. import {OrganizationContext} from 'sentry/views/organizationContext';
  8. import {SpanOperationBreakdownFilter} from 'sentry/views/performance/transactionSummary/filter';
  9. import SummaryContent from 'sentry/views/performance/transactionSummary/transactionOverview/content';
  10. import {RouteContext} from 'sentry/views/routeContext';
  11. function initialize(project, query, additionalFeatures: string[] = []) {
  12. const features = ['transaction-event', 'performance-view', ...additionalFeatures];
  13. const organization = Organization({
  14. features,
  15. projects: [project],
  16. });
  17. const initialData = initializeOrg({
  18. organization,
  19. router: {
  20. location: {
  21. query: {...query},
  22. },
  23. },
  24. projects: [],
  25. });
  26. const eventView = EventView.fromNewQueryWithLocation(
  27. {
  28. id: undefined,
  29. version: 2,
  30. name: 'test-transaction',
  31. fields: ['id', 'user.display', 'transaction.duration', 'trace', 'timestamp'],
  32. projects: [],
  33. },
  34. initialData.router.location
  35. );
  36. const spanOperationBreakdownFilter = SpanOperationBreakdownFilter.NONE;
  37. const transactionName = 'example-transaction';
  38. return {
  39. ...initialData,
  40. spanOperationBreakdownFilter,
  41. transactionName,
  42. location: initialData.router.location,
  43. eventView,
  44. };
  45. }
  46. function WrappedComponent({
  47. organization,
  48. router,
  49. ...props
  50. }: React.ComponentProps<typeof SummaryContent> & {
  51. router: InjectedRouter<Record<string, string>, any>;
  52. }) {
  53. return (
  54. <OrganizationContext.Provider value={organization}>
  55. <RouteContext.Provider value={{router, ...router}}>
  56. <MEPSettingProvider>
  57. <SummaryContent organization={organization} {...props} />
  58. </MEPSettingProvider>
  59. </RouteContext.Provider>
  60. </OrganizationContext.Provider>
  61. );
  62. }
  63. describe('Transaction Summary Content', function () {
  64. beforeEach(function () {
  65. MockApiClient.addMockResponse({
  66. method: 'GET',
  67. url: '/prompts-activity/',
  68. body: {},
  69. });
  70. MockApiClient.addMockResponse({
  71. url: '/organizations/org-slug/sdk-updates/',
  72. body: [],
  73. });
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/events/',
  76. body: {data: [{'event.type': 'error'}], meta: {fields: {'event.type': 'string'}}},
  77. });
  78. MockApiClient.addMockResponse({
  79. url: '/organizations/org-slug/users/',
  80. body: [],
  81. });
  82. MockApiClient.addMockResponse({
  83. url: '/organizations/org-slug/issues/?limit=5&query=is%3Aunresolved%20transaction%3Aexample-transaction&sort=new&statsPeriod=14d',
  84. body: [],
  85. });
  86. MockApiClient.addMockResponse({
  87. url: '/organizations/org-slug/events-facets/',
  88. body: [],
  89. });
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/releases/stats/',
  92. body: [],
  93. });
  94. MockApiClient.addMockResponse({
  95. url: '/organizations/org-slug/events-stats/',
  96. body: [],
  97. });
  98. MockApiClient.addMockResponse({
  99. url: '/organizations/org-slug/events-facets-performance/',
  100. body: {},
  101. });
  102. MockApiClient.addMockResponse({
  103. url: '/organizations/org-slug/events-has-measurements/',
  104. body: {measurements: false},
  105. });
  106. MockApiClient.addMockResponse({
  107. url: '/organizations/org-slug/events-spans-performance/',
  108. body: [
  109. {
  110. op: 'ui.long-task',
  111. group: 'c777169faad84eb4',
  112. description: 'Main UI thread blocked',
  113. frequency: 713,
  114. count: 9040,
  115. avgOccurrences: null,
  116. sumExclusiveTime: 1743893.9822921753,
  117. p50ExclusiveTime: null,
  118. p75ExclusiveTime: 244.9998779296875,
  119. p95ExclusiveTime: null,
  120. p99ExclusiveTime: null,
  121. },
  122. ],
  123. });
  124. MockApiClient.addMockResponse({
  125. url: `/projects/org-slug/project-slug/profiling/functions/`,
  126. body: {functions: []},
  127. });
  128. });
  129. afterEach(function () {
  130. MockApiClient.clearMockResponses();
  131. });
  132. it('performs basic rendering', function () {
  133. const project = TestStubs.Project();
  134. const {
  135. organization,
  136. location,
  137. eventView,
  138. spanOperationBreakdownFilter,
  139. transactionName,
  140. router,
  141. } = initialize(project, {});
  142. const routerContext = TestStubs.routerContext([{organization}]);
  143. render(
  144. <WrappedComponent
  145. location={location}
  146. organization={organization}
  147. eventView={eventView}
  148. projectId={project.id}
  149. transactionName={transactionName}
  150. isLoading={false}
  151. totalValues={null}
  152. spanOperationBreakdownFilter={spanOperationBreakdownFilter}
  153. error={null}
  154. onChangeFilter={() => {}}
  155. router={router}
  156. />,
  157. {context: routerContext}
  158. );
  159. expect(screen.getByTestId('page-filter-environment-selector')).toBeInTheDocument();
  160. expect(screen.getByTestId('page-filter-timerange-selector')).toBeInTheDocument();
  161. expect(screen.getByTestId('smart-search-bar')).toBeInTheDocument();
  162. expect(screen.getByTestId('transaction-summary-charts')).toBeInTheDocument();
  163. expect(screen.getByRole('heading', {name: /user misery/i})).toBeInTheDocument();
  164. expect(screen.getByRole('heading', {name: /status breakdown/i})).toBeInTheDocument();
  165. expect(screen.getByRole('heading', {name: /apdex/i})).toBeInTheDocument();
  166. expect(screen.getByTestId('apdex-summary-value')).toBeInTheDocument();
  167. expect(screen.getByRole('heading', {name: /failure rate/i})).toBeInTheDocument();
  168. expect(screen.getByTestId('failure-rate-summary-value')).toBeInTheDocument();
  169. });
  170. });