httpSamplesPanel.spec.tsx 5.2 KB

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