content.spec.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 initialOrgData = {
  17. organization,
  18. router: {
  19. location: {
  20. query: {...query},
  21. },
  22. },
  23. project: parseInt(project.id, 10),
  24. projects: [],
  25. };
  26. const initialData = initializeOrg(initialOrgData);
  27. const eventView = EventView.fromNewQueryWithLocation(
  28. {
  29. id: undefined,
  30. version: 2,
  31. name: 'test-transaction',
  32. fields: ['id', 'user.display', 'transaction.duration', 'trace', 'timestamp'],
  33. projects: [],
  34. },
  35. initialData.router.location
  36. );
  37. const spanOperationBreakdownFilter = SpanOperationBreakdownFilter.None;
  38. const transactionName = 'example-transaction';
  39. return {
  40. ...initialData,
  41. spanOperationBreakdownFilter,
  42. transactionName,
  43. location: initialData.router.location,
  44. eventView,
  45. };
  46. }
  47. const WrappedComponent = ({
  48. organization,
  49. router,
  50. ...props
  51. }: React.ComponentProps<typeof SummaryContent> & {
  52. router: InjectedRouter<Record<string, string>, any>;
  53. }) => {
  54. return (
  55. <OrganizationContext.Provider value={organization}>
  56. <RouteContext.Provider value={{router, ...router}}>
  57. <MEPSettingProvider>
  58. <SummaryContent organization={organization} {...props} />
  59. </MEPSettingProvider>
  60. </RouteContext.Provider>
  61. </OrganizationContext.Provider>
  62. );
  63. };
  64. describe('Transaction Summary Content', function () {
  65. beforeEach(function () {
  66. MockApiClient.addMockResponse({
  67. method: 'GET',
  68. url: '/prompts-activity/',
  69. body: {},
  70. });
  71. MockApiClient.addMockResponse({
  72. url: '/organizations/org-slug/sdk-updates/',
  73. body: [],
  74. });
  75. MockApiClient.addMockResponse({
  76. url: '/organizations/org-slug/eventsv2/',
  77. body: {data: [{'event.type': 'error'}], meta: {'event.type': 'string'}},
  78. });
  79. MockApiClient.addMockResponse({
  80. url: '/organizations/org-slug/users/',
  81. body: [],
  82. });
  83. MockApiClient.addMockResponse({
  84. url: '/organizations/org-slug/issues/?limit=5&query=is%3Aunresolved%20transaction%3Aexample-transaction&sort=new&statsPeriod=14d',
  85. body: [],
  86. });
  87. MockApiClient.addMockResponse({
  88. url: '/organizations/org-slug/events-facets/',
  89. body: [],
  90. });
  91. MockApiClient.addMockResponse({
  92. url: '/organizations/org-slug/releases/stats/',
  93. body: [],
  94. });
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/events-stats/',
  97. body: [],
  98. });
  99. MockApiClient.addMockResponse({
  100. url: '/organizations/org-slug/events-facets-performance/',
  101. body: {},
  102. });
  103. MockApiClient.addMockResponse({
  104. url: '/organizations/org-slug/events-has-measurements/',
  105. body: {measurements: false},
  106. });
  107. });
  108. afterEach(function () {
  109. MockApiClient.clearMockResponses();
  110. });
  111. it('performs basic rendering', function () {
  112. const project = TestStubs.Project();
  113. const {
  114. organization,
  115. location,
  116. eventView,
  117. spanOperationBreakdownFilter,
  118. transactionName,
  119. router,
  120. } = initialize(project, {});
  121. const routerContext = TestStubs.routerContext([{organization}]);
  122. render(
  123. <WrappedComponent
  124. location={location}
  125. organization={organization}
  126. eventView={eventView}
  127. projectId={project.id}
  128. transactionName={transactionName}
  129. isLoading={false}
  130. totalValues={null}
  131. spanOperationBreakdownFilter={spanOperationBreakdownFilter}
  132. error={null}
  133. onChangeFilter={() => {}}
  134. router={router}
  135. />,
  136. {context: routerContext}
  137. );
  138. expect(screen.getByTestId('page-filter-environment-selector')).toBeInTheDocument();
  139. expect(screen.getByTestId('page-filter-timerange-selector')).toBeInTheDocument();
  140. expect(screen.getByTestId('smart-search-bar')).toBeInTheDocument();
  141. expect(screen.getByTestId('transaction-summary-charts')).toBeInTheDocument();
  142. expect(screen.getByRole('heading', {name: /user misery/i})).toBeInTheDocument();
  143. expect(screen.getByRole('heading', {name: /status breakdown/i})).toBeInTheDocument();
  144. expect(screen.getByRole('heading', {name: /apdex/i})).toBeInTheDocument();
  145. expect(screen.getByTestId('apdex-summary-value')).toBeInTheDocument();
  146. expect(screen.getByRole('heading', {name: /failure rate/i})).toBeInTheDocument();
  147. expect(screen.getByTestId('failure-rate-summary-value')).toBeInTheDocument();
  148. });
  149. });