|
4 | 4 | * SPDX-License-Identifier: BSD-3-Clause |
5 | 5 | * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
6 | 6 | */ |
7 | | -import React from 'react' |
| 7 | +import React, {useState, useEffect} from 'react' |
8 | 8 | import {screen, waitFor, fireEvent, act} from '@testing-library/react' |
9 | 9 | import ContactInfo from '@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info' |
10 | 10 | import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils' |
@@ -213,6 +213,65 @@ describe('ContactInfo Component', () => { |
213 | 213 | expect(phoneInput).toHaveAttribute('disabled') |
214 | 214 | }) |
215 | 215 |
|
| 216 | + test('displays phone number in summary card for registered user', async () => { |
| 217 | + jest.resetModules() |
| 218 | + jest.doMock('@salesforce/commerce-sdk-react', () => { |
| 219 | + const originalModule = jest.requireActual('@salesforce/commerce-sdk-react') |
| 220 | + return { |
| 221 | + ...originalModule, |
| 222 | + useCustomerType: jest.fn(() => ({isRegistered: true})), |
| 223 | + useAuthHelper: jest |
| 224 | + .fn() |
| 225 | + .mockImplementation( |
| 226 | + (helperType) => |
| 227 | + mockAuthHelperFunctions[helperType] || {mutateAsync: jest.fn()} |
| 228 | + ) |
| 229 | + } |
| 230 | + }) |
| 231 | + jest.doMock('@salesforce/retail-react-app/app/hooks/use-current-customer', () => ({ |
| 232 | + useCurrentCustomer: () => ({ |
| 233 | + data: { |
| 234 | + email: 'reg@salesforce.com', |
| 235 | + isRegistered: true, |
| 236 | + phoneHome: '(111) 222-3333' |
| 237 | + } |
| 238 | + }) |
| 239 | + })) |
| 240 | + jest.doMock( |
| 241 | + '@salesforce/retail-react-app/app/pages/checkout-one-click/util/checkout-context', |
| 242 | + () => { |
| 243 | + return { |
| 244 | + useCheckout: jest.fn().mockReturnValue({ |
| 245 | + customer: null, |
| 246 | + basket: {basketId: 'test-basket-id'}, |
| 247 | + isGuestCheckout: false, |
| 248 | + setIsGuestCheckout: jest.fn(), |
| 249 | + step: 1, // Not on CONTACT_INFO step, so summary shows |
| 250 | + login: null, |
| 251 | + STEPS: {CONTACT_INFO: 0}, |
| 252 | + goToStep: jest.fn(), |
| 253 | + goToNextStep: jest.fn(), |
| 254 | + setContactPhone: jest.fn() |
| 255 | + }) |
| 256 | + } |
| 257 | + } |
| 258 | + ) |
| 259 | + const {renderWithProviders: localRenderWithProviders} = await import( |
| 260 | + '@salesforce/retail-react-app/app/utils/test-utils' |
| 261 | + ) |
| 262 | + const module = await import( |
| 263 | + '@salesforce/retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info' |
| 264 | + ) |
| 265 | + const Component = module.default |
| 266 | + |
| 267 | + localRenderWithProviders(<Component />) |
| 268 | + |
| 269 | + // Verify email and phone are displayed in summary |
| 270 | + expect(screen.getByText('reg@salesforce.com')).toBeInTheDocument() |
| 271 | + expect(screen.getByText('(111) 222-3333')).toBeInTheDocument() |
| 272 | + }) |
| 273 | + |
| 274 | + |
216 | 275 | test('shows social login when enabled', () => { |
217 | 276 | renderWithProviders(<ContactInfo isSocialEnabled={true} idps={['google', 'apple']} />) |
218 | 277 |
|
|
0 commit comments