import { fireEvent, render, screen } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'; import { LearningSidebar } from '@/components/layout/LearningSidebar'; function LocationProbe() { const location = useLocation(); return {location.pathname}; } describe('LearningSidebar', () => { it('shows only the new project catalog navigation and returns detail pages to the list', () => { render( } /> , ); expect(screen.getByRole('navigation', { name: 'AI 学习导航' })).toHaveTextContent('学习项目'); expect(screen.queryByText('生成课程')).not.toBeInTheDocument(); expect(screen.queryByText('我的课程')).not.toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: '学习项目' })); expect(screen.getByTestId('location-path')).toHaveTextContent('/learning'); }); it('keeps the collapsed navigation compact', () => { render(); expect(screen.getByRole('button', { name: '学习项目' })).toBeInTheDocument(); expect(screen.queryByText('阅读项目说明并下载到电脑实践。')).not.toBeInTheDocument(); }); });