-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(insights): add useDomainViewFilters tests (#80419)
- Loading branch information
1 parent
fe43a92
commit edd7df3
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |