eventsTable.spec.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  3. import {t} from 'sentry/locale';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import EventView from 'sentry/utils/discover/eventView';
  6. import {
  7. SPAN_OP_BREAKDOWN_FIELDS,
  8. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  9. } from 'sentry/utils/discover/fields';
  10. import EventsTable from 'sentry/views/performance/transactionSummary/transactionEvents/eventsTable';
  11. type Data = {
  12. features?: string[];
  13. };
  14. export const MOCK_EVENTS_TABLE_DATA = [
  15. {
  16. id: 'deadbeef',
  17. 'user.display': 'uhoh@example.com',
  18. 'transaction.duration': 400,
  19. 'project.id': 1,
  20. timestamp: '2020-05-21T15:31:18+00:00',
  21. trace: '1234',
  22. 'span_ops_breakdown.relative': '',
  23. 'spans.browser': 100,
  24. 'spans.db': 30,
  25. 'spans.http': 170,
  26. 'spans.resource': 100,
  27. 'spans.total.time': 400,
  28. },
  29. {
  30. id: 'moredeadbeef',
  31. 'user.display': 'moreuhoh@example.com',
  32. 'transaction.duration': 600,
  33. 'project.id': 1,
  34. timestamp: '2020-05-22T15:31:18+00:00',
  35. trace: '4321',
  36. 'span_ops_breakdown.relative': '',
  37. 'spans.browser': 100,
  38. 'spans.db': 300,
  39. 'spans.http': 100,
  40. 'spans.resource': 100,
  41. 'spans.total.time': 600,
  42. },
  43. ];
  44. export const EVENTS_TABLE_RESPONSE_FIELDS = [
  45. 'id',
  46. 'user.display',
  47. SPAN_OP_RELATIVE_BREAKDOWN_FIELD,
  48. 'transaction.duration',
  49. 'trace',
  50. 'timestamp',
  51. 'spans.total.time',
  52. ...SPAN_OP_BREAKDOWN_FIELDS,
  53. ];
  54. function initializeData({features: additionalFeatures = []}: Data = {}) {
  55. const features = ['discover-basic', 'performance-view', ...additionalFeatures];
  56. const organization = TestStubs.Organization({
  57. features,
  58. projects: [TestStubs.Project()],
  59. apdexThreshold: 400,
  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. project: 1,
  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 = TestStubs.Organization();
  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: '/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. const {container} = 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. expect(container).toSnapshot();
  239. });
  240. it('renders event id and trace id url', async function () {
  241. const initialData = initializeData();
  242. const eventView = EventView.fromNewQueryWithLocation(
  243. {
  244. id: undefined,
  245. version: 2,
  246. name: 'transactionName',
  247. fields,
  248. query,
  249. projects: [],
  250. orderby: '-timestamp',
  251. },
  252. initialData.router.location
  253. );
  254. render(
  255. <EventsTable
  256. eventView={eventView}
  257. organization={organization}
  258. routes={initialData.router.routes}
  259. location={initialData.router.location}
  260. setError={() => {}}
  261. columnTitles={transactionsListTitles}
  262. transactionName={transactionName}
  263. />,
  264. {context: initialData.routerContext}
  265. );
  266. expect(await screen.findByRole('link', {name: 'deadbeef'})).toHaveAttribute(
  267. 'href',
  268. '/organizations/org-slug/performance/undefined:deadbeef/?project=1&transaction=transactionName&transactionCursor=1%3A0%3A0'
  269. );
  270. expect(screen.getByRole('link', {name: '1234'})).toHaveAttribute(
  271. 'href',
  272. '/organizations/org-slug/performance/trace/1234/?'
  273. );
  274. });
  275. it('renders replay id', async function () {
  276. const initialData = initializeData();
  277. fields = [...fields, 'replayId'];
  278. data.forEach(result => {
  279. result.replayId = 'mock_replay_id';
  280. });
  281. const eventView = EventView.fromNewQueryWithLocation(
  282. {
  283. id: undefined,
  284. version: 2,
  285. name: 'transactionName',
  286. fields,
  287. query,
  288. projects: [],
  289. orderby: '-timestamp',
  290. },
  291. initialData.router.location
  292. );
  293. const {container} = render(
  294. <EventsTable
  295. eventView={eventView}
  296. organization={organization}
  297. routes={initialData.router.routes}
  298. location={initialData.router.location}
  299. setError={() => {}}
  300. columnTitles={transactionsListTitles}
  301. transactionName={transactionName}
  302. />,
  303. {context: initialData.routerContext}
  304. );
  305. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  306. expect(screen.getAllByRole('columnheader')).toHaveLength(7);
  307. expect(container).toSnapshot();
  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. const {container} = 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. {context: initialData.routerContext}
  338. );
  339. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  340. expect(screen.getAllByRole('columnheader')).toHaveLength(7);
  341. expect(container).toSnapshot();
  342. });
  343. });