Skip to content

Commit

Permalink
PWA-3233 : fixed test case coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rudraswamy.c authored and rudraswamy.c committed Feb 22, 2024
1 parent 62f2fb8 commit 3e779a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
17 changes: 16 additions & 1 deletion packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jest.mock('../../../context/user', () => ({
jest.mock('../../../hooks/useGoogleReCaptcha', () => ({
useGoogleReCaptcha: jest.fn().mockReturnValue({
recaptchaLoading: false,
generateReCaptchaData: jest.fn(() => {}),
generateReCaptchaData: jest.fn(() => { }),
recaptchaWidgetProps: {}
})
}));
Expand Down Expand Up @@ -227,3 +227,18 @@ test('mutation error is returned by talon', async () => {
`[Error: Uh oh! There was an error signing in :(]`
);
});

it('should call handleForgotPassword when Enter key is pressed', () => {
const { result } = renderHookWithProviders();
const { forgotPasswordHandleEnterKeyPress } = result.current;
const enterKeyEvent = { key: "Enter" };
renderHook(() => forgotPasswordHandleEnterKeyPress(enterKeyEvent));
});

it('should call handleEnterKeyPress when Enter key is pressed', () => {
const { result } = renderHookWithProviders();
const { handleEnterKeyPress } = result.current;
const enterKeyEvent = { key: "Enter" };
renderHook(() => handleEnterKeyPress(enterKeyEvent));
});

35 changes: 16 additions & 19 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,11 @@ export const useSignIn = props => {
showForgotPassword();
}, [setDefaultUsername, showForgotPassword]);

const forgotPasswordHandleEnterKeyPress = useCallback(() => {
event => {
if (event.key === 'Enter') {
handleForgotPassword();
}
};
const forgotPasswordHandleEnterKeyPress = useCallback((event) => {

if (event.key === 'Enter') {
handleForgotPassword();
}
}, [handleForgotPassword]);

const handleCreateAccount = useCallback(() => {
Expand All @@ -180,20 +179,18 @@ export const useSignIn = props => {
showCreateAccount();
}, [setDefaultUsername, showCreateAccount]);

const handleEnterKeyPress = useCallback(() => {
event => {
if (event.key === 'Enter') {
handleCreateAccount();
}
};
const handleEnterKeyPress = useCallback((event) => {

if (event.key === 'Enter') {
handleCreateAccount();
}
}, [handleCreateAccount]);

const signinHandleEnterKeyPress = useCallback(() => {
event => {
if (event.key === 'Enter') {
handleSubmit();
}
};
const signinHandleEnterKeyPress = useCallback((event) => {

if (event.key === 'Enter') {
handleSubmit();
}
}, [handleSubmit]);

const errors = useMemo(
Expand All @@ -217,4 +214,4 @@ export const useSignIn = props => {
setFormApi,
recaptchaWidgetProps
};
};
};

0 comments on commit 3e779a3

Please sign in to comment.