content.spec.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {textWithMarkupMatcher} from 'sentry-test/utils';
  4. import {t} from 'sentry/locale';
  5. import ProjectsStore from 'sentry/stores/projectsStore';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {
  8. SPAN_OP_BREAKDOWN_FIELDS,
  9. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  10. } from 'sentry/utils/discover/fields';
  11. import {WebVital} from 'sentry/utils/fields';
  12. import {OrganizationContext} from 'sentry/views/organizationContext';
  13. import {SpanOperationBreakdownFilter} from 'sentry/views/performance/transactionSummary/filter';
  14. import EventsPageContent from 'sentry/views/performance/transactionSummary/transactionEvents/content';
  15. import {EventsDisplayFilterName} from 'sentry/views/performance/transactionSummary/transactionEvents/utils';
  16. import {RouteContext} from 'sentry/views/routeContext';
  17. function initializeData() {
  18. const organization = TestStubs.Organization({
  19. features: ['discover-basic', 'performance-view'],
  20. projects: [TestStubs.Project()],
  21. apdexThreshold: 400,
  22. });
  23. const initialData = initializeOrg({
  24. organization,
  25. router: {
  26. location: {
  27. query: {
  28. transaction: '/performance',
  29. project: 1,
  30. transactionCursor: '1:0:0',
  31. },
  32. },
  33. },
  34. project: 1,
  35. projects: [],
  36. });
  37. act(() => void ProjectsStore.loadInitialData(initialData.organization.projects));
  38. return initialData;
  39. }
  40. describe('Performance Transaction Events Content', function () {
  41. let fields;
  42. let data;
  43. let transactionName;
  44. let eventView;
  45. let totalEventCount;
  46. let initialData;
  47. const query =
  48. 'transaction.duration:<15m event.type:transaction transaction:/api/0/organizations/{organization_slug}/events/';
  49. beforeEach(function () {
  50. transactionName = 'transactionName';
  51. totalEventCount = '200';
  52. fields = [
  53. 'id',
  54. 'user.display',
  55. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  56. 'transaction.duration',
  57. 'trace',
  58. 'timestamp',
  59. 'spans.total.time',
  60. ...SPAN_OP_BREAKDOWN_FIELDS,
  61. ];
  62. MockApiClient.addMockResponse({
  63. url: '/organizations/org-slug/projects/',
  64. body: [],
  65. });
  66. MockApiClient.addMockResponse({
  67. url: '/prompts-activity/',
  68. body: {},
  69. });
  70. MockApiClient.addMockResponse({
  71. url: '/organizations/org-slug/sdk-updates/',
  72. body: [],
  73. });
  74. data = [
  75. {
  76. id: 'deadbeef',
  77. 'user.display': 'uhoh@example.com',
  78. 'transaction.duration': 400,
  79. 'project.id': 1,
  80. timestamp: '2020-05-21T15:31:18+00:00',
  81. trace: '1234',
  82. 'span_ops_breakdown.relative': '',
  83. 'spans.browser': 100,
  84. 'spans.db': 30,
  85. 'spans.http': 170,
  86. 'spans.resource': 100,
  87. 'spans.total.time': 400,
  88. },
  89. {
  90. id: 'moredeadbeef',
  91. 'user.display': 'moreuhoh@example.com',
  92. 'transaction.duration': 600,
  93. 'project.id': 1,
  94. timestamp: '2020-05-22T15:31:18+00:00',
  95. trace: '4321',
  96. 'span_ops_breakdown.relative': '',
  97. 'spans.browser': 100,
  98. 'spans.db': 300,
  99. 'spans.http': 100,
  100. 'spans.resource': 100,
  101. 'spans.total.time': 600,
  102. },
  103. ];
  104. // Transaction list response
  105. MockApiClient.addMockResponse({
  106. url: '/organizations/org-slug/events/',
  107. headers: {
  108. Link:
  109. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  110. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  111. },
  112. body: {
  113. meta: {
  114. fields: {
  115. id: 'string',
  116. 'user.display': 'string',
  117. 'transaction.duration': 'duration',
  118. 'project.id': 'integer',
  119. timestamp: 'date',
  120. },
  121. },
  122. data,
  123. },
  124. match: [
  125. (_url, options) => {
  126. return options.query?.field?.includes('user.display');
  127. },
  128. ],
  129. });
  130. MockApiClient.addMockResponse({
  131. url: '/organizations/org-slug/events-has-measurements/',
  132. body: {measurements: false},
  133. });
  134. initialData = initializeData();
  135. eventView = EventView.fromNewQueryWithLocation(
  136. {
  137. id: undefined,
  138. version: 2,
  139. name: 'transactionName',
  140. fields,
  141. query,
  142. projects: [],
  143. orderby: '-timestamp',
  144. },
  145. initialData.router.location
  146. );
  147. });
  148. afterEach(function () {
  149. MockApiClient.clearMockResponses();
  150. ProjectsStore.reset();
  151. jest.clearAllMocks();
  152. });
  153. it('basic rendering', function () {
  154. render(
  155. <RouteContext.Provider value={initialData.routerContext}>
  156. <OrganizationContext.Provider value={initialData.organization}>
  157. <EventsPageContent
  158. totalEventCount={totalEventCount}
  159. eventView={eventView}
  160. organization={initialData.organization}
  161. location={initialData.router.location}
  162. transactionName={transactionName}
  163. spanOperationBreakdownFilter={SpanOperationBreakdownFilter.None}
  164. onChangeSpanOperationBreakdownFilter={() => {}}
  165. eventsDisplayFilterName={EventsDisplayFilterName.p100}
  166. onChangeEventsDisplayFilter={() => {}}
  167. setError={() => {}}
  168. />
  169. </OrganizationContext.Provider>
  170. </RouteContext.Provider>,
  171. {context: initialData.routerContext}
  172. );
  173. expect(screen.getByTestId('events-table')).toBeInTheDocument();
  174. expect(screen.getByText(textWithMarkupMatcher('Percentilep100'))).toBeInTheDocument();
  175. expect(
  176. screen.getByPlaceholderText(t('Search for events, users, tags, and more'))
  177. ).toBeInTheDocument();
  178. expect(screen.getByTestId('span-operation-breakdown-filter')).toBeInTheDocument();
  179. const columnTitles = screen
  180. .getAllByRole('columnheader')
  181. .map(elem => elem.textContent);
  182. expect(columnTitles).toEqual([
  183. t('event id'),
  184. t('user'),
  185. t('operation duration'),
  186. t('total duration'),
  187. t('trace id'),
  188. t('timestamp'),
  189. ]);
  190. });
  191. it('rendering with webvital selected', function () {
  192. render(
  193. <RouteContext.Provider value={initialData.routerContext}>
  194. <OrganizationContext.Provider value={initialData.organization}>
  195. <EventsPageContent
  196. totalEventCount={totalEventCount}
  197. eventView={eventView}
  198. organization={initialData.organization}
  199. location={initialData.router.location}
  200. transactionName={transactionName}
  201. spanOperationBreakdownFilter={SpanOperationBreakdownFilter.None}
  202. onChangeSpanOperationBreakdownFilter={() => {}}
  203. eventsDisplayFilterName={EventsDisplayFilterName.p100}
  204. onChangeEventsDisplayFilter={() => {}}
  205. webVital={WebVital.LCP}
  206. setError={() => {}}
  207. />
  208. </OrganizationContext.Provider>
  209. </RouteContext.Provider>,
  210. {context: initialData.routerContext}
  211. );
  212. expect(screen.getByTestId('events-table')).toBeInTheDocument();
  213. expect(screen.getByText(textWithMarkupMatcher('Percentilep100'))).toBeInTheDocument();
  214. expect(
  215. screen.getByPlaceholderText(t('Search for events, users, tags, and more'))
  216. ).toBeInTheDocument();
  217. expect(screen.getByTestId('span-operation-breakdown-filter')).toBeInTheDocument();
  218. const columnTitles = screen
  219. .getAllByRole('columnheader')
  220. .map(elem => elem.textContent);
  221. expect(columnTitles).toStrictEqual(expect.arrayContaining([t('measurements.lcp')]));
  222. });
  223. });