content.spec.tsx 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {useParams} from 'sentry/utils/useParams';
  7. import useProjects from 'sentry/utils/useProjects';
  8. import SpanSummary from 'sentry/views/performance/transactionSummary/transactionSpans/spanSummary/content';
  9. jest.mock('sentry/utils/useParams');
  10. jest.mock('sentry/utils/useLocation');
  11. jest.mock('sentry/utils/usePageFilters');
  12. jest.mock('sentry/utils/useProjects');
  13. describe('SpanSummaryPage', function () {
  14. const organization = OrganizationFixture();
  15. const project = ProjectFixture();
  16. jest.mocked(useLocation).mockReturnValue({
  17. pathname: '',
  18. search: '',
  19. query: {statsPeriod: '10d', project: '1'},
  20. hash: '',
  21. state: undefined,
  22. action: 'PUSH',
  23. key: '',
  24. });
  25. jest.mocked(useProjects).mockReturnValue({
  26. projects: [],
  27. onSearch: jest.fn(),
  28. placeholders: [],
  29. fetching: false,
  30. hasMore: null,
  31. fetchError: null,
  32. initiallyLoaded: false,
  33. });
  34. jest.mocked(usePageFilters).mockReturnValue({
  35. isReady: true,
  36. desyncedFilters: new Set(),
  37. pinnedFilters: new Set(),
  38. shouldPersist: true,
  39. selection: {
  40. datetime: {
  41. period: '10d',
  42. start: null,
  43. end: null,
  44. utc: false,
  45. },
  46. environments: [],
  47. projects: [parseInt(project.id, 10)],
  48. },
  49. });
  50. let headerDataMock;
  51. let avgDurationChartMock;
  52. let spanThroughputChartMock;
  53. let transactionThroughputChartMock;
  54. beforeEach(() => {
  55. jest.mocked(useParams).mockReturnValue({
  56. spanSlug: 'db:aaaaaaaa',
  57. });
  58. jest.clearAllMocks();
  59. avgDurationChartMock = MockApiClient.addMockResponse({
  60. url: '/organizations/org-slug/events-stats/',
  61. method: 'GET',
  62. match: [
  63. MockApiClient.matchQuery({
  64. referrer: 'api.performance.span-summary-duration-chart',
  65. }),
  66. ],
  67. body: {
  68. data: [
  69. [
  70. 1717102800,
  71. [
  72. {
  73. count: 4.924892746006871,
  74. },
  75. ],
  76. ],
  77. [
  78. 1717104600,
  79. [
  80. {
  81. count: 8.20925404044671,
  82. },
  83. ],
  84. ],
  85. [
  86. 1717106400,
  87. [
  88. {
  89. count: 7.218881600137195,
  90. },
  91. ],
  92. ],
  93. ],
  94. },
  95. });
  96. spanThroughputChartMock = MockApiClient.addMockResponse({
  97. url: '/organizations/org-slug/events-stats/',
  98. method: 'GET',
  99. match: [
  100. MockApiClient.matchQuery({
  101. referrer: 'api.performance.span-summary-throughput-chart',
  102. }),
  103. ],
  104. body: {
  105. data: [
  106. [
  107. 1717102800,
  108. [
  109. {
  110. count: 22580.666666666668,
  111. },
  112. ],
  113. ],
  114. [
  115. 1717104600,
  116. [
  117. {
  118. count: 258816.26666666666,
  119. },
  120. ],
  121. ],
  122. [
  123. 1717106400,
  124. [
  125. {
  126. count: 305550.4666666667,
  127. },
  128. ],
  129. ],
  130. ],
  131. },
  132. });
  133. transactionThroughputChartMock = MockApiClient.addMockResponse({
  134. url: '/organizations/org-slug/events-stats/',
  135. method: 'GET',
  136. match: [
  137. MockApiClient.matchQuery({
  138. referrer: 'api.performance.span-summary-transaction-throughput-chart',
  139. }),
  140. ],
  141. body: {
  142. data: [
  143. [
  144. 1717102800,
  145. [
  146. {
  147. count: 152823.58333333334,
  148. },
  149. ],
  150. ],
  151. [
  152. 1717106400,
  153. [
  154. {
  155. count: 143062.61666666667,
  156. },
  157. ],
  158. ],
  159. [
  160. 1717110000,
  161. [
  162. {
  163. count: 158031.58333333334,
  164. },
  165. ],
  166. ],
  167. ],
  168. },
  169. });
  170. MockApiClient.addMockResponse({
  171. url: '/organizations/org-slug/events/',
  172. body: {
  173. data: [
  174. {
  175. 'transaction.id': '93b88037ba134225bdf67d05a69de9ab',
  176. project: 'sentry',
  177. 'project.name': 'sentry',
  178. span_id: '9b6e1f295ce7e875',
  179. id: '9b6e1f295ce7e875',
  180. 'span.duration': 0.860929,
  181. trace: '80a8718f4b3847eb8d6f3b5715602558',
  182. timestamp: '2024-05-16T14:45:15+00:00',
  183. },
  184. ],
  185. },
  186. });
  187. MockApiClient.addMockResponse({
  188. url: '/organizations/org-slug/events/',
  189. body: {
  190. data: [
  191. {
  192. 'transaction.duration': 160,
  193. id: '93b88037ba134225bdf67d05a69de9ab',
  194. 'project.name': 'sentry',
  195. },
  196. {
  197. 'transaction.duration': 50,
  198. id: '2a2c0e1a7cf941f6bcd8ab22b0c4d8c9',
  199. 'project.name': 'sentry',
  200. },
  201. ],
  202. },
  203. });
  204. });
  205. it('correctly renders the details in the header', async function () {
  206. headerDataMock = MockApiClient.addMockResponse({
  207. url: '/organizations/org-slug/events/',
  208. body: {
  209. data: [
  210. {
  211. 'span.description': 'SELECT thing FROM my_cool_db WHERE value = %s',
  212. 'avg(span.duration)': 1.7381229881349218,
  213. 'count()': 3677407172,
  214. 'sum(span.self_time)': 6391491809.035965,
  215. },
  216. ],
  217. meta: {
  218. fields: {
  219. 'span.description': 'string',
  220. 'sum(span.self_time)': 'duration',
  221. 'count()': 'integer',
  222. 'avg(span.duration)': 'duration',
  223. },
  224. units: {
  225. 'span.description': null,
  226. 'sum(span.self_time)': 'millisecond',
  227. 'count()': null,
  228. 'avg(span.duration)': 'millisecond',
  229. },
  230. isMetricsData: false,
  231. isMetricsExtractedData: false,
  232. tips: {},
  233. datasetReason: 'unchanged',
  234. dataset: 'spansMetrics',
  235. },
  236. },
  237. });
  238. render(
  239. <SpanSummary
  240. spanSlug={{group: 'aaaaaaaa', op: 'db'}}
  241. transactionName="transaction"
  242. organization={organization}
  243. project={undefined}
  244. />
  245. );
  246. expect(headerDataMock).toHaveBeenCalled();
  247. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  248. expect(await screen.findByTestId('operation-name')).toHaveTextContent('db');
  249. expect(await screen.findByTestId('header-span-description')).toHaveTextContent(
  250. 'SELECT thing FROM my_cool_db WHERE value = %s'
  251. );
  252. expect(await screen.findByTestId('header-avg-duration')).toHaveTextContent('1.74ms');
  253. expect(await screen.findByTestId('header-total-time-spent')).toHaveTextContent(
  254. '2.43mo'
  255. );
  256. expect(await screen.findByTestId('total-span-count')).toHaveTextContent('3.6b spans');
  257. });
  258. it('renders the charts', async () => {
  259. render(
  260. <SpanSummary
  261. spanSlug={{group: 'aaaaaaaa', op: 'db'}}
  262. transactionName="transaction"
  263. organization={organization}
  264. project={project}
  265. />
  266. );
  267. expect(avgDurationChartMock).toHaveBeenCalled();
  268. expect(spanThroughputChartMock).toHaveBeenCalled();
  269. expect(transactionThroughputChartMock).toHaveBeenCalled();
  270. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  271. const chartHeaders = await screen.findAllByTestId('chart-panel-header');
  272. expect(chartHeaders[0]).toHaveTextContent('Average Duration');
  273. expect(chartHeaders[1]).toHaveTextContent('Span Throughput');
  274. expect(chartHeaders[2]).toHaveTextContent('Transaction Throughput');
  275. });
  276. });