databaseLandingPage.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. jest.mocked(usePageFilters).mockReturnValue({
  13. isReady: true,
  14. desyncedFilters: new Set(),
  15. pinnedFilters: new Set(),
  16. shouldPersist: true,
  17. selection: {
  18. datetime: {
  19. period: '10d',
  20. start: null,
  21. end: null,
  22. utc: false,
  23. },
  24. environments: [],
  25. projects: [],
  26. },
  27. });
  28. jest.mocked(useLocation).mockReturnValue({
  29. pathname: '',
  30. search: '',
  31. query: {statsPeriod: '10d'},
  32. hash: '',
  33. state: undefined,
  34. action: 'PUSH',
  35. key: '',
  36. });
  37. jest.mocked(useOrganization).mockReturnValue(organization);
  38. beforeAll(function () {
  39. MockApiClient.addMockResponse({
  40. url: '/organizations/org-slug/sdk-updates/',
  41. body: [],
  42. });
  43. MockApiClient.addMockResponse({
  44. url: `/organizations/${organization.slug}/events/`,
  45. method: 'GET',
  46. match: [MockApiClient.matchQuery({referrer: 'span-metrics'})],
  47. body: {
  48. data: [],
  49. },
  50. });
  51. MockApiClient.addMockResponse({
  52. url: `/organizations/${organization.slug}/events/`,
  53. method: 'GET',
  54. match: [MockApiClient.matchQuery({referrer: 'api.starfish.get-span-actions'})],
  55. body: {
  56. data: [{'span.action': 'SELECT', count: 1}],
  57. },
  58. });
  59. MockApiClient.addMockResponse({
  60. url: `/organizations/${organization.slug}/events/`,
  61. method: 'GET',
  62. match: [MockApiClient.matchQuery({referrer: 'api.starfish.get-span-domains'})],
  63. body: {
  64. data: [{'span.domain': ['sentry_users'], count: 1}],
  65. },
  66. });
  67. MockApiClient.addMockResponse({
  68. url: `/organizations/${organization.slug}/events/`,
  69. method: 'GET',
  70. match: [MockApiClient.matchQuery({referrer: 'api.starfish.use-span-list'})],
  71. body: {
  72. data: [
  73. {
  74. 'span.group': '271536360c0b6f89',
  75. 'span.description': 'SELECT * FROM users',
  76. },
  77. {
  78. 'span.group': '360c0b6f89271536',
  79. 'span.description': 'SELECT * FROM organizations',
  80. },
  81. ],
  82. },
  83. });
  84. MockApiClient.addMockResponse({
  85. url: `/organizations/${organization.slug}/events-stats/`,
  86. method: 'GET',
  87. body: {
  88. 'spm()': {
  89. data: [
  90. [1699907700, [{count: 7810.2}]],
  91. [1699908000, [{count: 1216.8}]],
  92. ],
  93. },
  94. },
  95. });
  96. });
  97. afterAll(function () {
  98. jest.resetAllMocks();
  99. });
  100. it('renders a list of queries', async function () {
  101. // eslint-disable-next-line no-console
  102. jest.spyOn(console, 'error').mockImplementation(jest.fn()); // This silences pointless unique key errors that React throws because of the tokenized query descriptions
  103. render(<DatabaseLandingPage />);
  104. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  105. expect(screen.getByRole('cell', {name: 'SELECT * FROM users'})).toBeInTheDocument();
  106. expect(
  107. screen.getByRole('cell', {name: 'SELECT * FROM organizations'})
  108. ).toBeInTheDocument();
  109. });
  110. });