eventsTable.spec.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} 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. 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. showReplayCol={false}
  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. showReplayCol={false}
  232. />,
  233. {context: initialData.routerContext}
  234. );
  235. expect(screen.getAllByRole('columnheader')).toHaveLength(6);
  236. expect(screen.queryByText(SPAN_OP_RELATIVE_BREAKDOWN_FIELD)).not.toBeInTheDocument();
  237. expect(screen.queryByTestId('relative-ops-breakdown')).not.toBeInTheDocument();
  238. expect(screen.queryByTestId('grid-head-cell-static')).not.toBeInTheDocument();
  239. expect(container).toSnapshot();
  240. });
  241. it('renders event id and trace id url', async function () {
  242. const initialData = initializeData();
  243. const eventView = EventView.fromNewQueryWithLocation(
  244. {
  245. id: undefined,
  246. version: 2,
  247. name: 'transactionName',
  248. fields,
  249. query,
  250. projects: [],
  251. orderby: '-timestamp',
  252. },
  253. initialData.router.location
  254. );
  255. render(
  256. <EventsTable
  257. eventView={eventView}
  258. organization={organization}
  259. routes={initialData.router.routes}
  260. location={initialData.router.location}
  261. setError={() => {}}
  262. columnTitles={transactionsListTitles}
  263. transactionName={transactionName}
  264. showReplayCol={false}
  265. />,
  266. {context: initialData.routerContext}
  267. );
  268. expect(await screen.findByRole('link', {name: 'deadbeef'})).toHaveAttribute(
  269. 'href',
  270. '/organizations/org-slug/performance/undefined:deadbeef/?project=1&transaction=transactionName&transactionCursor=1%3A0%3A0'
  271. );
  272. expect(screen.getByRole('link', {name: '1234'})).toHaveAttribute(
  273. 'href',
  274. '/organizations/org-slug/performance/trace/1234/?'
  275. );
  276. });
  277. it('renders replay id', function () {
  278. const initialData = initializeData({features: ['session-replay-ui']});
  279. fields.push('replayId');
  280. data.forEach(result => {
  281. result.replayId = 'mock_replay_id';
  282. });
  283. const eventView = EventView.fromNewQueryWithLocation(
  284. {
  285. id: undefined,
  286. version: 2,
  287. name: 'transactionName',
  288. fields,
  289. query,
  290. projects: [],
  291. orderby: '-timestamp',
  292. },
  293. initialData.router.location
  294. );
  295. const {container} = render(
  296. <EventsTable
  297. eventView={eventView}
  298. organization={organization}
  299. routes={initialData.router.routes}
  300. location={initialData.router.location}
  301. setError={() => {}}
  302. columnTitles={transactionsListTitles}
  303. transactionName={transactionName}
  304. showReplayCol
  305. />,
  306. {context: initialData.routerContext}
  307. );
  308. expect(screen.getAllByRole('columnheader')).toHaveLength(7);
  309. expect(container).toSnapshot();
  310. });
  311. });