7f8400fd3a
将 PlatformAsyncStatePanel 扩展到公共素材选择网格 将 PlatformAsyncStatePanel 扩展到视觉小说存档面板与账号安全子区块 将兑换码弹窗提交动作改为使用标准 profile modal footer 补充对应测试并更新 PlatformUiKit 收口计划与共享决策记录
76 lines
2.0 KiB
TypeScript
76 lines
2.0 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);
|
|
});
|
|
|
|
test('reuses the shared profile modal footer chrome for submit action', () => {
|
|
render(
|
|
<PlatformProfileRewardCodeRedeemModal
|
|
value="ab12"
|
|
isSubmitting={false}
|
|
error={null}
|
|
success={null}
|
|
onChange={vi.fn()}
|
|
onSubmit={vi.fn()}
|
|
onClose={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
const submitButton = screen.getByRole('button', { name: '兑换' });
|
|
const footer = submitButton.closest('div');
|
|
|
|
expect(footer?.className).toContain('border-t');
|
|
expect(footer?.className).toContain('pb-5');
|
|
expect(footer?.className).toContain('pt-0');
|
|
});
|
|
});
|