databaseLandingPage.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import {Organization} 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 {DatabaseLandingPage} from 'sentry/views/performance/database/databaseLandingPage';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('DatabaseLandingPage', function () {
  11. const organization = Organization();
  12. let spanListRequestMock;
  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. beforeAll(function () {
  40. MockApiClient.addMockResponse({
  41. url: '/organizations/org-slug/sdk-updates/',
  42. body: [],
  43. });
  44. MockApiClient.addMockResponse({
  45. url: `/organizations/${organization.slug}/events/`,
  46. method: 'GET',
  47. match: [MockApiClient.matchQuery({referrer: 'span-metrics'})],
  48. body: {
  49. data: [],
  50. },
  51. });
  52. MockApiClient.addMockResponse({
  53. url: `/organizations/${organization.slug}/events/`,
  54. method: 'GET',
  55. match: [MockApiClient.matchQuery({referrer: 'api.starfish.get-span-actions'})],
  56. body: {
  57. data: [{'span.action': 'SELECT', count: 1}],
  58. },
  59. });
  60. MockApiClient.addMockResponse({
  61. url: `/organizations/${organization.slug}/events/`,
  62. method: 'GET',
  63. match: [MockApiClient.matchQuery({referrer: 'api.starfish.get-span-domains'})],
  64. body: {
  65. data: [{'span.domain': ['sentry_users'], count: 1}],
  66. },
  67. });
  68. spanListRequestMock = MockApiClient.addMockResponse({
  69. url: `/organizations/${organization.slug}/events/`,
  70. method: 'GET',
  71. match: [MockApiClient.matchQuery({referrer: 'api.starfish.use-span-list'})],
  72. body: {
  73. data: [
  74. {
  75. 'span.group': '271536360c0b6f89',
  76. 'span.description': 'SELECT * FROM users',
  77. },
  78. {
  79. 'span.group': '360c0b6f89271536',
  80. 'span.description': 'SELECT * FROM organizations',
  81. },
  82. ],
  83. },
  84. });
  85. MockApiClient.addMockResponse({
  86. url: `/organizations/${organization.slug}/events-stats/`,
  87. method: 'GET',
  88. body: {
  89. 'spm()': {
  90. data: [
  91. [1699907700, [{count: 7810.2}]],
  92. [1699908000, [{count: 1216.8}]],
  93. ],
  94. },
  95. },
  96. });
  97. });
  98. afterAll(function () {
  99. jest.resetAllMocks();
  100. });
  101. it('renders a list of queries', async function () {
  102. // eslint-disable-next-line no-console
  103. jest.spyOn(console, 'error').mockImplementation(jest.fn()); // This silences pointless unique key errors that React throws because of the tokenized query descriptions
  104. render(<DatabaseLandingPage />);
  105. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  106. expect(spanListRequestMock).toHaveBeenCalledWith(
  107. `/organizations/${organization.slug}/events/`,
  108. expect.objectContaining({
  109. method: 'GET',
  110. query: {
  111. dataset: 'spansMetrics',
  112. environment: [],
  113. field: [
  114. 'project.id',
  115. 'span.group',
  116. 'span.description',
  117. 'spm()',
  118. 'avg(span.self_time)',
  119. 'sum(span.self_time)',
  120. 'time_spent_percentage()',
  121. ],
  122. per_page: 25,
  123. project: [],
  124. query: 'span.module:db has:span.description',
  125. referrer: 'api.starfish.use-span-list',
  126. sort: '-time_spent_percentage()',
  127. statsPeriod: '10d',
  128. },
  129. })
  130. );
  131. expect(screen.getByRole('cell', {name: 'SELECT * FROM users'})).toBeInTheDocument();
  132. expect(
  133. screen.getByRole('cell', {name: 'SELECT * FROM organizations'})
  134. ).toBeInTheDocument();
  135. });
  136. });