httpLandingPage.spec.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 {HTTPLandingPage} from 'sentry/views/performance/http/httpLandingPage';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('HTTPLandingPage', function () {
  11. const organization = OrganizationFixture();
  12. let spanListRequestMock, spanChartsRequestMock;
  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: {statsPeriod: '10d'},
  33. hash: '',
  34. state: undefined,
  35. action: 'PUSH',
  36. key: '',
  37. });
  38. jest.mocked(useOrganization).mockReturnValue(organization);
  39. beforeEach(function () {
  40. jest.clearAllMocks();
  41. spanListRequestMock = MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/events/`,
  43. method: 'GET',
  44. match: [
  45. MockApiClient.matchQuery({
  46. referrer: 'api.starfish.http-module-landing-domains-list',
  47. }),
  48. ],
  49. body: {
  50. data: [
  51. {
  52. 'span.domain': '*.sentry.io',
  53. },
  54. {
  55. 'span.domain': '*.github.com',
  56. },
  57. ],
  58. },
  59. });
  60. spanChartsRequestMock = MockApiClient.addMockResponse({
  61. url: `/organizations/${organization.slug}/events-stats/`,
  62. method: 'GET',
  63. body: {
  64. 'spm()': {
  65. data: [
  66. [1699907700, [{count: 7810.2}]],
  67. [1699908000, [{count: 1216.8}]],
  68. ],
  69. },
  70. },
  71. });
  72. });
  73. afterAll(function () {
  74. jest.resetAllMocks();
  75. });
  76. it('fetches module data', async function () {
  77. render(<HTTPLandingPage />);
  78. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  79. 1,
  80. `/organizations/${organization.slug}/events-stats/`,
  81. expect.objectContaining({
  82. method: 'GET',
  83. query: {
  84. cursor: undefined,
  85. dataset: 'spansMetrics',
  86. environment: [],
  87. excludeOther: 0,
  88. field: [],
  89. interval: '30m',
  90. orderby: undefined,
  91. partial: 1,
  92. per_page: 50,
  93. project: [],
  94. query: 'span.module:http has:span.domain',
  95. referrer: 'api.starfish.http-module-landing-throughput-chart',
  96. statsPeriod: '10d',
  97. topEvents: undefined,
  98. yAxis: 'spm()',
  99. },
  100. })
  101. );
  102. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  103. 2,
  104. `/organizations/${organization.slug}/events-stats/`,
  105. expect.objectContaining({
  106. method: 'GET',
  107. query: {
  108. cursor: undefined,
  109. dataset: 'spansMetrics',
  110. environment: [],
  111. excludeOther: 0,
  112. field: [],
  113. interval: '30m',
  114. orderby: undefined,
  115. partial: 1,
  116. per_page: 50,
  117. project: [],
  118. query: 'span.module:http has:span.domain',
  119. referrer: 'api.starfish.http-module-landing-duration-chart',
  120. statsPeriod: '10d',
  121. topEvents: undefined,
  122. yAxis: 'avg(span.self_time)',
  123. },
  124. })
  125. );
  126. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  127. 3,
  128. `/organizations/${organization.slug}/events-stats/`,
  129. expect.objectContaining({
  130. method: 'GET',
  131. query: {
  132. cursor: undefined,
  133. dataset: 'spansMetrics',
  134. environment: [],
  135. excludeOther: 0,
  136. field: [],
  137. interval: '30m',
  138. orderby: undefined,
  139. partial: 1,
  140. per_page: 50,
  141. project: [],
  142. query: 'span.module:http has:span.domain',
  143. referrer: 'api.starfish.http-module-landing-response-code-chart',
  144. statsPeriod: '10d',
  145. topEvents: undefined,
  146. yAxis: [
  147. 'http_response_rate(3)',
  148. 'http_response_rate(4)',
  149. 'http_response_rate(5)',
  150. ],
  151. },
  152. })
  153. );
  154. expect(spanListRequestMock).toHaveBeenCalledWith(
  155. `/organizations/${organization.slug}/events/`,
  156. expect.objectContaining({
  157. method: 'GET',
  158. query: {
  159. dataset: 'spansMetrics',
  160. environment: [],
  161. field: [
  162. 'project.id',
  163. 'span.domain',
  164. 'spm()',
  165. 'http_response_rate(3)',
  166. 'http_response_rate(4)',
  167. 'http_response_rate(5)',
  168. 'avg(span.self_time)',
  169. 'sum(span.self_time)',
  170. 'time_spent_percentage()',
  171. ],
  172. per_page: 10,
  173. project: [],
  174. query: 'span.module:http has:span.domain',
  175. referrer: 'api.starfish.http-module-landing-domains-list',
  176. sort: '-time_spent_percentage()',
  177. statsPeriod: '10d',
  178. },
  179. })
  180. );
  181. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  182. });
  183. it('renders a list of domains', async function () {
  184. render(<HTTPLandingPage />);
  185. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  186. expect(screen.getByRole('link', {name: '*.sentry.io'})).toHaveAttribute(
  187. 'href',
  188. '/organizations/org-slug/performance/http/domains/?domain=%2A.sentry.io&statsPeriod=10d'
  189. );
  190. expect(screen.getByRole('link', {name: '*.github.com'})).toHaveAttribute(
  191. 'href',
  192. '/organizations/org-slug/performance/http/domains/?domain=%2A.github.com&statsPeriod=10d'
  193. );
  194. });
  195. });