22301014 | 3d96630 | 2025-06-07 22:54:40 +0800 | [diff] [blame] | 1 | import { render, screen } from '@testing-library/react'; |
| 2 | import GameCategory from '../../feature/categories/GameCategory'; |
| 3 | import { Provider } from 'react-redux'; |
| 4 | import { store } from '../../store/store'; |
| 5 | import { MemoryRouter } from 'react-router'; |
| 6 | |
| 7 | describe('GameCategory Component', () => { |
| 8 | it('renders game category page with search and game cards', () => { |
| 9 | render( |
| 10 | <MemoryRouter> |
| 11 | <Provider store={store}> |
| 12 | <GameCategory /> |
| 13 | </Provider> |
| 14 | </MemoryRouter> |
| 15 | ); |
| 16 | |
| 17 | // 验证标题和描述 |
| 18 | expect(screen.getByText('游戏资源分区')).toBeInTheDocument(); |
| 19 | expect(screen.getByText('PC、主机游戏资源分享')).toBeInTheDocument(); |
| 20 | |
| 21 | // 验证搜索框 |
| 22 | const searchInput = screen.getByPlaceholderText('搜索游戏名称或开发商'); |
| 23 | expect(searchInput).toBeInTheDocument(); |
| 24 | |
| 25 | // 验证游戏卡片 |
| 26 | expect(screen.getByText('赛博朋克2077')).toBeInTheDocument(); |
| 27 | expect(screen.getByText('艾尔登法环')).toBeInTheDocument(); |
| 28 | |
| 29 | // 验证开发商信息 |
| 30 | expect(screen.getByText('开发商: CD Projekt Red')).toBeInTheDocument(); |
| 31 | expect(screen.getByText('开发商: FromSoftware')).toBeInTheDocument(); |
| 32 | }); |
| 33 | }); |