eventsTable.spec.tsx 10 KB

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