| import { render, screen } from '@testing-library/react'; |
| import GameCategory from '../../feature/categories/GameCategory'; |
| import { Provider } from 'react-redux'; |
| import { store } from '../../store/store'; |
| import { MemoryRouter } from 'react-router'; |
| |
| describe('GameCategory Component', () => { |
| it('renders game category page with search and game cards', () => { |
| render( |
| <MemoryRouter> |
| <Provider store={store}> |
| <GameCategory /> |
| </Provider> |
| </MemoryRouter> |
| ); |
| |
| // 验证标题和描述 |
| expect(screen.getByText('游戏资源分区')).toBeInTheDocument(); |
| expect(screen.getByText('PC、主机游戏资源分享')).toBeInTheDocument(); |
| |
| // 验证搜索框 |
| const searchInput = screen.getByPlaceholderText('搜索游戏名称或开发商'); |
| expect(searchInput).toBeInTheDocument(); |
| |
| // 验证游戏卡片 |
| expect(screen.getByText('赛博朋克2077')).toBeInTheDocument(); |
| expect(screen.getByText('艾尔登法环')).toBeInTheDocument(); |
| |
| // 验证开发商信息 |
| expect(screen.getByText('开发商: CD Projekt Red')).toBeInTheDocument(); |
| expect(screen.getByText('开发商: FromSoftware')).toBeInTheDocument(); |
| }); |
| }); |