123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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(<DatabaseLandingPage />);
- await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
- expect(screen.getByRole('cell', {name: 'SELECT * FROM users'})).toBeInTheDocument();
- expect(
- screen.getByRole('cell', {name: 'SELECT * FROM organizations'})
- ).toBeInTheDocument();
- });
- });
|