forked from magento/pwa-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PWA-1512]: Check if email is associated with account in guest checko…
…ut (magento#3529) * PWA-1512 Add dismissAction option to toast * PWA-1521 Add isEmailAvailable query to operations * PWA-1512 Add email verification and toast features * PWA-1512 Add translations * Hide errors from getEmailAvailable query * Use "key" prop instead of conditional rendering * Add unit tests * Update snapshots * Remove unnecessary snapshot test * Add Cypress coverage * Rollback cypress config changes * Fix failing cypress tests * Update propTypes * Add onpaste handler * Remove console.log * Fix unit tests Co-authored-by: Eric Oeur <[email protected]>
- Loading branch information
1 parent
3c2d50d
commit 06524f9
Showing
30 changed files
with
639 additions
and
31 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
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 |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import React from 'react'; | ||
import { act } from 'react-test-renderer'; | ||
import { useMutation } from '@apollo/client'; | ||
import { useLazyQuery, useMutation } from '@apollo/client'; | ||
|
||
import createTestInstance from '../../../../../util/createTestInstance'; | ||
import { useGuestForm } from '../useGuestForm'; | ||
|
||
jest.mock('@apollo/client', () => ({ | ||
useMutation: jest | ||
.fn() | ||
.mockReturnValue([jest.fn(), { called: false, loading: false }]) | ||
.mockReturnValue([jest.fn(), { called: false, loading: false }]), | ||
useLazyQuery: jest | ||
.fn() | ||
.mockReturnValue([ | ||
jest.fn(), | ||
{ data: null, called: false, loading: false, error: null } | ||
]) | ||
})); | ||
|
||
jest.mock('../../../../../context/cart', () => { | ||
|
@@ -221,3 +227,71 @@ test('should call onSuccess on mutation success', () => { | |
|
||
expect(onSuccess).toHaveBeenCalled(); | ||
}); | ||
|
||
test('handleValidateEmail calls isEmailAvailable query if email is valid', () => { | ||
const validadeEmailQuery = jest.fn(); | ||
useLazyQuery.mockReturnValueOnce([validadeEmailQuery, { data: null }]); | ||
|
||
const tree = createTestInstance( | ||
<Component mutations={{}} shippingData={shippingData} /> | ||
); | ||
|
||
const { root } = tree; | ||
const { talonProps } = root.findByType('i').props; | ||
const { handleValidateEmail } = talonProps; | ||
|
||
handleValidateEmail(); | ||
expect(validadeEmailQuery).not.toHaveBeenCalled(); | ||
handleValidateEmail('testmail.com'); | ||
expect(validadeEmailQuery).not.toHaveBeenCalled(); | ||
handleValidateEmail('[email protected]'); | ||
expect(validadeEmailQuery).toHaveBeenCalled(); | ||
}); | ||
|
||
test('sets signIn toast visible when email is not available', () => { | ||
const validadeEmailQuery = jest.fn(); | ||
useLazyQuery.mockReturnValueOnce([ | ||
validadeEmailQuery, | ||
{ | ||
data: { | ||
isEmailAvailable: { | ||
is_email_available: false | ||
} | ||
} | ||
} | ||
]); | ||
|
||
const tree = createTestInstance( | ||
<Component mutations={{}} shippingData={shippingData} /> | ||
); | ||
|
||
const { root } = tree; | ||
const { talonProps } = root.findByType('i').props; | ||
const { showSignInToast } = talonProps; | ||
|
||
expect(showSignInToast).toBe(true); | ||
}); | ||
|
||
test('handleToastAction fires up defined toast callback action', () => { | ||
const removeToast = jest.fn(); | ||
const setGuestSignInUsername = jest.fn(); | ||
const toggleSignInContent = jest.fn(); | ||
|
||
const tree = createTestInstance( | ||
<Component | ||
mutations={{}} | ||
shippingData={shippingData} | ||
toggleSignInContent={toggleSignInContent} | ||
setGuestSignInUsername={setGuestSignInUsername} | ||
/> | ||
); | ||
|
||
const { root } = tree; | ||
const { talonProps } = root.findByType('i').props; | ||
const { handleToastAction } = talonProps; | ||
|
||
handleToastAction(removeToast, '[email protected]'); | ||
expect(setGuestSignInUsername).toHaveBeenCalledWith('[email protected]'); | ||
expect(toggleSignInContent).toHaveBeenCalled(); | ||
expect(removeToast).toHaveBeenCalled(); | ||
}); |
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
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
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
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 |
---|---|---|
|
@@ -36,11 +36,13 @@ Array [ | |
className="input" | ||
> | ||
<input | ||
autoComplete="off" | ||
className="input" | ||
id="email" | ||
name="email" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
onPaste={[Function]} | ||
value="" | ||
/> | ||
</span> | ||
|
@@ -475,11 +477,13 @@ Array [ | |
className="input" | ||
> | ||
<input | ||
autoComplete="off" | ||
className="input" | ||
id="email" | ||
name="email" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
onPaste={[Function]} | ||
value="" | ||
/> | ||
</span> | ||
|
@@ -910,11 +914,13 @@ Array [ | |
className="input" | ||
> | ||
<input | ||
autoComplete="off" | ||
className="input" | ||
id="email" | ||
name="email" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
onPaste={[Function]} | ||
value="[email protected]" | ||
/> | ||
</span> | ||
|
@@ -1363,11 +1369,13 @@ Array [ | |
className="input" | ||
> | ||
<input | ||
autoComplete="off" | ||
className="input" | ||
id="email" | ||
name="email" | ||
onBlur={[Function]} | ||
onChange={[Function]} | ||
onPaste={[Function]} | ||
value="[email protected]" | ||
/> | ||
</span> | ||
|
Oops, something went wrong.