import {Organization} from 'sentry-fixture/organization'; import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary'; import {useLocation} from 'sentry/utils/useLocation'; import useOrganization from 'sentry/utils/useOrganization'; import usePageFilters from 'sentry/utils/usePageFilters'; import {DatabaseLandingPage} from 'sentry/views/performance/database/databaseLandingPage'; jest.mock('sentry/utils/useLocation'); jest.mock('sentry/utils/usePageFilters'); jest.mock('sentry/utils/useOrganization'); describe('DatabaseLandingPage', function () { const organization = Organization(); jest.mocked(usePageFilters).mockReturnValue({ isReady: true, desyncedFilters: new Set(), pinnedFilters: new Set(), shouldPersist: true, selection: { datetime: { period: '10d', start: null, end: null, utc: false, }, environments: [], projects: [], }, }); jest.mocked(useLocation).mockReturnValue({ pathname: '', search: '', query: {statsPeriod: '10d'}, hash: '', state: undefined, action: 'PUSH', key: '', }); jest.mocked(useOrganization).mockReturnValue(organization); beforeAll(function () { MockApiClient.addMockResponse({ url: '/organizations/org-slug/sdk-updates/', body: [], }); MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events/`, method: 'GET', match: [MockApiClient.matchQuery({referrer: 'span-metrics'})], body: { data: [], }, }); MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events/`, method: 'GET', match: [MockApiClient.matchQuery({referrer: 'api.starfish.get-span-actions'})], body: { data: [{'span.action': 'SELECT', count: 1}], }, }); MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events/`, method: 'GET', match: [MockApiClient.matchQuery({referrer: 'api.starfish.get-span-domains'})], body: { data: [{'span.domain': ['sentry_users'], count: 1}], }, }); MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events/`, method: 'GET', match: [MockApiClient.matchQuery({referrer: 'api.starfish.use-span-list'})], body: { data: [ { 'span.group': '271536360c0b6f89', 'span.description': 'SELECT * FROM users', }, { 'span.group': '360c0b6f89271536', 'span.description': 'SELECT * FROM organizations', }, ], }, }); MockApiClient.addMockResponse({ url: `/organizations/${organization.slug}/events-stats/`, method: 'GET', body: { 'spm()': { data: [ [1699907700, [{count: 7810.2}]], [1699908000, [{count: 1216.8}]], ], }, }, }); }); afterAll(function () { jest.resetAllMocks(); }); it('renders a list of queries', async function () { // eslint-disable-next-line no-console jest.spyOn(console, 'error').mockImplementation(jest.fn()); // This silences pointless unique key errors that React throws because of the tokenized query descriptions render(); await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator')); expect(screen.getByRole('cell', {name: 'SELECT * FROM users'})).toBeInTheDocument(); expect( screen.getByRole('cell', {name: 'SELECT * FROM organizations'}) ).toBeInTheDocument(); }); });