content.spec.tsx 6.0 KB

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