httpLandingPage.spec.tsx 5.9 KB

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