content.spec.tsx 5.9 KB

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