Files
Genarrative/src/components/auth/BindPhoneScreen.test.tsx
T
wuxiangwanzi dab879e0c4 统一界面上的ip形象标识
新增陶泥儿产品 IP 公共图片资产
左上角品牌标识和绑定页品牌块统一展示该形象
更新产品基线、创作主页方案和共享决策记录
2026-06-23 15:48:03 +08:00

65 lines
2.0 KiB
TypeScript

/* @vitest-environment jsdom */
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { expect, test, vi } from 'vitest';
import type { AuthUser } from '../../services/authService';
import { BindPhoneScreen } from './BindPhoneScreen';
const baseUser: AuthUser = {
id: 'user-1',
displayName: '微信旅人',
avatarUrl: null,
publicUserCode: 'user-bind-phone',
phoneNumberMasked: null,
loginMethod: 'wechat',
bindingStatus: 'pending_bind_phone',
wechatBound: true,
};
test('绑定手机号表单复用平台输入和字段标题', async () => {
const user = userEvent.setup();
const onSubmit = vi.fn().mockResolvedValue(undefined);
render(
<BindPhoneScreen
user={baseUser}
platformTheme="light"
sendingCode={false}
binding={false}
error=""
captchaChallenge={null}
onSendCode={vi.fn().mockResolvedValue({
cooldownSeconds: 60,
expiresInSeconds: 300,
})}
onSubmit={onSubmit}
onLogout={vi.fn().mockResolvedValue(undefined)}
/>,
);
const phoneInput = screen.getByLabelText('手机号') as HTMLInputElement;
const codeInput = screen.getByLabelText('验证码') as HTMLInputElement;
expect(phoneInput.className).toContain('platform-text-field');
expect(codeInput.className).toContain('platform-text-field');
expect(screen.getByText('手机号').className).toContain(
'text-[var(--platform-text-strong)]',
);
expect(screen.getByText('当前登录身份:微信旅人').className).toContain(
'platform-subpanel',
);
expect(
document
.querySelector('.selection-hero-brand__image')
?.getAttribute('src'),
).toBe('/branding/taonier-product-ip.png');
await user.type(phoneInput, '13800000000');
await user.type(codeInput, '123456');
await user.click(screen.getByRole('button', { name: '绑定手机号并进入游戏' }));
expect(onSubmit).toHaveBeenCalledWith('13800000000', '123456');
});