eventsTable.spec.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  5. import {t} from 'sentry/locale';
  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 EventsTable from 'sentry/views/performance/transactionSummary/transactionEvents/eventsTable';
  13. type Data = {
  14. features?: string[];
  15. };
  16. export const MOCK_EVENTS_TABLE_DATA = [
  17. {
  18. id: 'deadbeef',
  19. 'user.display': 'uhoh@example.com',
  20. 'transaction.duration': 400,
  21. 'project.id': 1,
  22. timestamp: '2020-05-21T15:31:18+00:00',
  23. trace: '1234',
  24. 'span_ops_breakdown.relative': '',
  25. 'spans.browser': 100,
  26. 'spans.db': 30,
  27. 'spans.http': 170,
  28. 'spans.resource': 100,
  29. 'spans.total.time': 400,
  30. },
  31. {
  32. id: 'moredeadbeef',
  33. 'user.display': 'moreuhoh@example.com',
  34. 'transaction.duration': 600,
  35. 'project.id': 1,
  36. timestamp: '2020-05-22T15:31:18+00:00',
  37. trace: '4321',
  38. 'span_ops_breakdown.relative': '',
  39. 'spans.browser': 100,
  40. 'spans.db': 300,
  41. 'spans.http': 100,
  42. 'spans.resource': 100,
  43. 'spans.total.time': 600,
  44. },
  45. ];
  46. export const EVENTS_TABLE_RESPONSE_FIELDS = [
  47. 'id',
  48. 'user.display',
  49. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  50. 'transaction.duration',
  51. 'trace',
  52. 'timestamp',
  53. 'spans.total.time',
  54. ...SPAN_OP_BREAKDOWN_FIELDS,
  55. ];
  56. function initializeData({features: additionalFeatures = []}: Data = {}) {
  57. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  58. const organization = OrganizationFixture({
  59. features,
  60. projects: [ProjectFixture()],
  61. });
  62. const initialData = initializeOrg({
  63. organization,
  64. router: {
  65. location: {
  66. query: {
  67. transaction: '/performance',
  68. project: '1',
  69. transactionCursor: '1:0:0',
  70. },
  71. },
  72. },
  73. projects: [],
  74. });
  75. ProjectsStore.loadInitialData(initialData.organization.projects);
  76. return initialData;
  77. }
  78. describe('Performance GridEditable Table', function () {
  79. const transactionsListTitles = [
  80. t('event id'),
  81. t('user'),
  82. t('operation duration'),
  83. t('total duration'),
  84. t('trace id'),
  85. t('timestamp'),
  86. ];
  87. let fields = EVENTS_TABLE_RESPONSE_FIELDS;
  88. const organization = OrganizationFixture();
  89. const transactionName = 'transactionName';
  90. let data;
  91. const query =
  92. 'transaction.duration:<15m event.type:transaction transaction:/api/0/organizations/{organization_slug}/events/';
  93. beforeEach(function () {
  94. MockApiClient.addMockResponse({
  95. url: '/organizations/org-slug/projects/',
  96. body: [],
  97. });
  98. MockApiClient.addMockResponse({
  99. url: '/organizations/org-slug/prompts-activity/',
  100. body: {},
  101. });
  102. MockApiClient.addMockResponse({
  103. url: '/organizations/org-slug/sdk-updates/',
  104. body: [],
  105. });
  106. fields = EVENTS_TABLE_RESPONSE_FIELDS;
  107. data = MOCK_EVENTS_TABLE_DATA;
  108. // Total events count response
  109. MockApiClient.addMockResponse({
  110. url: '/organizations/org-slug/events/',
  111. headers: {
  112. Link:
  113. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  114. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  115. },
  116. body: {
  117. meta: {
  118. fields: {
  119. 'count()': 'integer',
  120. },
  121. },
  122. data: [{'count()': 100}],
  123. },
  124. match: [
  125. (_url, options) => {
  126. return options.query?.field?.includes('count()');
  127. },
  128. ],
  129. });
  130. // Transaction list response
  131. MockApiClient.addMockResponse({
  132. url: '/organizations/org-slug/events/',
  133. headers: {
  134. Link:
  135. '<http://localhost/api/0/organizations/org-slug/events/?cursor=2:0:0>; rel="next"; results="true"; cursor="2:0:0",' +
  136. '<http://localhost/api/0/organizations/org-slug/events/?cursor=1:0:0>; rel="previous"; results="false"; cursor="1:0:0"',
  137. },
  138. body: {
  139. meta: {
  140. fields: {
  141. id: 'string',
  142. 'user.display': 'string',
  143. 'transaction.duration': 'duration',
  144. 'project.id': 'integer',
  145. timestamp: 'date',
  146. },
  147. },
  148. data,
  149. },
  150. match: [
  151. (_url, options) => {
  152. return options.query?.field?.includes('user.display');
  153. },
  154. ],
  155. });
  156. });
  157. afterEach(function () {
  158. MockApiClient.clearMockResponses();
  159. ProjectsStore.reset();
  160. jest.clearAllMocks();
  161. });
  162. it('renders ops breakdown bar when querying for span_ops_breakdown.relative', async function () {
  163. const initialData = initializeData();
  164. const eventView = EventView.fromNewQueryWithLocation(
  165. {
  166. id: undefined,
  167. version: 2,
  168. name: 'transactionName',
  169. fields,
  170. query,
  171. projects: [],
  172. orderby: '-timestamp',
  173. },
  174. initialData.router.location
  175. );
  176. render(
  177. <EventsTable
  178. eventView={eventView}
  179. organization={organization}
  180. routes={initialData.router.routes}
  181. location={initialData.router.location}
  182. setError={() => {}}
  183. columnTitles={transactionsListTitles}
  184. transactionName={transactionName}
  185. />,
  186. {context: initialData.routerContext}
  187. );
  188. expect(await screen.findAllByTestId('relative-ops-breakdown')).toHaveLength(2);
  189. expect(screen.getAllByRole('columnheader')).toHaveLength(6);
  190. expect(screen.getByText('operation duration')).toBeInTheDocument();
  191. expect(screen.queryByTestId('grid-head-cell-static')).not.toBeInTheDocument();
  192. });
  193. it('renders basic columns without ops breakdown when not querying for span_ops_breakdown.relative', function () {
  194. const initialData = initializeData();
  195. fields = [
  196. 'id',
  197. 'user.display',
  198. 'transaction.duration',
  199. 'trace',
  200. 'timestamp',
  201. 'spans.http',
  202. ];
  203. data.forEach(result => {
  204. delete result['span_ops_breakdown.relative'];
  205. delete result['spans.resource'];
  206. delete result['spans.browser'];
  207. delete result['spans.db'];
  208. delete result['spans.total.time'];
  209. });
  210. const eventView = EventView.fromNewQueryWithLocation(
  211. {
  212. id: undefined,
  213. version: 2,
  214. name: 'transactionName',
  215. fields,
  216. query,
  217. projects: [],
  218. orderby: '-timestamp',
  219. },
  220. initialData.router.location
  221. );
  222. render(
  223. <EventsTable
  224. eventView={eventView}
  225. organization={organization}
  226. routes={initialData.router.routes}
  227. location={initialData.router.location}
  228. setError={() => {}}
  229. columnTitles={transactionsListTitles}
  230. transactionName={transactionName}
  231. />,
  232. {context: initialData.routerContext}
  233. );
  234. expect(screen.getAllByRole('columnheader')).toHaveLength(6);
  235. expect(screen.queryByText(SPAN_OP_RELATIVE_BREAKDOWN_FIELD)).not.toBeInTheDocument();
  236. expect(screen.queryByTestId('relative-ops-breakdown')).not.toBeInTheDocument();
  237. expect(screen.queryByTestId('grid-head-cell-static')).not.toBeInTheDocument();
  238. });
  239. it('renders event id and trace id url', async function () {
  240. const initialData = initializeData();
  241. const eventView = EventView.fromNewQueryWithLocation(
  242. {
  243. id: undefined,
  244. version: 2,
  245. name: 'transactionName',
  246. fields,
  247. query,
  248. projects: [],
  249. orderby: '-timestamp',
  250. },
  251. initialData.router.location
  252. );
  253. render(
  254. <EventsTable
  255. eventView={eventView}
  256. organization={organization}
  257. routes={initialData.router.routes}
  258. location={initialData.router.location}
  259. setError={() => {}}
  260. columnTitles={transactionsListTitles}
  261. transactionName={transactionName}
  262. />,
  263. {context: initialData.routerContext}
  264. );
  265. expect(await screen.findByRole('link', {name: 'deadbeef'})).toHaveAttribute(
  266. 'href',
  267. '/organizations/org-slug/performance/undefined:deadbeef/?project=1&transaction=transactionName&transactionCursor=1%3A0%3A0'
  268. );
  269. expect(screen.getByRole('link', {name: '1234'})).toHaveAttribute(
  270. 'href',
  271. '/organizations/org-slug/performance/trace/1234/?'
  272. );
  273. });
  274. it('renders replay id', async function () {
  275. MockApiClient.addMockResponse({
  276. url: '/organizations/org-slug/replay-count/',
  277. body: {},
  278. });
  279. const initialData = initializeData();
  280. fields = [...fields, 'replayId'];
  281. data.forEach(result => {
  282. result.replayId = 'mock_replay_id';
  283. });
  284. const eventView = EventView.fromNewQueryWithLocation(
  285. {
  286. id: undefined,
  287. version: 2,
  288. name: 'transactionName',
  289. fields,
  290. query,
  291. projects: [],
  292. orderby: '-timestamp',
  293. },
  294. initialData.router.location
  295. );
  296. render(
  297. <EventsTable
  298. eventView={eventView}
  299. organization={organization}
  300. routes={initialData.router.routes}
  301. location={initialData.router.location}
  302. setError={() => {}}
  303. columnTitles={transactionsListTitles}
  304. transactionName={transactionName}
  305. />,
  306. {context: initialData.routerContext}
  307. );
  308. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  309. expect(screen.getAllByRole('columnheader')).toHaveLength(7);
  310. });
  311. it('renders profile id', async function () {
  312. const initialData = initializeData();
  313. fields = [...fields, 'profile.id'];
  314. data.forEach(result => {
  315. result['profile.id'] = 'mock_profile_id';
  316. });
  317. const eventView = EventView.fromNewQueryWithLocation(
  318. {
  319. id: undefined,
  320. version: 2,
  321. name: 'transactionName',
  322. fields,
  323. query,
  324. projects: [],
  325. orderby: '-timestamp',
  326. },
  327. initialData.router.location
  328. );
  329. render(
  330. <EventsTable
  331. eventView={eventView}
  332. organization={organization}
  333. routes={initialData.router.routes}
  334. location={initialData.router.location}
  335. setError={() => {}}
  336. columnTitles={transactionsListTitles}
  337. transactionName={transactionName}
  338. />,
  339. {context: initialData.routerContext}
  340. );
  341. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  342. expect(screen.getAllByRole('columnheader')).toHaveLength(7);
  343. });
  344. });