content.spec.tsx 9.3 KB

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