/* @vitest-environment jsdom */ import { renderHook } from '@testing-library/react'; import { vi } from 'vitest'; import type { AuthUser } from '../../services/authService'; const profileClientMocks = vi.hoisted(() => ({ confirmWechatPlatformProfileRechargeOrder: vi.fn(), createPlatformProfileRechargeOrder: vi.fn(), getPlatformProfileRechargeCenter: vi.fn(), getPlatformProfileReferralInviteCenter: vi.fn(), getPlatformProfileWalletLedger: vi.fn(), redeemPlatformProfileReferralInviteCode: vi.fn(), redeemPlatformProfileRewardCode: vi.fn(), watchWechatPlatformProfileRechargeOrder: vi.fn(), })); const apiClientMocks = vi.hoisted(() => ({ clearStoredAccessToken: vi.fn(), })); const hostBridgeMocks = vi.hoisted(() => ({ getHostRuntime: vi.fn(() => ({ kind: 'browser' })), requestHostLogin: vi.fn(), requestHostPayment: vi.fn(), })); const paymentPlatformMocks = vi.hoisted(() => ({ resolveProfileRechargeProductPaymentChannel: vi.fn(() => 'wechat_native'), })); vi.mock( '../../services/platform-entry/platformProfileClient', () => profileClientMocks, ); vi.mock('../../services/apiClient', async () => { const actual = await vi.importActual< typeof import('../../services/apiClient') >('../../services/apiClient'); return { ...actual, ...apiClientMocks }; }); vi.mock('../../services/host-bridge/hostBridge', async () => { const actual = await vi.importActual< typeof import('../../services/host-bridge/hostBridge') >('../../services/host-bridge/hostBridge'); return { ...actual, ...hostBridgeMocks }; }); vi.mock('../../services/payment/paymentPlatform', async () => { const actual = await vi.importActual< typeof import('../../services/payment/paymentPlatform') >('../../services/payment/paymentPlatform'); return { ...actual, ...paymentPlatformMocks }; }); export { apiClientMocks, hostBridgeMocks, paymentPlatformMocks, profileClientMocks, }; import { usePlatformProfileCenterController } from './usePlatformProfileCenterController'; const baseUser = { publicUserCode: '100001', displayName: '测试用户', avatarUrl: null, phoneNumberMasked: null, loginMethod: 'password', bindingStatus: 'active', wechatBound: false, } satisfies Omit; export const userA = { ...baseUser, id: 'user-a' } satisfies AuthUser; export const userB = { ...baseUser, id: 'user-b', publicUserCode: '100002', } satisfies AuthUser; export function renderController( currentUser: AuthUser, onRechargeSuccess = vi.fn(), ) { const requestLogin = vi.fn(); return renderHook( ({ user }) => usePlatformProfileCenterController({ activeTab: 'settings', isAuthenticated: true, showRechargeEntry: true, onRechargeSuccess, requestLogin, currentUser: user, }), { initialProps: { user: currentUser } }, ); }