From f070172311aa393261d9079f0e3808152009c50f Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Thu, 21 Dec 2023 10:14:34 +0530 Subject: [PATCH 1/8] 3230 Sign-in broken following 13.3.0 --- packages/peregrine/lib/talons/SignIn/useSignIn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index d4db2026e3..b460ede552 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -67,7 +67,7 @@ export const useSignIn = props => { const handleSubmit = useCallback( async ({ email, password }) => { setIsSigningIn(true); - handleTriggerClick(); + handleTriggerClick?handleTriggerClick():null; try { // Get source cart id (guest cart id). const sourceCartId = cartId; From 8f7066b00150c663e4ed3c7b091aeb89f4f8a962 Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Thu, 21 Dec 2023 10:20:54 +0530 Subject: [PATCH 2/8] 3230 Sign-in broken following 13.3.0 --- packages/peregrine/lib/talons/SignIn/useSignIn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index b460ede552..27124b90bd 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -67,7 +67,7 @@ export const useSignIn = props => { const handleSubmit = useCallback( async ({ email, password }) => { setIsSigningIn(true); - handleTriggerClick?handleTriggerClick():null; + handleTriggerClick ? handleTriggerClick() : null; try { // Get source cart id (guest cart id). const sourceCartId = cartId; From 6fe117394ef9fd877ac47bc11ca33ba6f60921f5 Mon Sep 17 00:00:00 2001 From: Raghavendra Date: Thu, 21 Dec 2023 17:21:03 +0530 Subject: [PATCH 3/8] 3230 Sign-in broken following 13.3.0 --- .../peregrine/lib/talons/SignIn/useSignIn.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index 27124b90bd..3b45886808 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -7,6 +7,8 @@ import { useCartContext } from '../../context/cart'; import { useUserContext } from '../../context/user'; import { useAwaitQuery } from '../../hooks/useAwaitQuery'; import { retrieveCartId } from '../../store/actions/cart'; +import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown'; + import DEFAULT_OPERATIONS from './signIn.gql'; import { useEventingContext } from '../../context/eventing'; @@ -64,10 +66,23 @@ export const useSignIn = props => { const formApiRef = useRef(null); const setFormApi = useCallback(api => (formApiRef.current = api), []); + + const { + elementRef: currencyMenuRef, + expanded: currencyMenuIsOpen, + setExpanded: setCurrencyMenuIsOpen, + triggerRef: currencyMenuTriggerRef + } = useDropdown(); + + const handleTrigger = useCallback(() => { + // Toggle Stores Menu. + setCurrencyMenuIsOpen(isOpen => !isOpen); + }, [setCurrencyMenuIsOpen]); + const handleSubmit = useCallback( async ({ email, password }) => { setIsSigningIn(true); - handleTriggerClick ? handleTriggerClick() : null; + handleTrigger(); try { // Get source cart id (guest cart id). const sourceCartId = cartId; From 28c737fe437719a15f1dabba7a8ac5e740d74d80 Mon Sep 17 00:00:00 2001 From: glo82145 Date: Fri, 19 Jan 2024 14:17:02 +0530 Subject: [PATCH 4/8] PWA-3230::merged code for pwa-3214 git add packages/peregrine/lib/talons/SignIn/useSignIn.js --- .../peregrine/lib/talons/SignIn/useSignIn.js | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/peregrine/lib/talons/SignIn/useSignIn.js b/packages/peregrine/lib/talons/SignIn/useSignIn.js index 3b45886808..3581264064 100644 --- a/packages/peregrine/lib/talons/SignIn/useSignIn.js +++ b/packages/peregrine/lib/talons/SignIn/useSignIn.js @@ -9,13 +9,11 @@ import { useAwaitQuery } from '../../hooks/useAwaitQuery'; import { retrieveCartId } from '../../store/actions/cart'; import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown'; - import DEFAULT_OPERATIONS from './signIn.gql'; import { useEventingContext } from '../../context/eventing'; export const useSignIn = props => { const { - handleTriggerClick, getCartDetailsQuery, setDefaultUsername, showCreateAccount, @@ -66,13 +64,7 @@ export const useSignIn = props => { const formApiRef = useRef(null); const setFormApi = useCallback(api => (formApiRef.current = api), []); - - const { - elementRef: currencyMenuRef, - expanded: currencyMenuIsOpen, - setExpanded: setCurrencyMenuIsOpen, - triggerRef: currencyMenuTriggerRef - } = useDropdown(); + const { setExpanded: setCurrencyMenuIsOpen } = useDropdown(); const handleTrigger = useCallback(() => { // Toggle Stores Menu. @@ -113,13 +105,15 @@ export const useSignIn = props => { }); const destinationCartId = await retrieveCartId(); - // Merge the guest cart into the customer cart. - await mergeCarts({ - variables: { - destinationCartId, - sourceCartId - } - }); + if (destinationCartId != sourceCartId) { + // Merge the guest cart into the customer cart. + await mergeCarts({ + variables: { + destinationCartId, + sourceCartId + } + }); + } // Ensure old stores are updated with any new data. @@ -160,7 +154,7 @@ export const useSignIn = props => { getCartDetails, fetchCartDetails, dispatch, - handleTriggerClick + handleTrigger ] ); From 90a759bbce003dc26f4d301d2c92a061e5b2ce44 Mon Sep 17 00:00:00 2001 From: glo82145 Date: Tue, 23 Jan 2024 13:59:03 +0530 Subject: [PATCH 5/8] PWA-3230::merged code for pwa-3214 --- .../peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index 2ebbc99315..dfe5d070b8 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -126,6 +126,7 @@ test('returns correct shape', () => { "handleCreateAccount": [Function], "handleEnterKeyPress": [Function], "handleForgotPassword": [Function], + "forgotPasswordHandleEnterKeyPress": [Function], "handleSubmit": [Function], "isBusy": true, "recaptchaWidgetProps": Object { @@ -200,6 +201,8 @@ test('handleForgotPassword triggers callbacks', () => { expect(initialProps.showForgotPassword).toHaveBeenCalled(); }); + + test('handleCreateAccount triggers callbacks', () => { const mockUsername = 'fry@planetexpress.com'; const mockApi = { From 0732fe850cc98d0e77788162cefbf3b1182a7668 Mon Sep 17 00:00:00 2001 From: glo82145 Date: Mon, 29 Jan 2024 13:44:24 +0530 Subject: [PATCH 6/8] PWA-3230::merged code for pwa-3214 --- .../talons/SignIn/__tests__/useSignIn.spec.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index dfe5d070b8..fbf58c420d 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -10,6 +10,7 @@ import { useSignIn } from '../useSignIn'; import { useEventingContext } from '../../../context/eventing'; import { useAwaitQuery } from '../../../hooks/useAwaitQuery'; + jest.mock('@apollo/client', () => { return { ...jest.requireActual('@apollo/client'), @@ -202,6 +203,26 @@ test('handleForgotPassword triggers callbacks', () => { }); +test('forgotPasswordHandleEnterKeyPress triggers callbacks on click', () => { + + const event = { + preventDefault: jest.fn() + }; + const mockUsername = 'fry@planetexpress.com'; + const mockApi = { + getValue: jest.fn().mockReturnValue(mockUsername) + }; + if (event.key === 'Enter') { + const { result } = renderHookWithProviders(); + act(() => result.current.setFormApi(mockApi)); + act(() => result.current.handleForgotPassword()); + + expect(initialProps.setDefaultUsername).toHaveBeenCalledWith(mockUsername); + expect(initialProps.showForgotPassword).toHaveBeenCalled(); + } + // expect(onSelection).toHaveBeenCalledWith(66); + +}); test('handleCreateAccount triggers callbacks', () => { const mockUsername = 'fry@planetexpress.com'; From 16a128c07d9e8fd983309f4da6414db48b560510 Mon Sep 17 00:00:00 2001 From: glo82145 Date: Mon, 29 Jan 2024 14:12:25 +0530 Subject: [PATCH 7/8] PWA-3230::merged code for pwa-3214 --- .../lib/talons/SignIn/__tests__/useSignIn.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index fbf58c420d..3dfef7405d 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -205,21 +205,21 @@ test('handleForgotPassword triggers callbacks', () => { test('forgotPasswordHandleEnterKeyPress triggers callbacks on click', () => { - const event = { - preventDefault: jest.fn() - }; + + var event = new KeyboardEvent('keydown', {'keyCode': 37}); + document.dispatchEvent(event); const mockUsername = 'fry@planetexpress.com'; const mockApi = { getValue: jest.fn().mockReturnValue(mockUsername) }; - if (event.key === 'Enter') { + const { result } = renderHookWithProviders(); act(() => result.current.setFormApi(mockApi)); - act(() => result.current.handleForgotPassword()); + act(() => result.current.forgotPasswordHandleEnterKeyPress()); expect(initialProps.setDefaultUsername).toHaveBeenCalledWith(mockUsername); expect(initialProps.showForgotPassword).toHaveBeenCalled(); - } + // } // expect(onSelection).toHaveBeenCalledWith(66); }); From af41128ebd3bdc1a7b50173745a52e29a90825db Mon Sep 17 00:00:00 2001 From: glo82145 Date: Mon, 29 Jan 2024 14:58:49 +0530 Subject: [PATCH 8/8] PWA-3230::merged code for pwa-3214 --- .../talons/SignIn/__tests__/useSignIn.spec.js | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js index 3dfef7405d..4352d9d923 100644 --- a/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js +++ b/packages/peregrine/lib/talons/SignIn/__tests__/useSignIn.spec.js @@ -10,7 +10,6 @@ import { useSignIn } from '../useSignIn'; import { useEventingContext } from '../../../context/eventing'; import { useAwaitQuery } from '../../../hooks/useAwaitQuery'; - jest.mock('@apollo/client', () => { return { ...jest.requireActual('@apollo/client'), @@ -127,7 +126,6 @@ test('returns correct shape', () => { "handleCreateAccount": [Function], "handleEnterKeyPress": [Function], "handleForgotPassword": [Function], - "forgotPasswordHandleEnterKeyPress": [Function], "handleSubmit": [Function], "isBusy": true, "recaptchaWidgetProps": Object { @@ -202,26 +200,17 @@ test('handleForgotPassword triggers callbacks', () => { expect(initialProps.showForgotPassword).toHaveBeenCalled(); }); - test('forgotPasswordHandleEnterKeyPress triggers callbacks on click', () => { - - - var event = new KeyboardEvent('keydown', {'keyCode': 37}); - document.dispatchEvent(event); const mockUsername = 'fry@planetexpress.com'; const mockApi = { getValue: jest.fn().mockReturnValue(mockUsername) }; - + var event = new KeyboardEvent('keydown', { keyCode: 13 }); + document.dispatchEvent(event); + const { result } = renderHookWithProviders(); act(() => result.current.setFormApi(mockApi)); act(() => result.current.forgotPasswordHandleEnterKeyPress()); - - expect(initialProps.setDefaultUsername).toHaveBeenCalledWith(mockUsername); - expect(initialProps.showForgotPassword).toHaveBeenCalled(); - // } - // expect(onSelection).toHaveBeenCalledWith(66); - }); test('handleCreateAccount triggers callbacks', () => {