Files
Genarrative/src/components/platform-entry/PlatformProfilePrimitives.test.tsx
kdletters 051fd6156c 继续扩展共享可导航行
扩展 PlatformNavigableListItem 接入 profile 设置行
补充 profile 设置行的组件级与首页集成回归测试
更新 PlatformUiKit 收口计划与共享决策记录
2026-06-11 03:22:34 +08:00

88 lines
2.6 KiB
TypeScript

/* @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} />
</>,
);
const settingsButton = screen.getByRole('button', { name: //u });
expect(settingsButton.className).toContain('platform-navigable-list-item');
await user.click(settingsButton);
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();
});
});