httpDomainSummaryPage.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 {HTTPDomainSummaryPage} from 'sentry/views/performance/http/httpDomainSummaryPage';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('HTTPSummaryPage', function () {
  11. const organization = OrganizationFixture();
  12. let domainChartsRequestMock;
  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: {domain: '*.sentry.dev', statsPeriod: '10d'},
  33. hash: '',
  34. state: undefined,
  35. action: 'PUSH',
  36. key: '',
  37. });
  38. jest.mocked(useOrganization).mockReturnValue(organization);
  39. beforeEach(function () {
  40. MockApiClient.addMockResponse({
  41. url: `/organizations/${organization.slug}/events/`,
  42. method: 'GET',
  43. body: {
  44. data: [],
  45. },
  46. });
  47. domainChartsRequestMock = MockApiClient.addMockResponse({
  48. url: `/organizations/${organization.slug}/events-stats/`,
  49. method: 'GET',
  50. body: {
  51. 'spm()': {
  52. data: [
  53. [1699907700, [{count: 7810.2}]],
  54. [1699908000, [{count: 1216.8}]],
  55. ],
  56. },
  57. },
  58. });
  59. });
  60. afterAll(function () {
  61. jest.resetAllMocks();
  62. });
  63. it('fetches module data', async function () {
  64. render(<HTTPDomainSummaryPage />);
  65. expect(domainChartsRequestMock).toHaveBeenNthCalledWith(
  66. 1,
  67. `/organizations/${organization.slug}/events-stats/`,
  68. expect.objectContaining({
  69. method: 'GET',
  70. query: {
  71. cursor: undefined,
  72. dataset: 'spansMetrics',
  73. environment: [],
  74. excludeOther: 0,
  75. field: [],
  76. interval: '30m',
  77. orderby: undefined,
  78. partial: 1,
  79. per_page: 50,
  80. project: [],
  81. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  82. referrer: 'api.starfish.http-module-domain-summary-throughput-chart',
  83. statsPeriod: '10d',
  84. topEvents: undefined,
  85. yAxis: 'spm()',
  86. },
  87. })
  88. );
  89. expect(domainChartsRequestMock).toHaveBeenNthCalledWith(
  90. 2,
  91. `/organizations/${organization.slug}/events-stats/`,
  92. expect.objectContaining({
  93. method: 'GET',
  94. query: {
  95. cursor: undefined,
  96. dataset: 'spansMetrics',
  97. environment: [],
  98. excludeOther: 0,
  99. field: [],
  100. interval: '30m',
  101. orderby: undefined,
  102. partial: 1,
  103. per_page: 50,
  104. project: [],
  105. query: 'span.module:http span.domain:"\\*.sentry.dev"',
  106. referrer: 'api.starfish.http-module-domain-summary-duration-chart',
  107. statsPeriod: '10d',
  108. topEvents: undefined,
  109. yAxis: 'avg(span.self_time)',
  110. },
  111. })
  112. );
  113. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  114. });
  115. });