httpSamplesPanel.spec.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  84. });
  85. it('show basic transaction info', async function () {
  86. MockApiClient.addMockResponse({
  87. url: `/organizations/${organization.slug}/events/`,
  88. method: 'GET',
  89. match: [
  90. MockApiClient.matchQuery({
  91. referrer: 'api.starfish.http-module-samples-panel-metrics-ribbon',
  92. }),
  93. ],
  94. body: {
  95. data: [
  96. {
  97. 'spm()': 22.18,
  98. 'http_response_rate(3)': 0.01,
  99. 'http_response_rate(4)': 0.025,
  100. 'http_response_rate(5)': 0.015,
  101. 'avg(span.self_time)': 140.2,
  102. 'sum(span.self_time)': 2709238,
  103. },
  104. ],
  105. meta: {
  106. fields: {
  107. 'spm()': 'rate',
  108. 'avg(span.self_time)': 'duration',
  109. 'http_response_rate(2)': 'percentage',
  110. 'http_response_rate(4)': 'percentage',
  111. 'http_response_rate(5)': 'percentage',
  112. 'sum(span.self_time)': 'duration',
  113. },
  114. },
  115. },
  116. });
  117. render(<HTTPSamplesPanel />);
  118. // Panel heading
  119. expect(screen.getByRole('heading', {name: 'GET /api/0/users'})).toBeInTheDocument();
  120. // Metrics ribbon
  121. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  122. expect(
  123. screen.getByRole('heading', {name: 'Requests Per Minute'})
  124. ).toBeInTheDocument();
  125. expect(screen.getByRole('heading', {name: 'Avg Duration'})).toBeInTheDocument();
  126. expect(screen.getByRole('heading', {name: '3XXs'})).toBeInTheDocument();
  127. expect(screen.getByRole('heading', {name: '4XXs'})).toBeInTheDocument();
  128. expect(screen.getByRole('heading', {name: '5XXs'})).toBeInTheDocument();
  129. expect(screen.getByRole('heading', {name: 'Time Spent'})).toBeInTheDocument();
  130. expect(screen.getByText('22.2/min')).toBeInTheDocument();
  131. expect(screen.getByText('140.20ms')).toBeInTheDocument();
  132. expect(screen.getByText('1%')).toBeInTheDocument();
  133. expect(screen.getByText('2.5%')).toBeInTheDocument();
  134. expect(screen.getByText('1.5%')).toBeInTheDocument();
  135. expect(screen.getByText('45.15min')).toBeInTheDocument();
  136. });
  137. });