blob: 651f9c66c6442b3918b29407df0cf6b882b01790 [file] [log] [blame]
import { render, screen } from '@testing-library/react';
import { Router } from 'wouter'; // 使用 wouter 的 Router
import MainPage from './MainPage'; // 导入 MainPage 组件
test('renders MainPage with logo, navigation links, and user post', () => {
render(
<Router>
<MainPage />
</Router>
);
// 检查页面中是否有 Echo 站点名称
const siteNameElement = screen.getByText(/Echo/i);
expect(siteNameElement).toBeInTheDocument();
// 检查页面中是否有导航栏中的链接
const friendMomentsLink = screen.getByText(/好友动态/i);
const forumLink = screen.getByText(/论坛/i);
const interestGroupsLink = screen.getByText(/兴趣小组/i);
const seedListLink = screen.getByText(/种子列表/i);
const publishSeedLink = screen.getByText(/发布种子/i);
expect(friendMomentsLink).toBeInTheDocument();
expect(forumLink).toBeInTheDocument();
expect(interestGroupsLink).toBeInTheDocument();
expect(seedListLink).toBeInTheDocument();
expect(publishSeedLink).toBeInTheDocument();
// 检查页面中是否有用户动态信息
const usernameElement = screen.getByText(/user1/i);
expect(usernameElement).toBeInTheDocument();
const postContentElement = screen.getByText(/动态内容.../i);
expect(postContentElement).toBeInTheDocument();
// 使用更精确的查询来获取喜欢数和评论数
const likeCountElement = screen.getByText('21');
const commentCountElement = screen.getByText('2');
expect(likeCountElement).toBeInTheDocument();
expect(commentCountElement).toBeInTheDocument();
});