Skip to content

Commit

Permalink
PWA-3233 : Unable to sign-In using TAB/ Mouse Click button from Sign … (
Browse files Browse the repository at this point in the history
#4231)

* PWA-3233 : Unable to sign-In using TAB/ Mouse Click button from Sign in Page

* PWA-3233 :fixed the preetier issues

* PWA-3233 : fixed  test case coverage

* PWA-3233 : fixed  test case coverage

* Update useSignIn.js

* replacing handleTrigger with handleTriggerClick

---------

Co-authored-by: rudraswamy.c <[email protected]>
Co-authored-by: Aanchal Pawar <[email protected]>
Co-authored-by: glo11372 <[email protected]>
  • Loading branch information
4 people authored Apr 1, 2024
1 parent d8f7e84 commit 812105a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
14 changes: 14 additions & 0 deletions packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,17 @@ 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));
});
22 changes: 13 additions & 9 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const useSignIn = props => {
async ({ email, password }) => {
setIsSigningIn(true);
handleTriggerClick();

try {
// Get source cart id (guest cart id).
const sourceCartId = cartId;
Expand Down Expand Up @@ -159,13 +160,14 @@ export const useSignIn = props => {
showForgotPassword();
}, [setDefaultUsername, showForgotPassword]);

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

const handleCreateAccount = useCallback(() => {
const { current: formApi } = formApiRef;
Expand All @@ -177,21 +179,23 @@ export const useSignIn = props => {
showCreateAccount();
}, [setDefaultUsername, showCreateAccount]);

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

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

const errors = useMemo(
() =>
Expand Down

0 comments on commit 812105a

Please sign in to comment.