content.spec.tsx 9.9 KB

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