Skip to content

Commit

Permalink
test(insights): add useDomainViewFilters tests (#80419)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikB2014 authored Nov 8, 2024
1 parent fe43a92 commit edd7df3
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions static/app/views/insights/pages/useFilters.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {LocationFixture} from 'sentry-fixture/locationFixture';
import {OrganizationFixture} from 'sentry-fixture/organization';

import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {BACKEND_LANDING_SUB_PATH} from 'sentry/views/insights/pages/backend/settings';
import {FRONTEND_LANDING_SUB_PATH} from 'sentry/views/insights/pages/frontend/settings';
import {DOMAIN_VIEW_BASE_URL} from 'sentry/views/insights/pages/settings';
import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';

jest.mock('sentry/utils/useLocation');
jest.mock('sentry/utils/useOrganization');

const mockUseLocation = jest.mocked(useLocation);
const mockUseOrganization = jest.mocked(useOrganization);

const frontendBasePath = `/${DOMAIN_VIEW_BASE_URL}/${FRONTEND_LANDING_SUB_PATH}`;
const backendBasePath = `/${DOMAIN_VIEW_BASE_URL}/${BACKEND_LANDING_SUB_PATH}`;

describe('useDomainViewFilters', () => {
beforeEach(() => {
jest.resetAllMocks();
mockUseLocation.mockReturnValue(
LocationFixture({pathname: `/${DOMAIN_VIEW_BASE_URL}/${FRONTEND_LANDING_SUB_PATH}`})
);
mockUseOrganization.mockReturnValue(
OrganizationFixture({features: ['insights-domain-view']})
);
});

it('should return isInDomainView as false without feature', function () {
mockUseOrganization.mockReturnValue(OrganizationFixture());
const {isInDomainView, view} = useDomainViewFilters();
expect(isInDomainView).toBe(false);
expect(view).toBeUndefined();
});

it('should return correct domain view based on the url', function () {
mockUseLocation.mockReturnValue(LocationFixture({pathname: frontendBasePath}));
const {isInDomainView, view} = useDomainViewFilters();
expect(isInDomainView).toBe(true);
expect(view).toBe(FRONTEND_LANDING_SUB_PATH);
});

it('should return correct domain view if in nested url', function () {
mockUseLocation.mockReturnValue(
LocationFixture({pathname: `${backendBasePath}/http/`})
);
const {isInDomainView, view} = useDomainViewFilters();
expect(isInDomainView).toBe(true);
expect(view).toBe(BACKEND_LANDING_SUB_PATH);
});

it('should not return isInDomainView if not in domain view', function () {
mockUseLocation.mockReturnValue(LocationFixture({pathname: '/performance/'}));
const {isInDomainView, view} = useDomainViewFilters();
expect(isInDomainView).toBe(false);
expect(view).toBeUndefined();
});
});

0 comments on commit edd7df3

Please sign in to comment.