Files
Genarrative/src/components/platform-entry/PlatformProfileTaskCenterModal.test.tsx
kdletters 914b74ce8e 拆出个人中心剩余弹层组件
- 新增充值账单任务兑换码共享组件并补齐组件级测试
- 让 RpgEntryHomeView 改为复用新的 profile 弹层组件并删除内联实现
- 更新 PlatformUiKit 收口文档与团队共享记忆记录新的组件沉淀
2026-06-10 20:06:06 +08:00

99 lines
2.8 KiB
TypeScript

/* @vitest-environment jsdom */
import { render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, test, vi } from 'vitest';
import { PlatformProfileTaskCenterModal } from './PlatformProfileTaskCenterModal';
describe('PlatformProfileTaskCenterModal', () => {
test('renders claimable tasks and forwards claim action', async () => {
const user = userEvent.setup();
const onClaim = vi.fn();
render(
<PlatformProfileTaskCenterModal
center={{
dayKey: 20260610,
walletBalance: 66,
updatedAt: '2026-06-10T08:00:00.000Z',
tasks: [
{
taskId: 'task-1',
title: '每日登录',
description: '登录一次',
eventKey: 'daily_login',
cycle: 'daily',
rewardPoints: 10,
status: 'claimable',
progressCount: 1,
threshold: 1,
dayKey: 20260610,
claimedAt: null,
updatedAt: '2026-06-10T08:00:00.000Z',
},
],
}}
isLoading={false}
error={null}
success={null}
claimingTaskId={null}
fallbackBalance={12}
onClose={vi.fn()}
onRetry={vi.fn()}
onClaim={onClaim}
/>,
);
const dialog = screen.getByRole('dialog', { name: '每日任务' });
expect(within(dialog).getByText('66泥点')).toBeTruthy();
expect(within(dialog).getByText('每日登录')).toBeTruthy();
expect(within(dialog).getByText('1/1')).toBeTruthy();
expect(within(dialog).getByText('可领取')).toBeTruthy();
await user.click(within(dialog).getByRole('button', { name: '领取' }));
expect(onClaim).toHaveBeenCalledWith('task-1');
});
test('keeps incomplete tasks disabled', () => {
render(
<PlatformProfileTaskCenterModal
center={{
dayKey: 20260610,
walletBalance: 20,
updatedAt: '2026-06-10T08:00:00.000Z',
tasks: [
{
taskId: 'task-2',
title: '分享一次',
description: '完成一次分享',
eventKey: 'daily_share',
cycle: 'daily',
rewardPoints: 8,
status: 'incomplete',
progressCount: 0,
threshold: 1,
dayKey: 20260610,
claimedAt: null,
updatedAt: '2026-06-10T08:00:00.000Z',
},
],
}}
isLoading={false}
error={null}
success={null}
claimingTaskId={null}
fallbackBalance={12}
onClose={vi.fn()}
onRetry={vi.fn()}
onClaim={vi.fn()}
/>,
);
expect(
screen.getByRole('button', { name: '未完成' }).hasAttribute('disabled'),
).toBe(true);
});
});