httpLandingPage.spec.tsx 9.2 KB

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