抽离个人中心展示原子组件

新增 PlatformProfilePrimitives 收口个人中心统计卡快捷入口设置行与法律入口
RpgEntryHomeView 改为复用平台级个人中心展示组件
补充组件测试并更新前端收口文档与共享决策
This commit is contained in:
2026-06-10 18:31:52 +08:00
parent 17cf65a1a3
commit c975d41d46
5 changed files with 270 additions and 162 deletions

View File

@@ -0,0 +1,84 @@
/* @vitest-environment jsdom */
import { Settings } from 'lucide-react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, test, vi } from 'vitest';
import { ICP_RECORD_NUMBER, LEGAL_DOCUMENTS } from '../common/legalDocuments';
import {
ProfileLegalSection,
ProfileSettingsRow,
ProfileShortcutButton,
ProfileStatCard,
} from './PlatformProfilePrimitives';
function TestIcon({ className }: { className?: string }) {
return <span className={className}>I</span>;
}
describe('PlatformProfilePrimitives', () => {
test('ProfileStatCard reports its dashboard card key on click', async () => {
const user = userEvent.setup();
const onClick = vi.fn();
render(
<ProfileStatCard
cardKey="wallet"
label="泥点余额"
value="88"
icon={TestIcon}
onClick={onClick}
/>,
);
await user.click(screen.getByRole('button', { name: /\s*88/u }));
expect(onClick).toHaveBeenCalledWith('wallet');
});
test('ProfileShortcutButton keeps shortcut label and sub label visible', () => {
render(
<ProfileShortcutButton
label="玩家社区"
subLabel="交流心得"
icon={TestIcon}
onClick={vi.fn()}
/>,
);
const button = screen.getByRole('button', { name: //u });
expect(button.className).toContain('platform-profile-shortcut-button');
expect(screen.getByText('交流心得')).toBeTruthy();
});
test('ProfileSettingsRow and ProfileLegalSection keep their click affordances', async () => {
const user = userEvent.setup();
const onSettingsClick = vi.fn();
const onOpenDocument = vi.fn();
const firstLegalDocument = LEGAL_DOCUMENTS[0];
if (!firstLegalDocument) {
throw new Error('expected legal documents fixtures');
}
render(
<>
<ProfileSettingsRow
label="通用设置"
icon={Settings}
onClick={onSettingsClick}
/>
<ProfileLegalSection onOpenDocument={onOpenDocument} />
</>,
);
await user.click(screen.getByRole('button', { name: //u }));
expect(onSettingsClick).toHaveBeenCalledTimes(1);
await user.click(
screen.getByRole('button', { name: firstLegalDocument.title }),
);
expect(onOpenDocument).toHaveBeenCalledWith(firstLegalDocument.id);
expect(screen.getByText(ICP_RECORD_NUMBER)).toBeTruthy();
});
});