Krishya | 75e43c0 | 2025-04-05 21:16:30 +0800 | [diff] [blame^] | 1 | import React from 'react'; |
| 2 | import { render, screen, fireEvent } from '@testing-library/react'; |
| 3 | import AuthPage from './AuthPage'; |
| 4 | |
| 5 | describe('AuthPage component', () => { |
| 6 | test('switches between login and register forms', () => { |
| 7 | render(<AuthPage />); |
| 8 | |
| 9 | const registerButton = screen.getByText('点击注册'); |
| 10 | fireEvent.click(registerButton); |
| 11 | |
| 12 | const usernameInput = screen.getByPlaceholderText('请输入用户名'); |
| 13 | const passwordInput = screen.getByPlaceholderText('请输入密码'); |
| 14 | const emailInput = screen.getByPlaceholderText('请输入邮箱'); |
| 15 | |
| 16 | expect(usernameInput).toBeInTheDocument(); |
| 17 | expect(passwordInput).toBeInTheDocument(); |
| 18 | expect(emailInput).toBeInTheDocument(); |
| 19 | |
| 20 | const loginButton = screen.getByText('点击登录'); |
| 21 | fireEvent.click(loginButton); |
| 22 | |
| 23 | const loginUsernameInput = screen.getByPlaceholderText('请输入用户名'); |
| 24 | const loginPasswordInput = screen.getByPlaceholderText('请输入密码'); |
| 25 | const loginSubmitButton = screen.getByText('登录'); |
| 26 | |
| 27 | expect(loginUsernameInput).toBeInTheDocument(); |
| 28 | expect(loginPasswordInput).toBeInTheDocument(); |
| 29 | expect(loginSubmitButton).toBeInTheDocument(); |
| 30 | }); |
| 31 | }); |