content.spec.tsx 9.3 KB

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