httpLandingPage.spec.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. spanListRequestMock = MockApiClient.addMockResponse({
  62. url: `/organizations/${organization.slug}/events/`,
  63. method: 'GET',
  64. match: [
  65. MockApiClient.matchQuery({
  66. referrer: 'api.performance.http.landing-domains-list',
  67. }),
  68. ],
  69. body: {
  70. data: [
  71. {
  72. 'span.domain': ['*.sentry.io'],
  73. 'project.id': 1,
  74. 'sum(span.self_time)': 815833579.659315,
  75. 'spm()': 40767.0,
  76. 'time_spent_percentage()': 0.33634048399458855,
  77. 'http_response_rate(3)': 0.00035567983908553485,
  78. 'http_response_rate(4)': 0.3931893443226139,
  79. 'http_response_rate(5)': 0.0037624385736829626,
  80. 'avg(span.self_time)': 333.53512222275975,
  81. },
  82. {
  83. 'span.domain': ['*.github.com'],
  84. 'project.id': 2,
  85. 'sum(span.self_time)': 473552338.9970339,
  86. 'spm()': 29912.133333333335,
  87. 'time_spent_percentage()': 0.19522955032268177,
  88. 'http_response_rate(3)': 0.0,
  89. 'http_response_rate(4)': 0.0012324987407562593,
  90. 'http_response_rate(5)': 0.004054096219594279,
  91. 'avg(span.self_time)': 263.857441905979,
  92. },
  93. ],
  94. meta: {
  95. fields: {
  96. 'project.id': 'integer',
  97. 'span.domain': 'array',
  98. 'sum(span.self_time)': 'duration',
  99. 'http_response_rate(3)': 'percentage',
  100. 'spm()': 'rate',
  101. 'time_spent_percentage()': 'percentage',
  102. 'http_response_rate(4)': 'percentage',
  103. 'http_response_rate(5)': 'percentage',
  104. 'avg(span.self_time)': 'duration',
  105. },
  106. },
  107. },
  108. });
  109. spanChartsRequestMock = MockApiClient.addMockResponse({
  110. url: `/organizations/${organization.slug}/events-stats/`,
  111. method: 'GET',
  112. body: {
  113. 'spm()': {
  114. data: [
  115. [1699907700, [{count: 7810.2}]],
  116. [1699908000, [{count: 1216.8}]],
  117. ],
  118. },
  119. },
  120. });
  121. });
  122. afterAll(function () {
  123. jest.resetAllMocks();
  124. });
  125. it('fetches module data', async function () {
  126. render(<HTTPLandingPage />);
  127. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  128. 1,
  129. `/organizations/${organization.slug}/events-stats/`,
  130. expect.objectContaining({
  131. method: 'GET',
  132. query: {
  133. cursor: undefined,
  134. dataset: 'spansMetrics',
  135. environment: [],
  136. excludeOther: 0,
  137. field: [],
  138. interval: '30m',
  139. orderby: undefined,
  140. partial: 1,
  141. per_page: 50,
  142. project: [],
  143. query: 'span.module:http',
  144. referrer: 'api.performance.http.landing-throughput-chart',
  145. statsPeriod: '10d',
  146. topEvents: undefined,
  147. yAxis: 'spm()',
  148. },
  149. })
  150. );
  151. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  152. 2,
  153. `/organizations/${organization.slug}/events-stats/`,
  154. expect.objectContaining({
  155. method: 'GET',
  156. query: {
  157. cursor: undefined,
  158. dataset: 'spansMetrics',
  159. environment: [],
  160. excludeOther: 0,
  161. field: [],
  162. interval: '30m',
  163. orderby: undefined,
  164. partial: 1,
  165. per_page: 50,
  166. project: [],
  167. query: 'span.module:http',
  168. referrer: 'api.performance.http.landing-duration-chart',
  169. statsPeriod: '10d',
  170. topEvents: undefined,
  171. yAxis: 'avg(span.self_time)',
  172. },
  173. })
  174. );
  175. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  176. 3,
  177. `/organizations/${organization.slug}/events-stats/`,
  178. expect.objectContaining({
  179. method: 'GET',
  180. query: {
  181. cursor: undefined,
  182. dataset: 'spansMetrics',
  183. environment: [],
  184. excludeOther: 0,
  185. field: [],
  186. interval: '30m',
  187. orderby: undefined,
  188. partial: 1,
  189. per_page: 50,
  190. project: [],
  191. query: 'span.module:http',
  192. referrer: 'api.performance.http.landing-response-code-chart',
  193. statsPeriod: '10d',
  194. topEvents: undefined,
  195. yAxis: [
  196. 'http_response_rate(3)',
  197. 'http_response_rate(4)',
  198. 'http_response_rate(5)',
  199. ],
  200. },
  201. })
  202. );
  203. expect(spanListRequestMock).toHaveBeenCalledWith(
  204. `/organizations/${organization.slug}/events/`,
  205. expect.objectContaining({
  206. method: 'GET',
  207. query: {
  208. dataset: 'spansMetrics',
  209. environment: [],
  210. field: [
  211. 'project.id',
  212. 'span.domain',
  213. 'spm()',
  214. 'http_response_rate(3)',
  215. 'http_response_rate(4)',
  216. 'http_response_rate(5)',
  217. 'avg(span.self_time)',
  218. 'sum(span.self_time)',
  219. 'time_spent_percentage()',
  220. ],
  221. per_page: 10,
  222. project: [],
  223. query: 'span.module:http span.domain:*git*',
  224. referrer: 'api.performance.http.landing-domains-list',
  225. sort: '-time_spent_percentage()',
  226. statsPeriod: '10d',
  227. },
  228. })
  229. );
  230. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  231. });
  232. it('renders a list of domains', async function () {
  233. render(<HTTPLandingPage />);
  234. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  235. expect(screen.getByRole('table', {name: 'Domains'})).toBeInTheDocument();
  236. expect(screen.getByRole('columnheader', {name: 'Domain'})).toBeInTheDocument();
  237. expect(screen.getByRole('columnheader', {name: 'Project'})).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: '*.sentry.io'})).toBeInTheDocument();
  247. expect(screen.getByRole('link', {name: '*.sentry.io'})).toHaveAttribute(
  248. 'href',
  249. '/organizations/org-slug/performance/http/domains/?domain=%2A.sentry.io&project=1&statsPeriod=10d'
  250. );
  251. expect(screen.getByRole('cell', {name: 'backend'})).toBeInTheDocument();
  252. expect(screen.getByRole('link', {name: 'backend'})).toHaveAttribute(
  253. 'href',
  254. '/organizations/org-slug/projects/backend/?project=1'
  255. );
  256. expect(screen.getByRole('cell', {name: '40.8K/s'})).toBeInTheDocument();
  257. expect(screen.getByRole('cell', {name: '0.04%'})).toBeInTheDocument();
  258. expect(screen.getByRole('cell', {name: '39.32%'})).toBeInTheDocument();
  259. expect(screen.getByRole('cell', {name: '0.38%'})).toBeInTheDocument();
  260. expect(screen.getByRole('cell', {name: '333.54ms'})).toBeInTheDocument();
  261. expect(screen.getByRole('cell', {name: '1.35wk'})).toBeInTheDocument();
  262. });
  263. });