httpLandingPage.spec.tsx 9.5 KB

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