httpLandingPage.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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(spanListRequestMock).toHaveBeenCalledWith(
  126. `/organizations/${organization.slug}/events/`,
  127. expect.objectContaining({
  128. method: 'GET',
  129. query: {
  130. dataset: 'spansMetrics',
  131. environment: [],
  132. field: [
  133. 'project.id',
  134. 'span.domain',
  135. 'spm()',
  136. 'avg(span.self_time)',
  137. 'sum(span.self_time)',
  138. 'time_spent_percentage()',
  139. ],
  140. per_page: 10,
  141. project: [],
  142. query: 'span.module:http has:span.domain',
  143. referrer: 'api.starfish.http-module-landing-domains-list',
  144. sort: '-time_spent_percentage()',
  145. statsPeriod: '10d',
  146. },
  147. })
  148. );
  149. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  150. });
  151. it('renders a list of domains', async function () {
  152. render(<HTTPLandingPage />);
  153. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  154. expect(screen.getByRole('link', {name: '*.sentry.io'})).toHaveAttribute(
  155. 'href',
  156. '/organizations/org-slug/performance/http/domains/?domain=%2A.sentry.io&statsPeriod=10d'
  157. );
  158. expect(screen.getByRole('link', {name: '*.github.com'})).toHaveAttribute(
  159. 'href',
  160. '/organizations/org-slug/performance/http/domains/?domain=%2A.github.com&statsPeriod=10d'
  161. );
  162. });
  163. });