914b74ce8e
- 新增充值账单任务兑换码共享组件并补齐组件级测试 - 让 RpgEntryHomeView 改为复用新的 profile 弹层组件并删除内联实现 - 更新 PlatformUiKit 收口文档与团队共享记忆记录新的组件沉淀
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
/* @vitest-environment jsdom */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import { describe, expect, test, vi } from 'vitest';
|
|
|
|
import { PlatformProfileRewardCodeRedeemModal } from './PlatformProfileRewardCodeRedeemModal';
|
|
|
|
describe('PlatformProfileRewardCodeRedeemModal', () => {
|
|
test('submits on button click and enter key', async () => {
|
|
const user = userEvent.setup();
|
|
const onSubmit = vi.fn();
|
|
const onChange = vi.fn();
|
|
|
|
render(
|
|
<PlatformProfileRewardCodeRedeemModal
|
|
value="ab12"
|
|
isSubmitting={false}
|
|
error={null}
|
|
success={null}
|
|
onChange={onChange}
|
|
onSubmit={onSubmit}
|
|
onClose={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
const input = screen.getByRole('textbox', { name: '兑换码' });
|
|
|
|
await user.type(input, 'c');
|
|
await user.keyboard('{Enter}');
|
|
await user.click(screen.getByRole('button', { name: '兑换' }));
|
|
|
|
expect(onChange).toHaveBeenCalled();
|
|
expect(onSubmit).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
test('disables submit when the code is blank', () => {
|
|
render(
|
|
<PlatformProfileRewardCodeRedeemModal
|
|
value=" "
|
|
isSubmitting={false}
|
|
error={null}
|
|
success={null}
|
|
onChange={vi.fn()}
|
|
onSubmit={vi.fn()}
|
|
onClose={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(
|
|
screen.getByRole('button', { name: '兑换' }).hasAttribute('disabled'),
|
|
).toBe(true);
|
|
});
|
|
});
|