eventsTable.spec.tsx 9.6 KB

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