httpDomainSummaryPage.spec.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {HTTPDomainSummaryPage} from 'sentry/views/performance/http/httpDomainSummaryPage';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('HTTPSummaryPage', function () {
  11. const organization = OrganizationFixture();
  12. let domainChartsRequestMock, domainTransactionsListRequestMock;
  13. jest.mocked(usePageFilters).mockReturnValue({
  14. isReady: true,
  15. desyncedFilters: new Set(),
  16. pinnedFilters: new Set(),
  17. shouldPersist: true,
  18. selection: {
  19. datetime: {
  20. period: '10d',
  21. start: null,
  22. end: null,
  23. utc: false,
  24. },
  25. environments: [],
  26. projects: [],
  27. },
  28. });
  29. jest.mocked(useLocation).mockReturnValue({
  30. pathname: '',
  31. search: '',
  32. query: {domain: '*.sentry.dev', statsPeriod: '10d', transactionsCursor: '0:20:0'},
  33. hash: '',
  34. state: undefined,
  35. action: 'PUSH',
  36. key: '',
  37. });
  38. jest.mocked(useOrganization).mockReturnValue(organization);
  39. beforeEach(function () {
  40. jest.clearAllMocks();
  41. domainTransactionsListRequestMock = MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/events/`,
  43. method: 'GET',
  44. body: {
  45. data: [],
  46. },
  47. });
  48. domainChartsRequestMock = MockApiClient.addMockResponse({
  49. url: `/organizations/${organization.slug}/events-stats/`,
  50. method: 'GET',
  51. body: {
  52. 'spm()': {
  53. data: [
  54. [1699907700, [{count: 7810.2}]],
  55. [1699908000, [{count: 1216.8}]],
  56. ],
  57. },
  58. },
  59. });
  60. });
  61. afterAll(function () {
  62. jest.resetAllMocks();
  63. });
  64. it('fetches module data', async function () {
  65. render(<HTTPDomainSummaryPage />);
  66. expect(domainChartsRequestMock).toHaveBeenNthCalledWith(
  67. 1,
  68. `/organizations/${organization.slug}/events-stats/`,
  69. expect.objectContaining({
  70. method: 'GET',
  71. query: {
  72. cursor: undefined,
  73. dataset: 'spansMetrics',
  74. environment: [],
  75. excludeOther: 0,
  76. field: [],
  77. interval: '30m',
  78. orderby: undefined,
  79. partial: 1,
  80. per_page: 50,
  81. project: [],
  82. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  83. referrer: 'api.performance.http.domain-summary-throughput-chart',
  84. statsPeriod: '10d',
  85. topEvents: undefined,
  86. yAxis: 'spm()',
  87. },
  88. })
  89. );
  90. expect(domainChartsRequestMock).toHaveBeenNthCalledWith(
  91. 2,
  92. `/organizations/${organization.slug}/events-stats/`,
  93. expect.objectContaining({
  94. method: 'GET',
  95. query: {
  96. cursor: undefined,
  97. dataset: 'spansMetrics',
  98. environment: [],
  99. excludeOther: 0,
  100. field: [],
  101. interval: '30m',
  102. orderby: undefined,
  103. partial: 1,
  104. per_page: 50,
  105. project: [],
  106. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  107. referrer: 'api.performance.http.domain-summary-duration-chart',
  108. statsPeriod: '10d',
  109. topEvents: undefined,
  110. yAxis: 'avg(span.self_time)',
  111. },
  112. })
  113. );
  114. expect(domainChartsRequestMock).toHaveBeenNthCalledWith(
  115. 3,
  116. `/organizations/${organization.slug}/events-stats/`,
  117. expect.objectContaining({
  118. method: 'GET',
  119. query: {
  120. cursor: undefined,
  121. dataset: 'spansMetrics',
  122. environment: [],
  123. excludeOther: 0,
  124. field: [],
  125. interval: '30m',
  126. orderby: undefined,
  127. partial: 1,
  128. per_page: 50,
  129. project: [],
  130. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  131. referrer: 'api.performance.http.domain-summary-response-code-chart',
  132. statsPeriod: '10d',
  133. topEvents: undefined,
  134. yAxis: [
  135. 'http_response_rate(3)',
  136. 'http_response_rate(4)',
  137. 'http_response_rate(5)',
  138. ],
  139. },
  140. })
  141. );
  142. expect(domainTransactionsListRequestMock).toHaveBeenNthCalledWith(
  143. 1,
  144. `/organizations/${organization.slug}/events/`,
  145. expect.objectContaining({
  146. method: 'GET',
  147. query: {
  148. dataset: 'spansMetrics',
  149. environment: [],
  150. field: [
  151. 'spm()',
  152. 'avg(span.self_time)',
  153. 'sum(span.self_time)',
  154. 'http_response_rate(3)',
  155. 'http_response_rate(4)',
  156. 'http_response_rate(5)',
  157. 'time_spent_percentage()',
  158. ],
  159. per_page: 50,
  160. project: [],
  161. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  162. referrer: 'api.performance.http.domain-summary-metrics-ribbon',
  163. statsPeriod: '10d',
  164. },
  165. })
  166. );
  167. expect(domainTransactionsListRequestMock).toHaveBeenNthCalledWith(
  168. 2,
  169. `/organizations/${organization.slug}/events/`,
  170. expect.objectContaining({
  171. method: 'GET',
  172. query: {
  173. dataset: 'spansMetrics',
  174. environment: [],
  175. field: [
  176. 'project.id',
  177. 'transaction',
  178. 'transaction.method',
  179. 'spm()',
  180. 'http_response_rate(3)',
  181. 'http_response_rate(4)',
  182. 'http_response_rate(5)',
  183. 'avg(span.self_time)',
  184. 'sum(span.self_time)',
  185. 'time_spent_percentage()',
  186. ],
  187. per_page: 20,
  188. project: [],
  189. cursor: '0:20:0',
  190. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  191. sort: '-time_spent_percentage()',
  192. referrer: 'api.performance.http.domain-summary-transactions-list',
  193. statsPeriod: '10d',
  194. },
  195. })
  196. );
  197. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  198. });
  199. it('renders a list of queries', async function () {
  200. MockApiClient.addMockResponse({
  201. url: `/organizations/${organization.slug}/events/`,
  202. method: 'GET',
  203. match: [
  204. MockApiClient.matchQuery({
  205. referrer: 'api.performance.http.domain-summary-transactions-list',
  206. }),
  207. ],
  208. body: {
  209. data: [
  210. {
  211. 'project.id': 8,
  212. transaction: '/api/users',
  213. 'transaction.method': 'GET',
  214. 'spm()': 17.88,
  215. 'http_response_rate(3)': 0.97,
  216. 'http_response_rate(4)': 0.025,
  217. 'http_response_rate(5)': 0.005,
  218. 'avg(span.self_time)': 204.5,
  219. 'sum(span.self_time)': 177238,
  220. },
  221. ],
  222. meta: {
  223. fields: {
  224. 'spm()': 'rate',
  225. 'avg(span.self_time)': 'duration',
  226. 'http_response_rate(3)': 'percentage',
  227. 'http_response_rate(4)': 'percentage',
  228. 'http_response_rate(5)': 'percentage',
  229. 'sum(span.self_time)': 'duration',
  230. },
  231. },
  232. },
  233. });
  234. render(<HTTPDomainSummaryPage />);
  235. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  236. expect(screen.getByRole('table', {name: 'Transactions'})).toBeInTheDocument();
  237. expect(screen.getByRole('columnheader', {name: 'Found In'})).toBeInTheDocument();
  238. expect(
  239. screen.getByRole('columnheader', {name: 'Requests Per Minute'})
  240. ).toBeInTheDocument();
  241. expect(screen.getByRole('columnheader', {name: '3XXs'})).toBeInTheDocument();
  242. expect(screen.getByRole('columnheader', {name: '4XXs'})).toBeInTheDocument();
  243. expect(screen.getByRole('columnheader', {name: '5XXs'})).toBeInTheDocument();
  244. expect(screen.getByRole('columnheader', {name: 'Avg Duration'})).toBeInTheDocument();
  245. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  246. expect(screen.getByRole('cell', {name: 'GET /api/users'})).toBeInTheDocument();
  247. expect(screen.getByRole('link', {name: 'GET /api/users'})).toHaveAttribute(
  248. 'href',
  249. '/organizations/org-slug/performance/http/domains/?domain=%2A.sentry.dev&project=8&statsPeriod=10d&transaction=%2Fapi%2Fusers&transactionMethod=GET&transactionsCursor=0%3A20%3A0'
  250. );
  251. expect(screen.getByRole('cell', {name: '17.9/s'})).toBeInTheDocument();
  252. expect(screen.getByRole('cell', {name: '97%'})).toBeInTheDocument();
  253. expect(screen.getByRole('cell', {name: '2.5%'})).toBeInTheDocument();
  254. expect(screen.getByRole('cell', {name: '0.5%'})).toBeInTheDocument();
  255. expect(screen.getByRole('cell', {name: '204.50ms'})).toBeInTheDocument();
  256. expect(screen.getByRole('cell', {name: '2.95min'})).toBeInTheDocument();
  257. });
  258. });