Krishya | 1df0589 | 2025-04-05 21:16:30 +0800 | [diff] [blame] | 1 | import { render, screen } from '@testing-library/react'; |
| 2 | import { Router } from 'wouter'; // 使用 wouter 的 Router |
| 3 | import MainPage from './MainPage'; // 导入 MainPage 组件 |
| 4 | |
| 5 | test('renders MainPage with logo, navigation links, and user post', () => { |
| 6 | render( |
| 7 | <Router> |
| 8 | <MainPage /> |
| 9 | </Router> |
| 10 | ); |
| 11 | |
| 12 | // 检查页面中是否有 Echo 站点名称 |
| 13 | const siteNameElement = screen.getByText(/Echo/i); |
| 14 | expect(siteNameElement).toBeInTheDocument(); |
| 15 | |
| 16 | // 检查页面中是否有导航栏中的链接 |
| 17 | const friendMomentsLink = screen.getByText(/好友动态/i); |
| 18 | const forumLink = screen.getByText(/论坛/i); |
| 19 | const interestGroupsLink = screen.getByText(/兴趣小组/i); |
| 20 | const seedListLink = screen.getByText(/种子列表/i); |
| 21 | const publishSeedLink = screen.getByText(/发布种子/i); |
| 22 | |
| 23 | expect(friendMomentsLink).toBeInTheDocument(); |
| 24 | expect(forumLink).toBeInTheDocument(); |
| 25 | expect(interestGroupsLink).toBeInTheDocument(); |
| 26 | expect(seedListLink).toBeInTheDocument(); |
| 27 | expect(publishSeedLink).toBeInTheDocument(); |
| 28 | |
| 29 | // 检查页面中是否有用户动态信息 |
| 30 | const usernameElement = screen.getByText(/user1/i); |
| 31 | expect(usernameElement).toBeInTheDocument(); |
| 32 | |
| 33 | const postContentElement = screen.getByText(/动态内容.../i); |
| 34 | expect(postContentElement).toBeInTheDocument(); |
| 35 | |
| 36 | // 使用更精确的查询来获取喜欢数和评论数 |
| 37 | const likeCountElement = screen.getByText('21'); |
| 38 | const commentCountElement = screen.getByText('2'); |
| 39 | |
| 40 | expect(likeCountElement).toBeInTheDocument(); |
| 41 | expect(commentCountElement).toBeInTheDocument(); |
| 42 | }); |