-
Notifications
You must be signed in to change notification settings - Fork 6
ENT-11429: Add billing address capture and fix tracking event issue #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
b77c24f
073f871
8020061
15644db
b4cc66a
f38a527
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,286 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { render, screen } from '@testing-library/react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import userEvent from '@testing-library/user-event'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import '@testing-library/jest-dom/extend-expect'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useForm } from 'react-hook-form'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { DataStoreKey } from '@/constants/checkout'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useCheckoutFormStore } from '@/hooks/useCheckoutFormStore'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import BillingFormFields from '../BillingFormFields'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockSetFormData = jest.fn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mockAddressChangeEvent = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| value: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'John Doe', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| address: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: 'US', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '123 Main St', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: 'Apt 4B', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: 'Boston', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: 'MA', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| postal_code: '02109', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.mock('@/hooks/useCheckoutFormStore', () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useCheckoutFormStore: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.mock('@stripe/react-stripe-js', () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AddressElement: ({ onChange }: { onChange: (event: any) => void }) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button type="button" data-testid="address-element" onClick={() => onChange(mockAddressChangeEvent)}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AddressElement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PaymentElement: () => <div data-testid="payment-element">PaymentElement</div>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('BillingFormFields', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.clearAllMocks(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jest.mocked(useCheckoutFormStore).mockImplementation((selector) => selector({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| formData: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [DataStoreKey.BillingDetails]: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setFormData: mockSetFormData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkoutSessionClientSecret: undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| checkoutSessionStatus: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paymentStatus: null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setCheckoutSessionClientSecret: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setCheckoutSessionStatus: jest.fn(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('renders Stripe address and payment elements', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Wrapper = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const form = useForm<BillingDetailsData>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: 'onTouched', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultValues: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullName: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <IntlProvider locale="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <BillingFormFields form={form} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </IntlProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Wrapper />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByTestId('address-element')).toBeInTheDocument(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByTestId('payment-element')).toBeInTheDocument(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('maps Stripe AddressElement fields into store on change', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const user = userEvent.setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Wrapper = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const form = useForm<BillingDetailsData>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: 'onTouched', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultValues: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullName: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <IntlProvider locale="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <BillingFormFields form={form} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </IntlProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Wrapper />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await user.click(screen.getByTestId('address-element')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockSetFormData).toHaveBeenCalledWith( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DataStoreKey.BillingDetails, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect.objectContaining({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullName: 'John Doe', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: 'US', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '123 Main St', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: 'Apt 4B', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: 'Boston', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: 'MA', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip: '02109', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('renders fullName validation feedback when form error exists', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Wrapper = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const form = useForm<BillingDetailsData>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: 'onTouched', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultValues: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullName: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form.setError('fullName', { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'manual', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| message: 'Please provide your full name.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [form]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <IntlProvider locale="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <BillingFormFields form={form} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </IntlProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Wrapper />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByText('Please provide your full name.')).toBeInTheDocument(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('handles address change event without errors', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const user = userEvent.setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Wrapper = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const form = useForm<BillingDetailsData>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: 'onTouched', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultValues: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullName: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <IntlProvider locale="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <BillingFormFields form={form} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </IntlProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Wrapper />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await user.click(screen.getByTestId('address-element')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockSetFormData).toHaveBeenCalled(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('updates form setValue for all address fields when address changes', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const user = userEvent.setup(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const setValueSpy = jest.fn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
gshivajibiradar marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Wrapper = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const form = useForm<BillingDetailsData>({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode: 'onTouched', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defaultValues: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fullName: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| country: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line1: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line2: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| city: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Spy on the setValue method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originalSetValue = form.setValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form.setValue = jest.fn(originalSetValue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setValueSpy.mockImplementation(form.setValue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <IntlProvider locale="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <BillingFormFields form={form} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </IntlProvider> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Wrapper />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await user.click(screen.getByTestId('address-element')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(mockSetFormData).toHaveBeenCalled(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+193
to
+227
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+193
to
+228
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('updates form setValue for all address fields when address changes', async () => { | |
| const user = userEvent.setup(); | |
| const setValueSpy = jest.fn(); | |
| const Wrapper = () => { | |
| const form = useForm<BillingDetailsData>({ | |
| mode: 'onTouched', | |
| defaultValues: { | |
| fullName: '', | |
| country: '', | |
| line1: '', | |
| line2: '', | |
| city: '', | |
| state: '', | |
| zip: '', | |
| }, | |
| }); | |
| // Spy on the setValue method | |
| const originalSetValue = form.setValue; | |
| form.setValue = jest.fn(originalSetValue); | |
| setValueSpy.mockImplementation(form.setValue); | |
| return ( | |
| <IntlProvider locale="en"> | |
| <BillingFormFields form={form} /> | |
| </IntlProvider> | |
| ); | |
| }; | |
| render(<Wrapper />); | |
| await user.click(screen.getByTestId('address-element')); | |
| expect(mockSetFormData).toHaveBeenCalled(); | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only
fullNamevalidation feedback is rendered, but the schema now requires other address fields (country,line1,city,state,zip). If the AddressElement doesn’t populate these (or is incomplete), the user may be blocked from submitting with no visible error. Consider adding a generalized address error message when any of those related fields have validation errors (or integrating validation feedback with the AddressElement).