httpLandingPage.spec.tsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 useProjects from 'sentry/utils/useProjects';
  7. import {HTTPLandingPage} from 'sentry/views/performance/http/httpLandingPage';
  8. jest.mock('sentry/utils/useLocation');
  9. jest.mock('sentry/utils/usePageFilters');
  10. jest.mock('sentry/utils/useProjects');
  11. describe('HTTPLandingPage', function () {
  12. const organization = OrganizationFixture();
  13. let spanListRequestMock, spanChartsRequestMock;
  14. jest.mocked(usePageFilters).mockReturnValue({
  15. isReady: true,
  16. desyncedFilters: new Set(),
  17. pinnedFilters: new Set(),
  18. shouldPersist: true,
  19. selection: {
  20. datetime: {
  21. period: '10d',
  22. start: null,
  23. end: null,
  24. utc: false,
  25. },
  26. environments: [],
  27. projects: [],
  28. },
  29. });
  30. jest.mocked(useLocation).mockReturnValue({
  31. pathname: '',
  32. search: '',
  33. query: {statsPeriod: '10d', 'span.domain': 'git', project: '1'},
  34. hash: '',
  35. state: undefined,
  36. action: 'PUSH',
  37. key: '',
  38. });
  39. jest.mocked(useProjects).mockReturnValue({
  40. projects: [
  41. ProjectFixture({
  42. id: '1',
  43. name: 'Backend',
  44. slug: 'backend',
  45. firstTransactionEvent: true,
  46. platform: 'javascript',
  47. }),
  48. ],
  49. onSearch: jest.fn(),
  50. placeholders: [],
  51. fetching: false,
  52. hasMore: null,
  53. fetchError: null,
  54. initiallyLoaded: false,
  55. });
  56. beforeEach(function () {
  57. jest.clearAllMocks();
  58. MockApiClient.addMockResponse({
  59. url: `/organizations/${organization.slug}/projects/`,
  60. body: [ProjectFixture({name: 'frontend'}), ProjectFixture({name: 'backend'})],
  61. });
  62. spanListRequestMock = MockApiClient.addMockResponse({
  63. url: `/organizations/${organization.slug}/events/`,
  64. method: 'GET',
  65. match: [
  66. MockApiClient.matchQuery({
  67. referrer: 'api.performance.http.landing-domains-list',
  68. }),
  69. ],
  70. body: {
  71. data: [
  72. {
  73. 'span.domain': ['*.sentry.io'],
  74. project: 'backend',
  75. 'project.id': 1,
  76. 'sum(span.self_time)': 815833579.659315,
  77. 'spm()': 40767.0,
  78. 'time_spent_percentage()': 0.33634048399458855,
  79. 'http_response_rate(3)': 0.00035567983908553485,
  80. 'http_response_rate(4)': 0.3931893443226139,
  81. 'http_response_rate(5)': 0.0037624385736829626,
  82. 'avg(span.self_time)': 333.53512222275975,
  83. },
  84. {
  85. 'span.domain': ['*.github.com'],
  86. project: 'frontend',
  87. 'project.id': 2,
  88. 'sum(span.self_time)': 473552338.9970339,
  89. 'spm()': 29912.133333333335,
  90. 'time_spent_percentage()': 0.19522955032268177,
  91. 'http_response_rate(3)': 0.0,
  92. 'http_response_rate(4)': 0.0012324987407562593,
  93. 'http_response_rate(5)': 0.004054096219594279,
  94. 'avg(span.self_time)': 263.857441905979,
  95. },
  96. ],
  97. meta: {
  98. fields: {
  99. 'project.id': 'integer',
  100. 'span.domain': 'array',
  101. 'sum(span.self_time)': 'duration',
  102. 'http_response_rate(3)': 'percentage',
  103. 'spm()': 'rate',
  104. 'time_spent_percentage()': 'percentage',
  105. 'http_response_rate(4)': 'percentage',
  106. 'http_response_rate(5)': 'percentage',
  107. 'avg(span.self_time)': 'duration',
  108. },
  109. },
  110. },
  111. });
  112. spanChartsRequestMock = MockApiClient.addMockResponse({
  113. url: `/organizations/${organization.slug}/events-stats/`,
  114. method: 'GET',
  115. body: {
  116. 'spm()': {
  117. data: [
  118. [1699907700, [{count: 7810.2}]],
  119. [1699908000, [{count: 1216.8}]],
  120. ],
  121. },
  122. },
  123. });
  124. });
  125. afterAll(function () {
  126. jest.resetAllMocks();
  127. });
  128. it('fetches module data', async function () {
  129. render(<HTTPLandingPage />, {organization});
  130. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  131. 1,
  132. `/organizations/${organization.slug}/events-stats/`,
  133. expect.objectContaining({
  134. method: 'GET',
  135. query: {
  136. cursor: undefined,
  137. dataset: 'spansMetrics',
  138. environment: [],
  139. excludeOther: 0,
  140. field: [],
  141. interval: '30m',
  142. orderby: undefined,
  143. partial: 1,
  144. per_page: 50,
  145. project: [],
  146. query: 'span.module:http span.op:http.client',
  147. referrer: 'api.performance.http.landing-throughput-chart',
  148. statsPeriod: '10d',
  149. topEvents: undefined,
  150. yAxis: 'spm()',
  151. },
  152. })
  153. );
  154. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  155. 2,
  156. `/organizations/${organization.slug}/events-stats/`,
  157. expect.objectContaining({
  158. method: 'GET',
  159. query: {
  160. cursor: undefined,
  161. dataset: 'spansMetrics',
  162. environment: [],
  163. excludeOther: 0,
  164. field: [],
  165. interval: '30m',
  166. orderby: undefined,
  167. partial: 1,
  168. per_page: 50,
  169. project: [],
  170. query: 'span.module:http span.op:http.client',
  171. referrer: 'api.performance.http.landing-duration-chart',
  172. statsPeriod: '10d',
  173. topEvents: undefined,
  174. yAxis: 'avg(span.self_time)',
  175. },
  176. })
  177. );
  178. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  179. 3,
  180. `/organizations/${organization.slug}/events-stats/`,
  181. expect.objectContaining({
  182. method: 'GET',
  183. query: {
  184. cursor: undefined,
  185. dataset: 'spansMetrics',
  186. environment: [],
  187. excludeOther: 0,
  188. field: [],
  189. interval: '30m',
  190. orderby: undefined,
  191. partial: 1,
  192. per_page: 50,
  193. project: [],
  194. query: 'span.module:http span.op:http.client',
  195. referrer: 'api.performance.http.landing-response-code-chart',
  196. statsPeriod: '10d',
  197. topEvents: undefined,
  198. yAxis: [
  199. 'http_response_rate(3)',
  200. 'http_response_rate(4)',
  201. 'http_response_rate(5)',
  202. ],
  203. },
  204. })
  205. );
  206. expect(spanListRequestMock).toHaveBeenCalledWith(
  207. `/organizations/${organization.slug}/events/`,
  208. expect.objectContaining({
  209. method: 'GET',
  210. query: {
  211. dataset: 'spansMetrics',
  212. environment: [],
  213. field: [
  214. 'project',
  215. 'project.id',
  216. 'span.domain',
  217. 'spm()',
  218. 'http_response_rate(3)',
  219. 'http_response_rate(4)',
  220. 'http_response_rate(5)',
  221. 'avg(span.self_time)',
  222. 'sum(span.self_time)',
  223. 'time_spent_percentage()',
  224. ],
  225. per_page: 10,
  226. project: [],
  227. query: 'span.module:http span.op:http.client span.domain:*git*',
  228. referrer: 'api.performance.http.landing-domains-list',
  229. sort: '-time_spent_percentage()',
  230. statsPeriod: '10d',
  231. },
  232. })
  233. );
  234. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  235. });
  236. it('renders a list of domains', async function () {
  237. render(<HTTPLandingPage />, {organization});
  238. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  239. expect(screen.getByRole('table', {name: 'Domains'})).toBeInTheDocument();
  240. expect(screen.getByRole('columnheader', {name: 'Domain'})).toBeInTheDocument();
  241. expect(screen.getByRole('columnheader', {name: 'Project'})).toBeInTheDocument();
  242. expect(
  243. screen.getByRole('columnheader', {name: 'Requests Per Minute'})
  244. ).toBeInTheDocument();
  245. expect(screen.getByRole('columnheader', {name: '3XXs'})).toBeInTheDocument();
  246. expect(screen.getByRole('columnheader', {name: '4XXs'})).toBeInTheDocument();
  247. expect(screen.getByRole('columnheader', {name: '5XXs'})).toBeInTheDocument();
  248. expect(screen.getByRole('columnheader', {name: 'Avg Duration'})).toBeInTheDocument();
  249. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  250. expect(screen.getByRole('cell', {name: '*.sentry.io'})).toBeInTheDocument();
  251. expect(screen.getByRole('link', {name: '*.sentry.io'})).toHaveAttribute(
  252. 'href',
  253. '/organizations/org-slug/performance/http/domains/?domain=%2A.sentry.io&project=1&statsPeriod=10d'
  254. );
  255. expect(screen.getByRole('cell', {name: 'backend'})).toBeInTheDocument();
  256. expect(screen.getByRole('link', {name: 'backend'})).toHaveAttribute(
  257. 'href',
  258. '/organizations/org-slug/projects/backend/?project=1'
  259. );
  260. expect(screen.getByRole('cell', {name: '40.8K/s'})).toBeInTheDocument();
  261. expect(screen.getByRole('cell', {name: '0.04%'})).toBeInTheDocument();
  262. expect(screen.getByRole('cell', {name: '39.32%'})).toBeInTheDocument();
  263. expect(screen.getByRole('cell', {name: '0.38%'})).toBeInTheDocument();
  264. expect(screen.getByRole('cell', {name: '333.54ms'})).toBeInTheDocument();
  265. expect(screen.getByRole('cell', {name: '1.35wk'})).toBeInTheDocument();
  266. });
  267. });