-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test(auth)]: Add unit tests for useSignInUpForm hook (#9648)
Introduce unit tests to validate the behavior of the useSignInUpForm hook. Tests cover default initialization, handling of developer defaults, and prefilled values based on state.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
packages/twenty-front/src/modules/auth/sign-in-up/hooks/__tests__/useSignInUpForm.test.tsx
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,68 @@ | ||
import { RecoilRoot, useSetRecoilState } from 'recoil'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useSignInUpForm } from '@/auth/sign-in-up/hooks/useSignInUpForm'; | ||
import { ReactNode } from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { isDeveloperDefaultSignInPrefilledState } from '@/client-config/states/isDeveloperDefaultSignInPrefilledState'; | ||
|
||
describe('useSignInUpForm', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should initialize the form with default values', async () => { | ||
const { result } = renderHook(() => useSignInUpForm(), { | ||
wrapper: ({ children }: { children: ReactNode }) => ( | ||
<MemoryRouter> | ||
<RecoilRoot>{children}</RecoilRoot> | ||
</MemoryRouter> | ||
), | ||
}); | ||
expect(result.current.form).toBeDefined(); | ||
}); | ||
|
||
it('should not prefill sign-in developer defaults when state is false', () => { | ||
const { result } = renderHook(() => useSignInUpForm(), { | ||
wrapper: ({ children }: { children: ReactNode }) => ( | ||
<MemoryRouter initialEntries={['[email protected]']}> | ||
<RecoilRoot>{children}</RecoilRoot> | ||
</MemoryRouter> | ||
), | ||
}); | ||
|
||
expect(result.current.form.getValues()).toEqual({ | ||
exist: false, | ||
email: '[email protected]', | ||
password: '', | ||
captchaToken: '', | ||
}); | ||
}); | ||
|
||
it('should prefill developer defaults when the state is true', () => { | ||
const { result } = renderHook( | ||
() => { | ||
const setIsDeveloperDefaultSignInPrefilledState = useSetRecoilState( | ||
isDeveloperDefaultSignInPrefilledState, | ||
); | ||
|
||
setIsDeveloperDefaultSignInPrefilledState(true); | ||
|
||
return useSignInUpForm(); | ||
}, | ||
{ | ||
wrapper: ({ children }: { children: ReactNode }) => ( | ||
<MemoryRouter initialEntries={['[email protected]']}> | ||
<RecoilRoot>{children}</RecoilRoot> | ||
</MemoryRouter> | ||
), | ||
}, | ||
); | ||
|
||
expect(result.current.form.getValues()).toEqual({ | ||
exist: false, | ||
email: '[email protected]', | ||
password: 'Applecar2025', | ||
captchaToken: '', | ||
}); | ||
}); | ||
}); |