/* @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( , ); 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( , ); expect( screen.getByRole('button', { name: '兑换' }).hasAttribute('disabled'), ).toBe(true); }); });