eventsTable.spec.tsx 10 KB

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