blob: e398536d9b838ab57b28a834b2f97b52903b3308 [file] [log] [blame]
Krishya75e43c02025-04-05 21:16:30 +08001import React from 'react';
2import { render, screen, fireEvent } from '@testing-library/react';
3import AuthPage from './AuthPage';
4
5describe('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});