httpLandingPage.spec.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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({referrer: 'api.starfish.http-module-domains-list'}),
  45. ],
  46. body: {
  47. data: [
  48. {
  49. 'span.domain': '*.sentry.io',
  50. },
  51. {
  52. 'span.domain': '*.github.com',
  53. },
  54. ],
  55. },
  56. });
  57. spanChartsRequestMock = MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/events-stats/`,
  59. method: 'GET',
  60. body: {
  61. 'spm()': {
  62. data: [
  63. [1699907700, [{count: 7810.2}]],
  64. [1699908000, [{count: 1216.8}]],
  65. ],
  66. },
  67. },
  68. });
  69. });
  70. afterAll(function () {
  71. jest.resetAllMocks();
  72. });
  73. it('fetches module data', async function () {
  74. render(<HTTPLandingPage />);
  75. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  76. 1,
  77. `/organizations/${organization.slug}/events-stats/`,
  78. expect.objectContaining({
  79. method: 'GET',
  80. query: {
  81. cursor: undefined,
  82. dataset: 'spansMetrics',
  83. environment: [],
  84. excludeOther: 0,
  85. field: [],
  86. interval: '30m',
  87. orderby: undefined,
  88. partial: 1,
  89. per_page: 50,
  90. project: [],
  91. query: 'span.module:http has:span.domain',
  92. referrer: 'api.starfish.http-module-landing-throughput-chart',
  93. statsPeriod: '10d',
  94. topEvents: undefined,
  95. yAxis: 'spm()',
  96. },
  97. })
  98. );
  99. expect(spanChartsRequestMock).toHaveBeenNthCalledWith(
  100. 2,
  101. `/organizations/${organization.slug}/events-stats/`,
  102. expect.objectContaining({
  103. method: 'GET',
  104. query: {
  105. cursor: undefined,
  106. dataset: 'spansMetrics',
  107. environment: [],
  108. excludeOther: 0,
  109. field: [],
  110. interval: '30m',
  111. orderby: undefined,
  112. partial: 1,
  113. per_page: 50,
  114. project: [],
  115. query: 'span.module:http has:span.domain',
  116. referrer: 'api.starfish.http-module-landing-duration-chart',
  117. statsPeriod: '10d',
  118. topEvents: undefined,
  119. yAxis: 'avg(span.self_time)',
  120. },
  121. })
  122. );
  123. expect(spanListRequestMock).toHaveBeenCalledWith(
  124. `/organizations/${organization.slug}/events/`,
  125. expect.objectContaining({
  126. method: 'GET',
  127. query: {
  128. dataset: 'spansMetrics',
  129. environment: [],
  130. field: [
  131. 'project.id',
  132. 'span.domain',
  133. 'spm()',
  134. 'avg(span.self_time)',
  135. 'sum(span.self_time)',
  136. 'time_spent_percentage()',
  137. ],
  138. per_page: 10,
  139. project: [],
  140. query: 'span.module:http has:span.domain',
  141. referrer: 'api.starfish.http-module-domains-list',
  142. sort: '-time_spent_percentage()',
  143. statsPeriod: '10d',
  144. },
  145. })
  146. );
  147. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  148. });
  149. it('renders a list of domains', async function () {
  150. render(<HTTPLandingPage />);
  151. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  152. expect(screen.getByRole('cell', {name: '*.sentry.io'})).toBeInTheDocument();
  153. expect(screen.getByRole('cell', {name: '*.github.com'})).toBeInTheDocument();
  154. });
  155. });