-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5509 remove flash on intermediate verify step when sign in with sso (#…
…5526) - remove flash on /verify - remove flash on signInUp - remove useless redirections and hooks - Remove DefaultHomePage component - Move redirections to /objects/companies in PageChangeEffect - add useShowAuthModal hooks and tests - add usePageChangeEffectNaviteLocation hooks and tests - fix refresh token expired produces blank screen
- Loading branch information
Showing
26 changed files
with
976 additions
and
418 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
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
72 changes: 72 additions & 0 deletions
72
packages/twenty-front/src/hooks/__tests__/useDefaultHomePagePath.test.ts
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,72 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { RecoilRoot, useSetRecoilState } from 'recoil'; | ||
|
||
import { currentUserState } from '@/auth/states/currentUserState'; | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock'; | ||
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData'; | ||
import { AppPath } from '@/types/AppPath'; | ||
import { useDefaultHomePagePath } from '~/hooks/useDefaultHomePagePath'; | ||
import { mockedUsersData } from '~/testing/mock-data/users'; | ||
|
||
const objectMetadataItem = getObjectMetadataItemsMock()[0]; | ||
jest.mock('@/object-metadata/hooks/useObjectMetadataItem'); | ||
jest.mocked(useObjectMetadataItem).mockReturnValue({ | ||
objectMetadataItem, | ||
}); | ||
|
||
jest.mock('@/prefetch/hooks/usePrefetchedData'); | ||
const setupMockPrefetchedData = (viewId?: string) => { | ||
jest.mocked(usePrefetchedData).mockReturnValue({ | ||
isDataPrefetched: true, | ||
records: viewId | ||
? [ | ||
{ | ||
id: viewId, | ||
__typename: 'object', | ||
objectMetadataId: objectMetadataItem.id, | ||
}, | ||
] | ||
: [], | ||
}); | ||
}; | ||
|
||
const renderHooks = (withCurrentUser: boolean) => { | ||
const { result } = renderHook( | ||
() => { | ||
const setCurrentUser = useSetRecoilState(currentUserState); | ||
if (withCurrentUser) { | ||
setCurrentUser(mockedUsersData[0]); | ||
} | ||
return useDefaultHomePagePath(); | ||
}, | ||
{ | ||
wrapper: RecoilRoot, | ||
}, | ||
); | ||
return { result }; | ||
}; | ||
describe('useDefaultHomePagePath', () => { | ||
it('should return proper path when no currentUser', () => { | ||
setupMockPrefetchedData(); | ||
const { result } = renderHooks(false); | ||
expect(result.current.defaultHomePagePath).toEqual(AppPath.SignInUp); | ||
}); | ||
it('should return proper path when no currentUser and existing view', () => { | ||
setupMockPrefetchedData('viewId'); | ||
const { result } = renderHooks(false); | ||
expect(result.current.defaultHomePagePath).toEqual(AppPath.SignInUp); | ||
}); | ||
it('should return proper path when currentUser is defined', () => { | ||
setupMockPrefetchedData(); | ||
const { result } = renderHooks(true); | ||
expect(result.current.defaultHomePagePath).toEqual('/objects/companies'); | ||
}); | ||
it('should return proper path when currentUser is defined and view exists', () => { | ||
setupMockPrefetchedData('viewId'); | ||
const { result } = renderHooks(true); | ||
expect(result.current.defaultHomePagePath).toEqual( | ||
'/objects/companies?view=viewId', | ||
); | ||
}); | ||
}); |
Oops, something went wrong.