content.spec.tsx 5.7 KB

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