完善验证页面和后端接口的链接
> 1. 配置了开发环境的端口转发 -> localhost:8080\
> 2. 完成了注册,登录,忘记密码页的功能
> 3. 为项目配置了vitest测试框架
> 4. 对这三个页面进行了测试
> 重写了/test/setup.ts
Change-Id: I46c600ce06d698dae6953b2e1e3ff4a98b0f3de4
diff --git a/src/test/auth/Forget.test.tsx b/src/test/auth/Forget.test.tsx
new file mode 100644
index 0000000..b2ba158
--- /dev/null
+++ b/src/test/auth/Forget.test.tsx
@@ -0,0 +1,24 @@
+import { render, screen } from '@testing-library/react'
+import Forget from '../../feature/auth/Forget'
+import { Provider } from 'react-redux'
+import { store } from '../../store/store'
+import { MemoryRouter } from 'react-router'
+
+describe('Forget Password Page', () => {
+ it('renders forget password form', () => {
+ render(
+ <MemoryRouter>
+ <Provider store={store}>
+ <Forget />
+ </Provider>
+ </MemoryRouter>
+
+ )
+
+ const emailInput = screen.getByPlaceholderText('注册邮箱')
+ const getCodeButton = screen.getByText('获取验证码')
+
+ expect(emailInput).toBeInTheDocument()
+ expect(getCodeButton).toBeInTheDocument()
+ })
+})
\ No newline at end of file
diff --git a/src/test/auth/Login.test.tsx b/src/test/auth/Login.test.tsx
new file mode 100644
index 0000000..ade54e8
--- /dev/null
+++ b/src/test/auth/Login.test.tsx
@@ -0,0 +1,27 @@
+import { render, screen } from '@testing-library/react'
+import Login from '../../feature/auth/Login'
+import { Provider } from 'react-redux'
+import { store } from '../../store/store'
+import { MemoryRouter } from 'react-router'
+
+describe('Login Page', () => {
+ it('renders login form', () => {
+ render(
+ <MemoryRouter>
+ <Provider store={store}>
+ <Login />
+ </Provider>
+ </MemoryRouter>
+
+ )
+
+ const emailInput = screen.getByPlaceholderText('账号(注册邮箱)')
+ const passwordInput = screen.getByPlaceholderText('密码')
+ const loginButton = screen.getByRole('button', { name: /登录/i })
+
+
+ expect(emailInput).toBeInTheDocument()
+ expect(passwordInput).toBeInTheDocument()
+ expect(loginButton).toBeInTheDocument()
+ })
+})
\ No newline at end of file
diff --git a/src/test/auth/Register.test.tsx b/src/test/auth/Register.test.tsx
new file mode 100644
index 0000000..c118a8b
--- /dev/null
+++ b/src/test/auth/Register.test.tsx
@@ -0,0 +1,32 @@
+import { render, screen } from '@testing-library/react'
+import Register from '../../feature/auth/Register'
+import { Provider } from 'react-redux'
+import { store } from '../../store/store'
+import { MemoryRouter } from 'react-router'
+
+describe('Register Page', () => {
+ it('renders register form', () => {
+ render(
+ <MemoryRouter>
+ <Provider store={store}>
+ <Register />
+ </Provider>
+ </MemoryRouter>
+
+ )
+
+ const nameInput = screen.getByPlaceholderText('请输入用户名')
+ const emailInput = screen.getByPlaceholderText('请输入邮箱')
+ const verifyCodeInput = screen.getByPlaceholderText('请输入验证码')
+ const passwordInput = screen.getByPlaceholderText('请输入密码')
+ const confirmPasswordInput = screen.getByPlaceholderText('请确认密码')
+ const registerButton = screen.getByText('注册')
+
+ expect(nameInput).toBeInTheDocument()
+ expect(emailInput).toBeInTheDocument()
+ expect(verifyCodeInput).toBeInTheDocument()
+ expect(passwordInput).toBeInTheDocument()
+ expect(confirmPasswordInput).toBeInTheDocument()
+ expect(registerButton).toBeInTheDocument()
+ })
+})
\ No newline at end of file
diff --git a/src/test/setup.ts b/src/test/setup.ts
new file mode 100644
index 0000000..bb15cf4
--- /dev/null
+++ b/src/test/setup.ts
@@ -0,0 +1,9 @@
+import '@testing-library/jest-dom';
+
+globalThis.matchMedia = globalThis.matchMedia || function() {
+ return {
+ matches: false, // 模拟返回值
+ addListener: () => {}, // 不执行任何操作
+ removeListener: () => {} // 不执行任何操作
+ };
+ };
\ No newline at end of file