httpSamplesPanel.spec.tsx 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 {HTTPSamplesPanel} from 'sentry/views/performance/http/httpSamplesPanel';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('HTTPSamplesPanel', function () {
  11. const organization = OrganizationFixture();
  12. let eventsRequestMock;
  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: {
  33. domain: '*.sentry.dev',
  34. statsPeriod: '10d',
  35. transaction: '/api/0/users',
  36. transactionMethod: 'GET',
  37. panel: 'status',
  38. },
  39. hash: '',
  40. state: undefined,
  41. action: 'PUSH',
  42. key: '',
  43. });
  44. jest.mocked(useOrganization).mockReturnValue(organization);
  45. beforeEach(function () {
  46. eventsRequestMock = MockApiClient.addMockResponse({
  47. url: `/organizations/${organization.slug}/events/`,
  48. method: 'GET',
  49. body: {
  50. data: [],
  51. },
  52. });
  53. });
  54. afterAll(function () {
  55. jest.resetAllMocks();
  56. });
  57. it('fetches panel data', async function () {
  58. render(<HTTPSamplesPanel />);
  59. expect(eventsRequestMock).toHaveBeenNthCalledWith(
  60. 1,
  61. `/organizations/${organization.slug}/events/`,
  62. expect.objectContaining({
  63. method: 'GET',
  64. query: {
  65. dataset: 'spansMetrics',
  66. environment: [],
  67. field: [
  68. 'spm()',
  69. 'avg(span.self_time)',
  70. 'sum(span.self_time)',
  71. 'http_response_rate(3)',
  72. 'http_response_rate(4)',
  73. 'http_response_rate(5)',
  74. 'time_spent_percentage()',
  75. ],
  76. per_page: 50,
  77. project: [],
  78. query: 'span.module:http span.domain:"\\*.sentry.dev" transaction:/api/0/users',
  79. referrer: 'api.starfish.http-module-samples-panel-metrics-ribbon',
  80. statsPeriod: '10d',
  81. },
  82. })
  83. );
  84. expect(eventsRequestMock).toHaveBeenNthCalledWith(
  85. 2,
  86. `/organizations/${organization.slug}/events/`,
  87. expect.objectContaining({
  88. method: 'GET',
  89. query: {
  90. dataset: 'spansMetrics',
  91. environment: [],
  92. field: ['span.status_code', 'count()'],
  93. per_page: 50,
  94. sort: 'span.status_code',
  95. project: [],
  96. query: 'span.module:http span.domain:"\\*.sentry.dev" transaction:/api/0/users',
  97. referrer: 'api.starfish.http-module-samples-panel-response-bar-chart',
  98. statsPeriod: '10d',
  99. },
  100. })
  101. );
  102. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  103. });
  104. it('show basic transaction info', async function () {
  105. MockApiClient.addMockResponse({
  106. url: `/organizations/${organization.slug}/events/`,
  107. method: 'GET',
  108. match: [
  109. MockApiClient.matchQuery({
  110. referrer: 'api.starfish.http-module-samples-panel-metrics-ribbon',
  111. }),
  112. ],
  113. body: {
  114. data: [
  115. {
  116. 'project.id': 1,
  117. 'spm()': 22.18,
  118. 'http_response_rate(3)': 0.01,
  119. 'http_response_rate(4)': 0.025,
  120. 'http_response_rate(5)': 0.015,
  121. 'avg(span.self_time)': 140.2,
  122. 'sum(span.self_time)': 2709238,
  123. },
  124. ],
  125. meta: {
  126. fields: {
  127. 'spm()': 'rate',
  128. 'avg(span.self_time)': 'duration',
  129. 'http_response_rate(3)': 'percentage',
  130. 'http_response_rate(4)': 'percentage',
  131. 'http_response_rate(5)': 'percentage',
  132. 'sum(span.self_time)': 'duration',
  133. },
  134. },
  135. },
  136. });
  137. render(<HTTPSamplesPanel />);
  138. // Panel heading
  139. expect(screen.getByRole('heading', {name: 'GET /api/0/users'})).toBeInTheDocument();
  140. // Metrics ribbon
  141. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  142. expect(
  143. screen.getByRole('heading', {name: 'Requests Per Minute'})
  144. ).toBeInTheDocument();
  145. expect(screen.getByRole('heading', {name: 'Avg Duration'})).toBeInTheDocument();
  146. expect(screen.getByRole('heading', {name: '3XXs'})).toBeInTheDocument();
  147. expect(screen.getByRole('heading', {name: '4XXs'})).toBeInTheDocument();
  148. expect(screen.getByRole('heading', {name: '5XXs'})).toBeInTheDocument();
  149. expect(screen.getByRole('heading', {name: 'Time Spent'})).toBeInTheDocument();
  150. expect(screen.getByText('22.2/min')).toBeInTheDocument();
  151. expect(screen.getByText('140.20ms')).toBeInTheDocument();
  152. expect(screen.getByText('1%')).toBeInTheDocument();
  153. expect(screen.getByText('2.5%')).toBeInTheDocument();
  154. expect(screen.getByText('1.5%')).toBeInTheDocument();
  155. expect(screen.getByText('45.15min')).toBeInTheDocument();
  156. });
  157. });